Puppeteer: EPERM error attempting to run example

Created on 16 Aug 2017  ·  42Comments  ·  Source: puppeteer/puppeteer

Trying to run the following code:

var puppeteer = require("puppeteer");

puppeteer.launch().then(async browser => {
    let page = await browser.newPage();
    await page.goto('https://google.com');
    await page.screenshot({ path: 'screenshot.png' });
    browser.close();
});

I got an error:

Error: EPERM: operation not permitted, unlink 'C:\Users\tivac\Desktop\puppeteer-testing\node_modules\puppeteer\.dev_profile1\CrashpadMetrics-active.pma'

In the course of debugging this set DEBUG=* to try and understand where things were failing, but after doing that it then worked fine. 😕

Does the first-run experience not quite work right in non-DEBUG modes? I'm not sure, but that's what happened for me!

bug host

Most helpful comment

I have a solution, you have to close the page before closing the browser. Of course if you have more pages open, close all of them.
await page.close(); await browser.close();

Was having an issue with await browser.close() but thanks to @ivangergo3's answer adding a couple lines to close all the pages gets rid of the crash error! 😄

let pages = await browser.pages()
await Promise.all(pages.map(page =>page.close()))
await browser.close()

Edit 12/17/2020

  • fixed missing parentheses mentioned below

All 42 comments

Speculating: you might've accidentally launched the script twice, and two parallel puppeteers tried to run chrome with the same profile folder - .dev_profile1.

We should generate profile folder names randomly so that parallel runs of puppeteer work fine.

It's possible! Seems unlikely though as I was launching node via the CLI and not doing anything different beyond originally setting headless : false since I wanted to see the browser. It repro'd every time until setting DEBUG, at which point everything began working perfectly.

+1

Hi,
I freshly used with only puppeteer, but still got the same error. I used the https://github.com/GoogleChrome/puppeteer/#usage first example script.

I've been running into this problem as well, though with an even simpler example script that just launches the browser and then immediately tries to close it:

const puppeteer = require('puppeteer');

(async () => {
  console.log("Launching browser.");

  const browser = await puppeteer.launch();

  console.log("Closing browser.");

  browser.close();
})();

I've tried manually deleting the node_modules/puppeteer/.dev_profile1 directory before running this script, and the error still occurs.

As a workaround, I've found that simply calling process.exit(0) when I'm finished works okay--puppeteer seems to be very nice about cleaning up any launched Chromium child processes even in the case of unexpected parent process termination, so that's great!

I was seeing this the first couple times I ran the usage demo, but I didn't get it every time. About ten minutes later, I see far more successes than errors running the script. I'm not sure if that helps or not.

same problem, windows 10, node v7.10.0, puppeteer 1.0.0. setting DEBUG=* doesn't help, tried running as admin

D:\puppeteer>node index.js
fs.js:1081
  return binding.unlink(pathModule._makeLong(path));
                 ^

Error: EPERM: operation not permitted, unlink 'D:\puppeteer\node_modules\puppeteer\.dev_profile1\CrashpadMetrics-active.pma'
    at Object.fs.unlinkSync (fs.js:1081:18)
    at fixWinEPERMSync (D:\puppeteer\node_modules\rimraf\rimraf.js:210:13)
    at rimrafSync (D:\puppeteer\node_modules\rimraf\rimraf.js:310:28)
    at D:\puppeteer\node_modules\rimraf\rimraf.js:341:5
    at Array.forEach (native)
    at rmkidsSync (D:\puppeteer\node_modules\rimraf\rimraf.js:340:26)
    at rmdirSync (D:\puppeteer\node_modules\rimraf\rimraf.js:333:7)
    at fixWinEPERMSync (D:\puppeteer\node_modules\rimraf\rimraf.js:208:5)
    at rimrafSync (D:\puppeteer\node_modules\rimraf\rimraf.js:310:28)
    at ChildProcess.chromeProcess.on (D:\puppeteer\node_modules\puppeteer\lib\Launcher.js:87:7)

+1

same problem, windows 10, node v8.4.0, puppeteer 0.9.0

Everybody: could you please check if tip-of-tree puppeteer works for you? There have been some changes that might address this.

Windows 7 x64, Node .js 8.4.0.
With tip-of-tree puppeteer and example code from README.md, now I consistently get this error:

(node:1040) UnhandledPromiseRejectionWarning:
Unhandled promise rejection (rejection id: 1):
Error: EPERM: operation not permitted,
unlink 'c:\Windows\Temp\puppeteer_dev_profile-dgXrpD\CrashpadMetrics-active.pma'

(node:1040) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated.
In the future, promise rejections that are not handled
will terminate the Node.js process with a non-zero exit code.

Profile folders remain in the c:\Windows\Temp\.

Each folder contains 2 files with a lock sign (access for system and admins only):

DevToolsActivePort
CrashpadMetrics-active.pma

I didn't have any issues when I installed from latest. Caveat: I used a very different setup than what I had when I posted on this issue. At that time, I was integrating Puppeteer into an existing project, and after I got the error a couple of times, it just stopped erroring for some reason.

However, I wanted to give this update a test. I figured creating a new project was the easiest way to test this. I created a new project. I installed with yarn add puppeteer@latest. I ran an index.js file containing the readme example, and everything worked just fine every time I executed it. So... maybe it's fixed? Like I said, this was a different setup than what I had before, so it's not a terribly scientific experiment.

FWIW:

'use strict';

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  try { await browser.close(); } catch (err) { console.log(err); }
})();
{ Error: EPERM: operation not permitted,
  unlink 'c:\Windows\Temp\puppeteer_dev_profile-BzkIJu\CrashpadMetrics-active.pma'
    at Object.fs.unlinkSync (fs.js:1067:18)
    at fixWinEPERMSync (...\node_modules\rimraf\rimraf.js:210:13)
    at rimrafSync (...\node_modules\rimraf\rimraf.js:310:28)
    at ...\node_modules\rimraf\rimraf.js:341:5
    at Array.forEach (<anonymous>)
    at rmkidsSync (...\node_modules\rimraf\rimraf.js:340:26)
    at rmdirSync (...\node_modules\rimraf\rimraf.js:333:7)
    at fixWinEPERMSync (...\node_modules\rimraf\rimraf.js:208:5)
    at rimrafSync (...\node_modules\rimraf\rimraf.js:310:28)
    at killChromeAndCleanup (...\node_modules\puppeteer\lib\Launcher.js:103:7)
  errno: -4048,
  code: 'EPERM',
  syscall: 'unlink',
  path: 'c:\\Windows\\Temp\\puppeteer_dev_profile-BzkIJu\\CrashpadMetrics-active.pma' }

I am getting the same unlink error on CrashpadMetrics-active.pma.

Windows 7 Pro machine with fresh installs of Node 8.4.0 and puppeteer 0.9.0 from yesterday.

Yes, should be fixed now.

I got same problem with default chromium instillation with puppeteer but I solved by using chrome instead of the chromium

I am using puppeteer to extract data and push it into a db since the data is more i subdivided the data and running multiple instances in different computers but then i am getting the same error. Please help @aslushnikov

+1

+1 on puppeteer 5.2.1, node v12.14.0, windows7 only when using headless false

I have a solution, you have to close the page before closing the browser. Of course if you have more pages open, close all of them.
await page.close(); await browser.close();

I have been closing the page, but this problem appears only in windows so i used ubuntu and everything went smoothly

Having the same issue ... can anyone help to take a look ? Thanks!

+1 headless true/false, and await closing browser made no difference. Windows 10, node 13.10.0, puppeteer v5.2.1

I just got the same issue once, it seems to be random on win 10, puppeteer 4.0.1, I think this bug should be reopened

Same problem for me! Windows 10, puppeteer v5.2.1.

Same problem, no issues when running headless.

Same , error happens on windows 10

Same over here

Same Problem here.
[Error: EPERM: operation not permitted, unlink 'C:\Users\xxxxxx\AppData\Local\Temp\1\puppeteer_dev_chrome_profile-sj0wiy\CrashpadMetrics-active.pma'] {
errno: -4048,
code: 'EPERM',
syscall: 'unlink',
path: 'C:\Users\xxxxxxx\AppData\Local\Temp\1\puppeteer_dev_chrome_profile-sj0wiy\CrashpadMetrics-active.pma'
}
Can some one open the issue with the dev team?

Any news regarding the issue?

We still get this with 5.2.1

Seeing this on 5.3.1 as well

I'm getting this on 5.3.1 as well.

Please, reopen this issue. Still happening.

I have a solution, you have to close the page before closing the browser. Of course if you have more pages open, close all of them.
await page.close(); await browser.close();

Was having an issue with await browser.close() but thanks to @ivangergo3's answer adding a couple lines to close all the pages gets rid of the crash error! 😄

let pages = await browser.pages()
await Promise.all(pages.map(page =>page.close()))
await browser.close()

Edit 12/17/2020

  • fixed missing parentheses mentioned below
let pages = await browser.pages()
await Promise.all(pages.map(page =>page.close())
await browser.close()

let pages = await browser.pages()
await Promise.all(pages.map(page =>page.close())) //one closing bracket is missing in the above code
await browser.close()

I am closing all the pages before closing browser, but still seeing this issue. Anyone else the same?

i have same problem with multiples open and close chromium, i think it's concurrence

I ended up fixing it in a somewhat ugly way by doing browser.process().kill('SIGKILL'); instead of await browser.close(); And the issue never happended again. Any drawbacks of this?

Yes the drawback is that it's not documented in the api and it's a
workaround not a solution. The puppeteer dev team should push a fix. Thanks
anyway for the notice :-)

On Fri, Dec 18, 2020, 06:03 caihongxu notifications@github.com wrote:

I ended up fixing it in a somewhat ugly way by doing
browser.process().kill('SIGKILL'); instead of await browser.close(); And
the issue never happended again. Any drawbacks of this?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/puppeteer/puppeteer/issues/298#issuecomment-747869465,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ACLIE5B26YARSKBV22ZNKATSVLPBJANCNFSM4DXFG7VQ
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

selfrefactor picture selfrefactor  ·  3Comments

barnash picture barnash  ·  3Comments

sheweichun picture sheweichun  ·  3Comments

mityok picture mityok  ·  3Comments

paulirish picture paulirish  ·  3Comments