Puppeteer: page.waitForSelector doesn't work on baidu.com

Created on 30 Aug 2017  路  3Comments  路  Source: puppeteer/puppeteer

The following script fails with baidu.com:

const puppeteer = require('puppeteer');
(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://baidu.com');
  await page.waitForSelector('div');
  browser.close();
})();

The reason is that Baidu nullifies MutationObserver that is required for waitForSelector.

bug chromium

Most helpful comment

Suggest renaming this issue to something more general, like: "Puppeteer methods break if pages redefine built-in global objects"

Is this sort of thing even possible to work around at the library level? I did this in my code, which seems to work ok:

await this.page.evaluate( () => {
    if ( ! window.Node ) {
        window.Node = {};
    }
    if ( ! Node.ELEMENT_NODE ) {
        Node.ELEMENT_NODE = 1;
    }
} );

All 3 comments

As reported in #1668, page.click(selector) doesn't work if page redefines window.Node

Suggest renaming this issue to something more general, like: "Puppeteer methods break if pages redefine built-in global objects"

Is this sort of thing even possible to work around at the library level? I did this in my code, which seems to work ok:

await this.page.evaluate( () => {
    if ( ! window.Node ) {
        window.Node = {};
    }
    if ( ! Node.ELEMENT_NODE ) {
        Node.ELEMENT_NODE = 1;
    }
} );

Any updates on this issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

barnash picture barnash  路  3Comments

MehdiRaash picture MehdiRaash  路  3Comments

ebidel picture ebidel  路  3Comments

historylife picture historylife  路  3Comments

kesava picture kesava  路  3Comments