Activate WSLg in Pengwin
by mmyoji
2 min read
I tried WSLg because I might need to run
chromedriver
for next job.
I had ever struggled and gave up running chromedriver
in normal WSL(WSL2)
environment before, so I thought this was a good opportunity.
The following step is limited for WSL2 + Pengwin distro that I've been using.
Environment
- OS: Windows 11, 21H2, 22000.708
- GPU: GeForce RTX 2080
Steps
- Install NVIDIA GPU driver for WSL
- Install required packages in WSL
pengwin-setup update
# Open setup dialog
# and select [GUI], then install necessary packages.
pengwin-setup
After package installation, restart WSL (or restart Windows).
Install Google Chrome
ref: https://github.com/microsoft/wslg#install-and-run-gui-apps
cd /tmp
sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
sudo apt install --fix-broken -y
sudo dpkg -i google-chrome-stable_current_amd64.deb
# Start Google Chrome app in Linux GUI for test
google-chrome
Install chromedriver
ref: https://tecadmin.net/setup-selenium-with-chromedriver-on-debian/
# 1. check your google chrome version on WSLg
# 2. Download the same version of chromedriver with google-chrome
# http://chromedriver.storage.googleapis.com/index.html
# The version was 102.0.5005.61 this time.
cd /tmp
wget http://chromedriver.storage.googleapis.com/102.0.5005.61/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/bin/chromedriver
sudo chown root:root /usr/bin/chromedriver
sudo chmod +x /usr/bin/chromedriver
Run the following script when you want to test.
ref: https://www.npmjs.com/package/selenium-webdriver
/**
* $ npm init -y
* $ npm install selenium-webdriver
* $ vim main.js
*/
// main.js
const { Builder, Browser, By, Key, until } = require("selenium-webdriver");
(async function main() {
const driver = await new Builder().forBrowser(Browser.CHROME).build();
try {
await driver.get("http://www.google.com/ncr");
await driver.findElement(By.name("q")).sendKeys("webdriver", Key.RETURN);
await driver.wait(until.titleIs("webdriver - Google Search"), 1000);
// Replace the string with 'webdriver - Google 検索' when your language setting is Japanese.
} finally {
await driver.quit();
}
})();
// node main.js