cant get the right resulting value when use script execution by promise

68 views
Skip to first unread message

电里

unread,
Jul 20, 2023, 8:48:41 PM7/20/23
to Chromium Extensions
"If the resulting value of the script execution is a promise, Chrome will wait for the promise to settle and return the resulting value."
But when I execute according to the code in the demo, the result is returned immediately, and the result is null.
截屏2023-07-21 08.45.45.png截屏2023-07-21 08.45.59.png截屏2023-07-21 08.44.47.png

wOxxOm

unread,
Jul 21, 2023, 1:12:09 AM7/21/23
to Chromium Extensions, 电里
Your code is incorrect, you can't access a cross-origin frame's contentWindow, so it throws an exception, but currently such errors aren't reported back to executeScript, which is why you get a `null`, see https://crbug.com/1271527. The workaround for the lack of error reporting is to wrap the code in try/catch to handle any potential exceptions explicitly.

The solution to your original task is to run a new content script in the iframe, which you can do either declaratively (manifest.json or via registerContentScripts) or via executeScript with allFrames or frameIds parameter. This content script will run inside the iframe and be able to access its `document` and `window` directly.

电里

unread,
Jul 21, 2023, 11:26:04 AM7/21/23
to Chromium Extensions, wOxxOm, 电里
thank you so much!
Reply all
Reply to author
Forward
0 new messages