sindresorhus / pageres

Capture website screenshots
MIT License
9.68k stars 744 forks source link

Weird error received #435

Closed DNAScanner closed 2 years ago

DNAScanner commented 2 years ago

Helo. First off, im not sure if this issue is from pageres or puppeteer itself, but I'm getting some weird error right after the pageres function has been called:

node:events:504
      throw er; // Unhandled 'error' event
      ^

ProtocolError: Protocol error (DOM.resolveNode): No node with given id found
    at file:///E:/Coding/Discord-Bots/OhHellNaw-Bot/node_modules/puppeteer/lib/esm/puppeteer/common/Connection.js:294:24
    at new Promise (<anonymous>)
    at CDPSession.send (file:///E:/Coding/Discord-Bots/OhHellNaw-Bot/node_modules/puppeteer/lib/esm/puppeteer/common/Connection.js:290:16)
    at IsolatedWorld.adoptBackendNode (file:///E:/Coding/Discord-Bots/OhHellNaw-Bot/node_modules/puppeteer/lib/esm/puppeteer/common/IsolatedWorld.js:356:121)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async IsolatedWorld.adoptHandle (file:///E:/Coding/Discord-Bots/OhHellNaw-Bot/node_modules/puppeteer/lib/esm/puppeteer/common/IsolatedWorld.js:368:17)
    at async IsolatedWorld.transferHandle (file:///E:/Coding/Discord-Bots/OhHellNaw-Bot/node_modules/puppeteer/lib/esm/puppeteer/common/IsolatedWorld.js:371:24)
    at async Promise.all (index 0)
    at async internalCaptureWebsiteCore (file:///E:/Coding/Discord-Bots/OhHellNaw-Bot/node_modules/capture-website/index.js:322:3)
    at async internalCaptureWebsite (file:///E:/Coding/Discord-Bots/OhHellNaw-Bot/node_modules/capture-website/index.js:162:10)
Emitted 'error' event on Client instance at:
    at emitUnhandledRejectionOrErr (node:events:383:10)
    at processTicksAndRejections (node:internal/process/task_queues:85:21) {
  originalMessage: 'No node with given id found'
}
Summaw commented 2 years ago

Hello there, Can you upload some of your code? I might be able to see if your missing something... or you can try adding this with headless: false mode: browser.on('targetcreated', async target => { if (target.type() === 'page') { const page = await target.page() await page.target().createCDPSession() } })

DNAScanner commented 2 years ago

This is my code. It worked until a few days

await new Pageres({delay: 3, script: `./web_scripts/google_translate/run.js`})
            .source(translationUrl, ["1920x1080"], {filename: `${imageId}`, selector: `body > c-wiz:nth-of-type(1) > div:nth-of-type(1) > div:nth-of-type(2) > c-wiz:nth-of-type(1) > div:nth-of-type(2) > c-wiz:nth-of-type(1) > div:nth-of-type(1)`})
            .destination("./images/")
            .run();
Summaw commented 2 years ago

You could try waiting for the selector to appear. Like set a timeout before continuing

DNAScanner commented 2 years ago

Do you mean delay?

Summaw commented 2 years ago

So no, you already have a delay of 3 seconds there... what im saying is have puppeteer wait for the selector maybe something like page.waitForSelector('body > c-wiz:nth-of-type(1) > div:nth-of-type(1) > div:nth-of-type(2) > c-wiz:nth-of-type(1) > div:nth-of-type(2) > c-wiz:nth-of-type(1) > div:nth-of-type(1)', {timeout: 10 * 1000})`

so instead of what your doing try something like this: await new Pageres({ delay: 3, beforeScreenshot: async (page, browser) => { await checkSomething(); await page.waitForSelector('body > c-wiz:nth-of-type(1) > div:nth-of-type(1) > div:nth-of-type(2) > c-wiz:nth-of-type(1) > div:nth-of-type(2) > c-wiz:nth-of-type(1) > div:nth-of-type(1)', {timeout: 10 * 1000}) await page.click('do something with that selector or any other selector'); // you might not need this. } }) .source(translationUrl, ["1920x1080"],{filename: ${imageId}}) .destination('./images/') .run();

console.log('finished so and so');

DNAScanner commented 2 years ago

Plottwist, google just did some stuff i didnt like so that was the actual reason, why that stuff didn't work. Thanks anyways