chrome-page-eval
Advanced tools
Comparing version
@@ -67,2 +67,4 @@ 'use strict' | ||
args = [], | ||
waitForJS = false, | ||
waitForJSVarName = 'CHROME_PAGE_EVAL_READY', | ||
waitUntil, | ||
@@ -150,2 +152,7 @@ // use the same default value of puppeteer | ||
if (waitForJS === true) { | ||
debugMe('Chrome will wait for JS trigger..') | ||
await page.waitForFunction(`window.${waitForJSVarName} === true`, { timeout }) | ||
} | ||
debugMe('evaluating scriptFn with args:', args) | ||
@@ -152,0 +159,0 @@ |
{ | ||
"name": "chrome-page-eval", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Evaluate a script function on a page with Chrome", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -71,2 +71,53 @@ 'use strict' | ||
it('should wait for JS trigger to start to eval', async () => { | ||
const result = await chromeEval({ | ||
html: path.join(__dirname, 'sampleJSTrigger.html'), | ||
waitForJS: true, | ||
scriptFn: ` | ||
function () { | ||
let title = document.title | ||
let content = Array.from(document.querySelectorAll('.content'), (node) => { | ||
return node.textContent | ||
}) | ||
return { | ||
title, | ||
content | ||
} | ||
} | ||
` | ||
}) | ||
should(result).be.Object() | ||
should(result.title).be.eql('Test page') | ||
should(result.content).have.length(5) | ||
}) | ||
it('should wait for JS trigger to start to eval (custom var name)', async () => { | ||
const result = await chromeEval({ | ||
html: path.join(__dirname, 'sampleJSTrigger2.html'), | ||
waitForJS: true, | ||
waitForJSVarName: 'READY_TO_START', | ||
scriptFn: ` | ||
function () { | ||
let title = document.title | ||
let content = Array.from(document.querySelectorAll('.content'), (node) => { | ||
return node.textContent | ||
}) | ||
return { | ||
title, | ||
content | ||
} | ||
} | ||
` | ||
}) | ||
should(result).be.Object() | ||
should(result.title).be.eql('Test page') | ||
should(result.content).have.length(5) | ||
}) | ||
it('should pass custom args to script', async () => { | ||
@@ -73,0 +124,0 @@ const result = await chromeEval({ |
19866
15.11%13
18.18%336
17.07%