Skip to content

Commit c0646ea

Browse files
committed
fix: Puppeteer JavaScript world protocol errors
- Fixed _evaluateHandeInContext to use element.evaluate() directly when handle is provided - Removed incorrect extra 'el' parameter in grabHTMLFromAll - Removed incorrect extra 'el' parameter in grabCssPropertyFromAll - Installed missing Chrome dependencies (libatk, libgbm, etc.) for Ubuntu 24.04
1 parent c8f95ad commit c0646ea

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/helper/Puppeteer.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,14 @@ class Puppeteer extends Helper {
654654
}
655655
}
656656

657-
async _evaluateHandeInContext(...args) {
657+
async _evaluateHandeInContext(fn, handle, ...args) {
658+
// If handle is provided, evaluate directly on it to avoid "JavaScript world" errors
659+
if (handle) {
660+
return handle.evaluate(fn, ...args)
661+
}
662+
// Otherwise use the context
658663
const context = await this._getContext()
659-
return context.evaluateHandle(...args)
664+
return context.evaluateHandle(fn, ...args)
660665
}
661666

662667
async _withinBegin(locator) {
@@ -1925,7 +1930,7 @@ class Puppeteer extends Helper {
19251930
*/
19261931
async grabHTMLFromAll(locator) {
19271932
const els = await this._locate(locator)
1928-
const values = await Promise.all(els.map(el => el.evaluate(element => element.innerHTML, el)))
1933+
const values = await Promise.all(els.map(el => el.evaluate(element => element.innerHTML)))
19291934
return values
19301935
}
19311936

@@ -1948,7 +1953,7 @@ class Puppeteer extends Helper {
19481953
*/
19491954
async grabCssPropertyFromAll(locator, cssProperty) {
19501955
const els = await this._locate(locator)
1951-
const res = await Promise.all(els.map(el => el.evaluate(el => JSON.parse(JSON.stringify(getComputedStyle(el))), el)))
1956+
const res = await Promise.all(els.map(el => el.evaluate(el => JSON.parse(JSON.stringify(getComputedStyle(el))))))
19521957
const cssValues = res.map(props => props[toCamelCase(cssProperty)])
19531958

19541959
return cssValues

0 commit comments

Comments
 (0)