I want to start Chrome with puppeteer, and in mobile debug mode, It means to click the 'toggle device toolbar' button in devtools.
Sorry, I don't have enough prestige to upload pictures.
I tried the following code but it didn't work:
const browser = await puppeteer.launch({
devtools: true,
ignoreHTTPSErrors: true,
isMobile:true //I thought it would be fine to set isMobile: true, but not
});
So what should I do?
By default, Puppeteer downloads and uses a specific version of Chromium so its API is guaranteed to work out of the box. To use Puppeteer with a different version of Chrome or Chromium, pass in the executable's path when creating a Browser instance: const browser = await puppeteer.
Show activity on this post. I'd like to add, perhaps what you want is using the package chrome-launcher which takes care of running the chrome browser. You can then use puppeteer. connect() to connect the puppeteer-core library to the browser opened and instrument it.
Puppeteer runs headless by default, but can be configured to run full (non-headless) Chrome or Chromium.
To fully emulate a mobile device, you also have to specify other values like width
, height
, deviceScaleFactor
, hasTouch
and maybe also the user agent to make the website believe your browser is a mobile device. You can either set them manually (see the answer by Yevhen) or use one of the default device descriptors puppeteer provides via puppeteer.devices
and apply them by calling page.emulate
.
Code Sample
const puppeteer = require('puppeteer');
const iPhone = puppeteer.devices['iPhone 6'];
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.emulate(iPhone);
await page.goto(url);
// ...
})();
The isMobile
property is a part of the defaultViewport
object, it means that you should put isMobile
property inside the defaultViewport
object.
Like this:
defaultViewport: {
width: 375,
height: 667,
isMobile: true,
}
Full:
const browser = await puppeteer.launch({
devtools: true,
ignoreHTTPSErrors: true,
defaultViewport: {
width: 375,
height: 667,
isMobile: true,
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With