Skip to content

feat: expose sync js exec methods on WebFrame - #21315

Closed
bughit wants to merge 1 commit into
electron:masterfrom
bughit:web-frame-sync-js
Closed

bughit wants to merge 1 commit into
electron:masterfrom
bughit:web-frame-sync-js

Conversation

@bughit

@bughit bughit commented Nov 27, 2019

Copy link
Copy Markdown
Contributor

Description of Change

Before the promisification (#17312) of WebFrame#executeJavaScript* their interface was async (callback) but behavior was sync (callback called before the methods returned). So they could be used in sync code (or async, you could wrap them in a promise yourself). The switch from a callback to a promise interface made it impossible to use them in sync mode (#19161), which was a breaking change without a workaround.

This PR exposes the sync js exec methods on WebFrame, providing a workaround for code that used the original methods synchronously. In general, a sync in-process js eval makes perfect sense, because it's sync under the hood.

Fixes #19161

Checklist

Release Notes

Notes: add sync javascript execution methods to WebFrame

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Nov 27, 2019
@bughit bughit changed the title expose sync js exec interface on WebFrame feat: expose sync js exec methods on WebFrame Nov 27, 2019
@bughit

bughit commented Nov 27, 2019

Copy link
Copy Markdown
Contributor Author

It appears some commit hook is converting all .md filed to crlf. I am checking it as lf and have no conversion enabled.

@MarshallOfSound MarshallOfSound left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is deprecated in blink and will be removed in a future version. I'm against adding a dependency on a method that we know is going to be removed.

https://cs.chromium.org/chromium/src/third_party/blink/public/web/web_local_frame.h?type=cs&q=ExecuteScriptInIsolatedWorldAndReturnValue&sq=package:chromium&g=0&l=308

@bughit

bughit commented Nov 28, 2019

Copy link
Copy Markdown
Contributor Author

RequestExecuteScriptAndReturnValue used by the current method is also deprecated. So it did not seem wrong to use a deprecated method.

Is it also going to be removed? Then what's the right method to use? The deprecation comment says "Prefer requestExecuteScriptInIsolatedWorld", assuming they mean RequestExecuteScriptInIsolatedWorld, it does not work for the main world: "worldID must be > 0 (as 0 represents the main world)."

@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Nov 28, 2019
@MarshallOfSound

Copy link
Copy Markdown
Member

@bughit As our current implementation returns a promise we can transparently switch to using RequestExecuteScriptInIsolatedWorld internally without any API changes.

There is the current limitation on Chromium's side that that API does not allow you to pass in the main world ID, but that seems easily fix-able and we will probably do that.

We can't support a synchronous version here with Chromium's intention to remove all synchronous versions of those APIs.

@bughit

bughit commented Nov 29, 2019 •

Copy link
Copy Markdown
Contributor Author

Chromium's intention to remove all synchronous versions of those APIs.

@MarshallOfSound not sync execution

https://cs.chromium.org/chromium/src/third_party/blink/public/web/web_local_frame.h?l=364

The chrome APIs have an async (callback) interface but they can be executed synchronously and that's not going away. Please reopen this, I can at least try adding sync versions using the exiting APIs (RequestExecuteScript..). Please understand that for years these could be used synchronously without any issue, consistently, reliably, with no exceptions, despite having callback interface, and still can be.

@bughit

bughit commented Nov 29, 2019

Copy link
Copy Markdown
Contributor Author

@MarshallOfSound It is definitely possible to add a sync method based on RequestExecuteScript, that returns the value delivered by the sync callback and throws if the callback was not called (it will quietly delete itself when called later). The only reason it would ever not be called sync is if the FrameLifecycleState is not kRunning,

https://cs.chromium.org/chromium/src/third_party/blink/renderer/core/execution_context/execution_context.cc?l=158

something I have never seen, I am guessing it never just happens spontaneously, but regardless, that possibility would be covered.

Do object to even that? Why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

promisifying WebFrame.executeJavaScript(InIsolatedWorld) is a breaking change without a workaround

2 participants