question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

calling addScriptTag returns Unhandled promise rejection (rejection id: 1): Error: Evaluation failed: Event

See original GitHub issue

Steps to reproduce

Tell us about your environment:

What steps will reproduce the problem? I want to do automatic test about web applications.

  1. run to test with command:
node index.js

the code in index.js:

const puppeteer = require('puppeteer');

test();

async function test(){
	const browser = await puppeteer.launch({headless: false, args:['--no-sandbox']});
	const page = await browser.newPage();
	await page.goto('https://twitter.com/');
	// await page.goto('https://apples-oranges.herokuapp.com/');
	await page.addScriptTag({path:'./optimal-select.js'});
	
	let candidateSelector = await page.evaluate(scanCandidateAction);
	console.log(candidateSelector);
}

function scanCandidateAction() {
	let actions = [];
	let computeCSSSelector = window['OptimalSelect'].select;
	let aElements = document.querySelectorAll('a');
	for (let i=0 ; i < aElements.length ; i++) {
		if (! isMailTo(aElements[i])) actions.push(computeCSSSelector(aElements[i]));
	}

	return actions;

	function isMailTo(element) {
		let href = element.href;
		return href && (href.toLowerCase().indexOf('mailto') > -1)		
	}
}

What is the expected result? array of CSS Selector What happens instead? it faled with error: (node:83553) UnhandledPromiseRejectionWarning: Error: Evaluation failed: Event It stoped and filed in this line:

await page.addScriptTag({path:'./optimal-select.js'});

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
chenweiLabricommented, Jun 11, 2018

@yanivefraim for me, I call page.setBypassCSP(true) before navigating temporarily solve my problem.

2reactions
aslushnikovcommented, May 31, 2018

@chenweiLabri yes, this is due to CSP. if you call page.setBypassCSP(true) before navigating, the issue goes away.

Our error is not very descriptive though; it should be possible to detect CSP violation using the Log.entryAdded protocol event. There’s been an effort before but we didn’t finish it: https://github.com/GoogleChrome/puppeteer/pull/1624

This would be nice to have though specifically for the addScriptTag and addStyleTag methods since they are hitting our users most.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is an unhandled promise rejection? - Stack Overflow
I am getting an error like this: (node:4796) UnhandledPromiseRejectionWarning: Unhandled promise rejection (r ejection id: 1): ...
Read more >
Handling those unhandled promise rejections with JS async ...
One of your await ed functions fails (i.e. rejects a promise); You get the error. Another possibility is that you know you need...
Read more >
Window: unhandledrejection event - Web APIs | MDN
The unhandledrejection event is sent to the global scope of a script when a JavaScript Promise that has no rejection handler is rejected; ......
Read more >
puppeteer document is not defined - You.com | The AI Search ...
Using getEventListeners in page. · I get this error message (node:53503) UnhandledPromiseRejectionWarning: Error: Evaluation failed: ReferenceError: ...
Read more >
Puppeteer documentation - DevDocs
returns : <Promise> Promise which resolves when the element matching selector is successfully clicked. The Promise will be rejected if there is no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found