sindresorhus / pageres

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

Error: Protocol error (Emulation.setEmulatedMedia): Invalid parameters media: string value expected #407

Closed nodecentral closed 3 years ago

nodecentral commented 3 years ago

Hi

When running any pageres-cli commands, I get the following error message - does anyone know what to do to fix it ?


pi@raspberrypi:/ $ pageres www.google.com
Error: Protocol error (Emulation.setEmulatedMedia): Invalid parameters media: string value expected
    at /usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:208:63
    at new Promise (<anonymous>)
    at CDPSession.send (/usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:207:16)
    at Page.emulateMediaFeatures (/usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:873:32)
    at captureWebsite (/usr/local/lib/node_modules/pageres-cli/node_modules/capture-website/index.js:228:13)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async Pageres.create (/usr/local/lib/node_modules/pageres-cli/node_modules/pageres/dist/index.js:176:28)
    at async /usr/local/lib/node_modules/pageres-cli/node_modules/pageres/dist/index.js:84:33
    at async Promise.all (index 0)
    at async Pageres.run (/usr/local/lib/node_modules/pageres-cli/node_modules/pageres/dist/index.js:70:9)
sindresorhus commented 3 years ago

The URL needs to start with a scheme.

nodecentral commented 3 years ago

Sorry @sindresorhus , I thought I had made that clear when I said ‘any’ pageres_cli commands - apologies .

pi@raspberrypi:/ $ pageres http://google.com 1366x768

Error: Protocol error (Emulation.setEmulatedMedia): Invalid parameters media: string value expected
    at /usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:208:63
    at new Promise (<anonymous>)
    at CDPSession.send (/usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:207:16)
    at Page.emulateMediaFeatures (/usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:873:32)
    at captureWebsite (/usr/local/lib/node_modules/pageres-cli/node_modules/capture-website/index.js:228:13)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async Pageres.create (/usr/local/lib/node_modules/pageres-cli/node_modules/pageres/dist/index.js:176:28)
    at async /usr/local/lib/node_modules/pageres-cli/node_modules/pageres/dist/index.js:84:33
    at async Promise.all (index 0)
    at async Pageres.run (/usr/local/lib/node_modules/pageres-cli/node_modules/pageres/dist/index.js:70:9)

pi@raspberrypi:/ $ pageres https://www.google.com

Error: Protocol error (Emulation.setEmulatedMedia): Invalid parameters media: string value expected
    at /usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:208:63
    at new Promise (<anonymous>)
    at CDPSession.send (/usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:207:16)
    at Page.emulateMediaFeatures (/usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:873:32)
    at captureWebsite (/usr/local/lib/node_modules/pageres-cli/node_modules/capture-website/index.js:228:13)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async Pageres.create (/usr/local/lib/node_modules/pageres-cli/node_modules/pageres/dist/index.js:176:28)
    at async /usr/local/lib/node_modules/pageres-cli/node_modules/pageres/dist/index.js:84:33
    at async Promise.all (index 0)
    at async Pageres.run (/usr/local/lib/node_modules/pageres-cli/node_modules/pageres/dist/index.js:70:9)

pi@raspberrypi:/ $

no matter what I put I’m , same error

sindresorhus commented 3 years ago

I unfortunately cannot reproduce. I would recommend ensuring you're on the latest Node.js version and then try clearing the cache (npm cache clean --force) and then reinstalling Pageres.

nodecentral commented 3 years ago

Thanks for reopening my issue, I’ve done the first two first, see findings below..

pi@raspberrypi:~ $ node -v 
v15.6.0

pi@raspberrypi:~ $ sudo npm cache clean --force
npm WARN using --force Recommended protections disabled.

Regarding the next step - is there a particular way you want me to do the reinstall? Do I just re-run ‘sudo apt-get’ install again (over the top) ? Or do I need to uninstall and then re-install ?

sindresorhus commented 3 years ago

You install with npm install --global pageres-cli, not apt-get:

npm uninstall --global pageres-cli && npm install --global pageres-cli
nodecentral commented 3 years ago

Thanks, and here’s the output of running that command..


pi@raspberrypi:~ $ sudo npm uninstall --global pageres-cli && npm install --global pageres-cli

removed 259 packages, and audited 1 package in 14s

found 0 vulnerabilities
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/pageres-cli
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/pageres-cli'
npm ERR!  [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/pageres-cli'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/usr/local/lib/node_modules/pageres-cli'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/pi/.npm/_logs/2021-01-24T19_39_28_498Z-debug.log
pi@raspberrypi:~ $
nodecentral commented 3 years ago

And, now when running a pageres command, I get the following new ERROR..


pi@raspberrypi:~ $ pageres https://www.google.com
Error: Could not find browser revision 818858. Run "PUPPETEER_PRODUCT=firefox npm install" or "PUPPETEER_PRODUCT=firefox yarn install" to download a supported Firefox browser binary.
    at ChromeLauncher.launch (/usr/lib/node_modules/pageres-cli/node_modules/puppeteer/lib/cjs/puppeteer/node/Launcher.js:79:23)
    at async captureWebsite (/usr/lib/node_modules/pageres-cli/node_modules/capture-website/index.js:180:38)
    at async Pageres.create (/usr/lib/node_modules/pageres-cli/node_modules/pageres/dist/index.js:176:28)
    at async /usr/lib/node_modules/pageres-cli/node_modules/pageres/dist/index.js:84:33
    at async Promise.all (index 0)
    at async Pageres.run (/usr/lib/node_modules/pageres-cli/node_modules/pageres/dist/index.js:70:9)
    at async generate (/usr/lib/node_modules/pageres-cli/cli.js:78:2)
    at async init (/usr/lib/node_modules/pageres-cli/cli.js:168:2)
sindresorhus commented 3 years ago

Delete /usr/local/lib/node_modules/pageres-cli and then reinstall Pageres again. It failed earlier.

nodecentral commented 3 years ago

I don’t seem to have anything in that location.

pi@raspberrypi:/usr/local/lib/node_modules $ ls -la
total 12
drwxr-sr-x  3 root staff 4096 Jan 24 19:38 .
drwxrwsr-x 10 root staff 4096 Jan 23 10:59 ..
drwxr-sr-x 10 root staff 4096 Jan 23 10:59 npm

However going into ‘npm/node_modules’ I do have a lot of folder, but nothing called ‘pageres-cli’, so I’m assuming it’s already removed. I’ve run the install again, and see results


pi@raspberrypi:/ $ sudo npm install --global pageres-cli

added 259 packages, and audited 260 packages in 5m

31 packages are looking for funding
  run `npm fund` for details

6 high severity vulnerabilities

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

Then I tried a pageres command again, but it looks like we’re back to the original error again. :(


pi@raspberrypi:/ $ pageres https://www.google.com
Error: Failed to launch the browser process!
/usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/.local-chromium/linux-818858/chrome-linux/chrome: 1: /usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/.local-chromium/linux-818858/chrome-linux/chrome: Syntax error: "(" unexpected

TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

    at onClose (/usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:193:20)
    at Interface.<anonymous> (/usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:183:68)
    at Interface.emit (node:events:391:22)
    at Interface.close (node:readline:451:8)
    at Socket.onend (node:readline:224:10)
    at Socket.emit (node:events:391:22)
    at endReadableNT (node:internal/streams/readable:1307:12)
    at processTicksAndRejections (node:internal/process/task_queues:81:21)
sindresorhus commented 3 years ago

This is a problem with installing Puppeteer. I cannot really help with that. I suggest following the troubleshooting link. Maybe there's some problem with Puppeteer when running on Raspberry PI.

I'm happy to look further into this if someone submits a failing test, but there's not much I can do about this for now, so going to close this issue.

nodecentral commented 3 years ago

Haha

I’m now in a loop as that’s where I started - https://github.com/puppeteer/puppeteer/issues/6755 - and they sent me to you :)

boyphongsakorn commented 3 years ago

I don’t seem to have anything in that location.

pi@raspberrypi:/usr/local/lib/node_modules $ ls -la
total 12
drwxr-sr-x  3 root staff 4096 Jan 24 19:38 .
drwxrwsr-x 10 root staff 4096 Jan 23 10:59 ..
drwxr-sr-x 10 root staff 4096 Jan 23 10:59 npm

However going into ‘npm/node_modules’ I do have a lot of folder, but nothing called ‘pageres-cli’, so I’m assuming it’s already removed. I’ve run the install again, and see results


pi@raspberrypi:/ $ sudo npm install --global pageres-cli

added 259 packages, and audited 260 packages in 5m

31 packages are looking for funding
  run `npm fund` for details

6 high severity vulnerabilities

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

Then I tried a pageres command again, but it looks like we’re back to the original error again. :(

pi@raspberrypi:/ $ pageres https://www.google.com
Error: Failed to launch the browser process!
/usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/.local-chromium/linux-818858/chrome-linux/chrome: 1: /usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/.local-chromium/linux-818858/chrome-linux/chrome: Syntax error: "(" unexpected

TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

    at onClose (/usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:193:20)
    at Interface.<anonymous> (/usr/local/lib/node_modules/pageres-cli/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:183:68)
    at Interface.emit (node:events:391:22)
    at Interface.close (node:readline:451:8)
    at Socket.onend (node:readline:224:10)
    at Socket.emit (node:events:391:22)
    at endReadableNT (node:internal/streams/readable:1307:12)
    at processTicksAndRejections (node:internal/process/task_queues:81:21)

hey i got a same error, how to you fix "Syntax error: "(" unexpected" that error