calling addScriptTag returns Unhandled promise rejection (rejection id: 1): Error: Evaluation failed: Event
See original GitHub issueSteps to reproduce
Tell us about your environment:
- Puppeteer version: “^1.4.0”
- Platform / OS version: macOS 10.13.1
- URLs (if applicable): https://github.com/webAutomaticTest/pageEvaluate
- Node.js version: v8.11.2 I download the optimal-select.js from https://cdnjs.cloudflare.com/ajax/libs/optimal-select/4.0.1/optimal-select.js
What steps will reproduce the problem? I want to do automatic test about web applications.
- 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:
- Created 5 years ago
- Comments:9 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@yanivefraim for me, I call page.setBypassCSP(true) before navigating temporarily solve my problem.
@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/1624This would be nice to have though specifically for the
addScriptTag
andaddStyleTag
methods since they are hitting our users most.