Skip to content

Commit

Permalink
Merge pull request #1369 from macbre/puppeteer/22.10.0
Browse files Browse the repository at this point in the history
bump puppeteer to v22.10.0 [HeadlessChrome/125.0.0.0]
  • Loading branch information
macbre authored May 24, 2024
2 parents 458d99f + 284b8b3 commit 40c92bb
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 44 deletions.
2 changes: 1 addition & 1 deletion core/scope.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* phantomas browser "scope" with helper code
*
* Code below is executed in page's "scope" (injected by lib/browser.js)
* Code below is executed in page's "scope" (injected by the scope.injectJs() helper)
*/
/* istanbul ignore next */
(function coreScope(scope) {
Expand Down
2 changes: 1 addition & 1 deletion lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Browser.prototype.init = async (phantomasOptions) => {
var meta = responses[data.requestId];

/* istanbul ignore if */
if (typeof meta === "undefined") {
if (typeof meta?.response === "undefined") {
// the browser sometimes looses trace of a request, let's ignore.
networkDebug(
"Can't find request id %d in previous requests",
Expand Down
14 changes: 10 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ function phantomas(url, opts) {
return page.$$(selector);
},

// @see https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pageevaluateonnewdocumentpagefunction-args
// @see https://pptr.dev/api/puppeteer.page.evaluateonnewdocument
// Adds a function which would be invoked in when:
// - the child frame is attached or navigated
// - the page is navigated
injectJs: async (script) => {
const debug = require("debug")("phantomas:injectJs");

Expand All @@ -98,7 +101,9 @@ function phantomas(url, opts) {
suffix = "}";

const preloadFile =
prefix + require("fs").readFileSync(script, "utf8") + suffix;
prefix +
(await require("fs/promises").readFile(script, "utf8")) +
suffix;

await page.evaluateOnNewDocument(preloadFile);

Expand All @@ -117,8 +122,9 @@ function phantomas(url, opts) {
// @see https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pageexposefunctionname-puppeteerfunction
await page.exposeFunction("__phantomas_emit", scope.emit);

// Inject helper code into the browser's scope
events.on("init", () => {
// Inject helper code into the browser's scope (but only once!)
events.once("init", () => {
debug("onInit: injecting the core/scope.js ...");
scope.injectJs(__dirname + "/../core/scope.js");
});

Expand Down
10 changes: 7 additions & 3 deletions modules/domComplexity/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,17 @@
})();

// count <iframe> tags
document.querySelectorAll("iframe").forEach(function (iframe) {
phantomas.incrMetric("iframesCount"); // @desc number of iframe nodes
const iframes = document.querySelectorAll("iframe");
phantomas.setMetric("iframesCount", iframes.length); // @desc number of iframe nodes

for (const iframe of iframes) {
phantomas.log(`iframe: ${iframe.src}`);

phantomas.addOffender("iframesCount", {
element: phantomas.getDOMPath(iframe),
url: iframe.src,
});
});
}

phantomas.spyEnabled(true);
});
Expand Down
66 changes: 33 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"decamelize": "^5.0.0",
"fast-stats": "0.0.6",
"js-yaml": "^4.0.0",
"puppeteer": "^22.7.1"
"puppeteer": "^22.10.0"
},
"devDependencies": {
"@jest/globals": "^28.0.0",
Expand Down Expand Up @@ -62,7 +62,7 @@
"coverageThreshold": {
"global": {
"statements": 89,
"branches": 85,
"branches": 80,
"functions": 89,
"lines": 89
}
Expand Down

0 comments on commit 40c92bb

Please sign in to comment.