Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPERM error attempting to run example #298

Closed
tivac opened this issue Aug 16, 2017 · 63 comments
Closed

EPERM error attempting to run example #298

tivac opened this issue Aug 16, 2017 · 63 comments
Assignees

Comments

@tivac
Copy link

tivac commented Aug 16, 2017

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!

  • puppeteer@0.9.0
  • npm@5.3.0
  • node@8.2.1
  • Windows 10 Version 1607 (OS Build 14393.1593)
@aslushnikov aslushnikov self-assigned this Aug 16, 2017
@aslushnikov
Copy link
Contributor

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.

@tivac
Copy link
Author

tivac commented Aug 16, 2017

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.

@builden
Copy link

builden commented Aug 17, 2017

+1

@vinaybedre
Copy link

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.

@toolness
Copy link

toolness commented Aug 17, 2017

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!

@awayken
Copy link

awayken commented Aug 18, 2017

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.

@webuniverseio
Copy link

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)

@PlanetIrata
Copy link

+1

@islq
Copy link

islq commented Aug 22, 2017

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

@aslushnikov
Copy link
Contributor

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

@vsemozhetbyt
Copy link
Contributor

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\.

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Aug 22, 2017

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

DevToolsActivePort
CrashpadMetrics-active.pma

@awayken
Copy link

awayken commented Aug 22, 2017

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.

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Aug 22, 2017

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' }

@opub
Copy link

opub commented Aug 22, 2017

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.

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Aug 23, 2017

Seems to be fixed for me (Windows 7 x64) after ac109db

@aslushnikov
Copy link
Contributor

Yes, should be fixed now.

@lumosmind
Copy link

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

@bhanuprakash9980
Copy link

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

@winsjos
Copy link

winsjos commented Aug 20, 2020

+1

@caihongxu
Copy link

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

@felipemmorisson
Copy link

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

@caihongxu
Copy link

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?

@rbenzazon
Copy link

rbenzazon commented Dec 18, 2020 via email

@pierreminiggio
Copy link

pierreminiggio commented Jan 7, 2021

Hello guys, just had this error in the latest version, in my case it was because I forgot an "await" before a "browser.close()". So you should close the browser like this :

await browser.close()

My await was already missing before, but It didn't show any error before I installed my project on another computer. So make sure not to forget your awaits just like me :P

EDIT : Nevermind, it happens randomly even after making sure the await is there. And The issue started appearing on other projects that were fine before.

@kodelio
Copy link

kodelio commented Jan 8, 2021

Hello,
Neither closing all pages before closing browser or using browser.process().kill('SIGKILL'); is working for me. The issue occurs randomly.

@nick-loginov
Copy link

Hello guys, just had this error in the latest version, in my case it was because I forgot an "await" before a "browser.close()". So you should close the browser like this :

await browser.close()

My await was already missing before, but It didn't show any error before I installed my project on another computer. So make sure not to forget your awaits just like me :P

EDIT : Nevermind, it happens randomly even after making sure the await is there. And The issue started appearing on other projects that were fine before.

+1

@cogitozz
Copy link

Hello,
Neither closing all pages before closing browser or using browser.process().kill('SIGKILL'); is working for me. The issue occurs randomly.

+1

@Revadike Revadike mentioned this issue Jan 30, 2021
@caihongxu
Copy link

browser.process().kill

Using browser.process().kill() had been working well for me so far (since the last time I posted). Note that in order for this to work you need to remove both browser.close() and page.close() code, otherwise you will still get stuck.

@manuel-di-iorio
Copy link

Closing all browser pages before invoking close() worked for me (thanks @ CreativeBuilds)

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

@kodelio
Copy link

kodelio commented Feb 2, 2021

browser.process().kill

Using browser.process().kill() had been working well for me so far (since the last time I posted). Note that in order for this to work you need to remove both browser.close() and page.close() code, otherwise you will still get stuck.

Not working for me :(

@KrakerXyz
Copy link

KrakerXyz commented Feb 9, 2021

I started getting this error on a Windows box but it was after other changes I made trying to get puppeteer to run in a Debian VM. One of the things I had to do for Debian was to add '--no-sandbox', '--disable-setuid-sandbox' arguments. Once I removed those, it started working on Windows again.

I forget the exact reason I had needed to add them to for Debian.

@rishabh-pachori-habilelabs

Hello guys, just had this error in the latest version, in my case it was because I forgot an "await" before a "browser.close()". So you should close the browser like this :

await browser.close()

My await was already missing before, but It didn't show any error before I installed my project on another computer. So make sure not to forget your awaits just like me :P
EDIT : Nevermind, it happens randomly even after making sure the await is there. And The issue started appearing on other projects that were fine before.

+1

+1

@NotWearingPants
Copy link

The workaround isn't working for me, I believe the reproduction of this bug is dependent on how fast the computer is.
This is my repro, gets the EPERM after 1-5 loops:

const puppeteer = require('puppeteer');
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
(async () => {
	while (true) {
		console.log('launching');
		const browser = await puppeteer.launch({ headless: false, args: ['--no-sandbox'] });
		console.log('sleeping');
		await sleep(1000);
		console.log('closing pages');
		await Promise.all((await browser.pages()).map(async page => await page.close()));
		console.log('closing');
		await browser.close();
		console.log('sleeping');
		await sleep(1000);
	}
})();

I believe the headless: false, --no-sandbox, closing each page, and also the console.logs, all make the entire thing somehow slower in the right places, and cause the crashpad process to stay alive long enough so that rimrafs timeouts and throws the error (about 600ms).

A possible solution (which is bad but works) is to increase rimrafs maxBusyTries option so that it would retry a bit more, eventually it works. A better solution is to disable the crashpad process - #2778.

@kodelio
Copy link

kodelio commented Mar 12, 2021

The workaround isn't working for me, I believe the reproduction of this bug is dependent on how fast the computer is.
This is my repro, gets the EPERM after 1-5 loops:

const puppeteer = require('puppeteer');
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
(async () => {
	while (true) {
		console.log('launching');
		const browser = await puppeteer.launch({ headless: false, args: ['--no-sandbox'] });
		console.log('sleeping');
		await sleep(1000);
		console.log('closing pages');
		await Promise.all((await browser.pages()).map(async page => await page.close()));
		console.log('closing');
		await browser.close();
		console.log('sleeping');
		await sleep(1000);
	}
})();

I believe the headless: false, --no-sandbox, closing each page, and also the console.logs, all make the entire thing somehow slower in the right places, and cause the crashpad process to stay alive long enough so that rimrafs timeouts and throws the error (about 600ms).

A possible solution (which is bad but works) is to increase rimrafs maxBusyTries option so that it would retry a bit more, eventually it works. A better solution is to disable the crashpad process - #2778.

Disabling crashpad is actually not working, so not solving the initial issue

@waterss
Copy link

waterss commented Mar 22, 2021

Removing "args: ["--no-sandbox"]" from my "jest-puppeteer.config.js" file, module.exports object makes this work on windows 10. My module.exports now looks like:

module.exports = {
launch: {
headless: false,
ignoreHTTPSErrors: true,
defaultViewport: { width: 1600, height: 900 },
// slowMo: 100,
// devtools: true,
},
};

my package.json looks like:

{
"name": "jest-cucumber-puppeteer-testing",
"version": "1.0.0",
"description": "jest cucumber puppeteer testing prototype",
"main": "index.js",
"scripts": {
"test": "env-cmd -f .env jest --runInBand",
"report": "node ./cucumber-report-config.js"
},
"runner": "jest-serial-runner",
"author": "",
"license": "",
"dependencies": {
"@types/expect-puppeteer": "^4.4.3",
"@types/jest-environment-puppeteer": "^4.3.2",
"@types/puppeteer": "^3.0.1",
"cucumber-html-reporter": "^5.2.0",
"dotenv": "^8.2.0",
"env-cmd": "^10.1.0",
"i": "^0.3.6",
"jasmine": "^3.7.0",
"jest-cucumber": "2.0.12",
"jest-puppeteer": "^4.4.0",
"jest-serial-runner": "^1.1.0",
"puppeteer": "^5.5.0",
"yarn": "^1.22.10"
},
"jest": {
"preset": "jest-puppeteer",
"setupFiles": [
"dotenv/config"
],
"testMatch": [
"**/*.steps.js"
],
"reporters": [
"default",
[
"./node_modules/jest-cucumber/dist/src/reporter",
{
"formatter": "json"
}
]
]
}
}

@anotherawesomeprojects
Copy link

Closing all browser pages before invoking close() worked for me (thanks @ CreativeBuilds)

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

Still not work for me, I've tried all approach above, but no one work for me :(

@fdterr
Copy link

fdterr commented Apr 8, 2021

I started getting this error on a Windows box but it was after other changes I made trying to get puppeteer to run in a Debian VM. One of the things I had to do for Debian was to add '--no-sandbox', '--disable-setuid-sandbox' arguments. Once I removed those, it started working on Windows again.

I forget the exact reason I had needed to add them to for Debian.

I had the exact same situation and this seems to have worked for me

@alamothe
Copy link

alamothe commented Jun 3, 2021

#6946 is the only real fix short of switching away from Windows.

bdumitru added a commit to bdumitru/puppeteer that referenced this issue Jul 2, 2021
Fix for: puppeteer#6946, puppeteer#298 etc. (MAJOR PRIORITY)

Problem description:
WINDOWS ONLY!
Any process involving this library would completely crash ungracefully if browser.close() is unable to delete the /temp/ folder, because the promise never gets fulfilled or rejected.
Problem tends to happen on slower computers/VMs or environments with limited access to appdata/local folder.
Issue can be hard to reproduce in a lot of cases.

Solution:
fulfill() in catch for removeFolderAsync(this._tempDirectory)
Alternative solutions:
- SIMPLE, but not ideal: throw(error) instead, remove console.error(error).
- HARDER, ideal: add WORKING runtime arguments to disable Crashpad-Metrics.
@warsmit
Copy link

warsmit commented Aug 11, 2021

I use

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

Thank you. This is working for me.
I use metamask extension (dappeteer) for tests. Sometimes tests cannot close wallet request. This workaround help with this issue.

@alamothe
Copy link

alamothe commented Oct 9, 2021

I would like to report that, while this fix works (I prefer resolved vs rejected) and doesn't hang the browser, there is still a lot of instability caused by removing the temporary directory. Our production service on Windows crashes ever so often due to that. Right now the way we patched this is to schedule (setTimeout) deleting temp folder after a minute instead of immediately during close. Will report if this fully resolves the problem.

@MahbbRah
Copy link

#6341 (comment)

@alamothe
Copy link

@MahbbRah sadly doesn't work. This is not user profile but crashpad and metrics.

@MahbbRah
Copy link

@MahbbRah sadly doesn't work. This is not a user profile but a crashpad and metrics.

For me as well it didn't work. the issue is it kept working suddenly got that bug again. But Yes I fixed it for my case it was this issue and this way I solved it.

image

@talles-coder
Copy link

Hello, I know it's not the prettiest thing, but I managed to solve this error using the home page that is created when using "puppeteer.launch()" instead of creating a new page,

I changed:

const page = wait browser.newPage();

for:

const pages = await browser.pages();
const firstPage = page[0]

By Cromium's rule, if all tabs/pages are closed it will also close so you don't need to use the command "await browser.close()"
at the end of it all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests