puppeteer / puppeteer

JavaScript API for Chrome and Firefox
https://pptr.dev
Apache License 2.0
88.85k stars 9.09k forks source link

[Bug]: setViewport does not work for puppeteer.connect #12458

Closed vivien7512 closed 6 months ago

vivien7512 commented 6 months ago

Minimal, reproducible example

const puppeteer = require('puppeteer');

(async () => {
  try {
    const browserURL = 'http://127.0.0.1:9222';
    const browser = await puppeteer.connect({ browserURL });
    const pages = await browser.pages();
    const page = pages[0];
//does not display the full page
    await page.setViewport({
      width: 1200,  
      height: 800,  
      deviceScaleFactor: 1, 
    });
  }
  catch (e) {
    var dds = "dd";
  }
})();

Error string

no error

Bug behavior

Background

I'm using Puppeteer to connect to an already running instance of Chrome using the puppeteer.connect method.

Expectation

I am expecting a resize of the viewport

Reality

However, I am facing an issue where the viewport size settings do not apply when connected to an existing browser, whereas it works perfectly fine when I launch a new browser instance using puppeteer.launch

Puppeteer configuration file (if used)

{
  "name": "amazon",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "puppeteer": "^22.9.0"
  }
}

Puppeteer version

22.9.0

Node version

21.4.0

Package manager

npm

Package manager version

10.2.4

Operating system

Windows

github-actions[bot] commented 6 months ago

This issue was not reproducible. Please check that your example runs locally and the following:

Once the above checks are satisfied, please edit your issue with the changes and we will try to reproduce the bug again.


Analyzer run

OrKoN commented 6 months ago

I am not able to reproduce. The viewport is resized according to the setViewport command. Perhaps make sure that nothing else changes the viewport?

Screenshot 2024-05-17 at 11 33 57