You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
promisifying WebFrame.executeJavaScript(InIsolatedWorld) is a breaking change without a workaround #19161
I agree to follow the Code of Conduct that this project adheres to.
I have searched the issue tracker for an issue that matches the one I want to file, without success.
Issue Details
Electron Version: v6.0.0-beta.12 x86
Operating System: win7 x64 sp1
Last Known Working Electron version: v5.0.6
The webFrame execute APIs have always been synchronous (which makes perfect sense, since this is in-process js evaluation), and under the hood they still are, despite now (#17312) returning promises. The callback used to deliver the result synchronously before the method returned.
There is nothing gained and only loss of flexibility when you wrap an actually sync api in a promise. It's trivial for the user to go from sync to promise (Promise.(resolve|reject)) but going from promise to sync is impossible.
So this change (for webFrame) is:
not an improvement
a breaking change for 6.0 (I have code that depends on the synchronous nature of these, which now can't even be fixed without having to become async)
Expected Behavior
existing execute methods should remain sync, they could also be improved by returning the result, in addition to invoking the sync callback (which could be deprecated for later removal)
I will try to do a pull request for this, could you please comment on what solution you would accept.
My suggestion is to keep the callback in the webFrame.execute for compat, but deprecate it, which I believe is the standard procedure for removing functionality. Additionally return the eval result, which is a compatible change (before it was undefined)
I haven't build electron in the new build system, so there may be some delay.
Since this only regressed in 6.0 I would like to address it there, before the release.
So executor->Run(); means kSynchronous which is documented in the source as Execute script synchronously, unless the page is suspended..
Initially I thought that suspended referred to to tab unloading due to memory pressure and was therefore not applicable, but it may be more complicated. After looking at PausableScriptExecutor::Run
which means a non FrameLifecycleState::kRunning state
// The frame lifecycle state.enum FrameLifecycleState {
// State is normal running.kRunning,
// Paused state is used for nested event loops. Does not fire// frozen, resumed events on the document.kPaused,
// State is frozen, pause all media. Do not resume media// when moving to kRunning.kFrozen,
// State is frozen, auto resume media when moving to kRunning.kFrozenAutoResumeMedia,
};
I still am not sure if there's a theoretical possibility of a non kRunning state in electron. I suspect a frame could not spontaneously get into such a state. Do you happen to know?
It would still be valuable to have executeJavaScriptSync and I would like to add it when I have time. If there's any possibility, however remote, of a non kRunning state, it could check for that and throw an error. But practically, always it would just work, synchronously, as before 6.0 changes.
Activity
bughit commentedon Jul 9, 2019
@miniak @MarshallOfSound
I will try to do a pull request for this, could you please comment on what solution you would accept.
My suggestion is to keep the callback in the webFrame.execute for compat, but deprecate it, which I believe is the standard procedure for removing functionality. Additionally return the eval result, which is a compatible change (before it was undefined)
I haven't build electron in the new build system, so there may be some delay.
Since this only regressed in 6.0 I would like to address it there, before the release.
bughit commentedon Jul 31, 2019
@miniak @MarshallOfSound
Did a bit more investigating
So
executor->Run();meanskSynchronouswhich is documented in the source asExecute script synchronously, unless the page is suspended..Initially I thought that
suspendedreferred to to tab unloading due to memory pressure and was therefore not applicable, but it may be more complicated. After looking atPausableScriptExecutor::RunsuspendedmeansExecutionContext::IsContextPausedwhich means a non
FrameLifecycleState::kRunningstateI still am not sure if there's a theoretical possibility of a non
kRunningstate in electron. I suspect a frame could not spontaneously get into such a state. Do you happen to know?It would still be valuable to have
executeJavaScriptSyncand I would like to add it when I have time. If there's any possibility, however remote, of a nonkRunningstate, it could check for that and throw an error. But practically, always it would just work, synchronously, as before 6.0 changes.