Skip to content

fix: guard NotifyUserActivation on live main frame. - #52215

Merged
jkleinsc merged 1 commit into
electron:mainfrom
cucbin:chore/add_live_guard_on_notify_user_activation
Aug 7, 2026
Merged

jkleinsc merged 1 commit into
electron:mainfrom
cucbin:chore/add_live_guard_on_notify_user_activation

Conversation

@cucbin

@cucbin cucbin commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Description of Change

I encountered several sporadic crash stack traces.
callstack:

  *** Stack trace for last set context - .thread/.cxr resets it
 # Child-SP          RetAddr               Call Site
00 (Inline Function) --------`--------     RingCentral!blink::AssociatedInterfaceProvider::GetInterface+0x1b [] 
01 (Inline Function) --------`--------     RingCentral!content::RenderFrameHostImpl::GetAssociatedLocalFrame+0x30 [] 
02 0000003f`fd9fd180 00007ff6`448aca59     RingCentral!content::RenderFrameHostImpl::NotifyUserActivation+0x4d [] 
03 (Inline Function) --------`--------     RingCentral!electron::api::WebContents::NotifyUserActivation+0x3b [] 
04 0000003f`fd9fd1e0 00007ff6`448cc610     RingCentral!electron::api::WebContents::LoadURL+0x609 [] 
05 (Inline Function) --------`--------     RingCentral!base::RepeatingCallback<void (electron::api::WebContents *, const GURL &, const gin_helper::Dictionary &)>::Run+0x37 [] 
06 0000003f`fd9fd860 00007ff6`448cc388     RingCentral!gin_helper::Invoker<std::__Cr::integer_sequence<unsigned long long,0,1,2>,electron::api::WebContents *,const GURL &,const gin_helper::Dictionary &>::DispatchToCallback+0xa0 [] 
07 0000003f`fd9fd8d0 00007ff6`448cc237     RingCentral!gin_helper::Dispatcher<void (electron::api::WebContents *, const GURL &, const gin_helper::Dictionary &)>::DispatchToCallbackImpl+0x128 [] 
08 0000003f`fd9fd9e0 00007ff6`4dc559de     RingCentral!gin_helper::Dispatcher<void (electron::api::WebContents *, const GURL &, const gin_helper::Dictionary &)>::DispatchToCallback+0x47 [] 
09 0000003f`fd9fda30 00007ff6`4dc53c1e     RingCentral!Builtins_CallApiCallbackGeneric+0x9e
0a 0000003f`fd9fda88 00007ff6`4dc53c1e     RingCentral!Builtins_InterpreterEntryTrampoline+0x11e
0b 0000003f`fd9fdb40 00007ff6`4dc53c1e     RingCentral!Builtins_InterpreterEntryTrampoline+0x11e
0c 0000003f`fd9fdbc0 00007ff6`4dc962af     RingCentral!Builtins_InterpreterEntryTrampoline+0x11e
0d 0000003f`fd9fdcb8 00007ff6`4dd775ea     RingCentral!Builtins_AsyncFunctionAwaitResolveClosure+0x2f
0e 0000003f`fd9fdcf0 00007ff6`4dc84581     RingCentral!Builtins_PromiseFulfillReactionJob+0x2a
0f 0000003f`fd9fdd28 00007ff6`4dc516b3     RingCentral!Builtins_RunMicrotasks+0x2c1
10 0000003f`fd9fdd98 00007ff6`460ed291     RingCentral!Builtins_JSRunMicrotasksEntry+0xf3
11 0000003f`fd9fdec0 00007ff6`460edea5     RingCentral!v8::internal::`anonymous namespace'::Invoke+0x8b1 [] 
12 0000003f`fd9fe090 00007ff6`460ee0ab     RingCentral!v8::internal::`anonymous namespace'::InvokeWithTryCatch+0x65 [] 
13 0000003f`fd9fe120 00007ff6`46121228     RingCentral!v8::internal::Execution::TryRunMicrotasks+0x6b [] 
14 0000003f`fd9fe1a0 00007ff6`461219c3     RingCentral!v8::internal::MicrotaskQueue::RunMicrotasks+0xc8 [] 
15 (Inline Function) --------`--------     RingCentral!v8::internal::MicrotaskQueue::PerformCheckpointInternal+0x39 [] 
16 0000003f`fd9fe260 00007ff6`4a8e39c9     RingCentral!v8::internal::MicrotaskQueue::PerformCheckpoint+0x63 [] 
17 0000003f`fd9fe2c0 00007ff6`4dc559de     RingCentral!node::task_queue::RunMicrotasks+0xc9 [] 
18 0000003f`fd9fe320 00007ff6`add650a4     RingCentral!Builtins_CallApiCallbackGeneric+0x9e

And that likely cause is that IsRenderFrameLive() was not checked before sending the IPC.

RenderFrameHost::GetPrimaryMainFrame() can return an RFH object, but it does not guarantee that the RenderFrame in the renderer is already live.

The low risk change: avoid sending user activation notifications unless the primary main frame is live.

Checklist

Release Notes

Notes: Fixed a potential crash when notifying user activation before the primary main frame was live.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Jul 1, 2026
@deepak1556

Copy link
Copy Markdown
Member

Change is good, can you share some of those crash stack trace, it will give us better context of the issue. Thanks!

@deepak1556 deepak1556 added semver/patch backwards-compatible bug fixes target/42-x-y PR should also be added to the "42-x-y" branch. target/43-x-y PR should also be added to the "43-x-y" branch. labels Jul 1, 2026
@github-actions github-actions Bot added the target/44-x-y PR should also be added to the "44-x-y" branch. label Jul 1, 2026
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Jul 2, 2026

@deepak1556 deepak1556 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.

LGTM, minor nit

});

it('can correctly convert accelerators to key codes', async () => {
await w.webContents.executeJavaScript('document.getElementById("input").focus()');

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.

unrelated test change ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I ran unit test before submitting the code and found that this case failed.

not ok 114 webContents module sendInputEvent(event) can correctly convert accelerators to key codes
  expected '' to equal '+ + +'
  AssertionError: expected '' to equal '+ + +'

I fixed it while I was at it.

@deepak1556 deepak1556 Jul 3, 2026 •

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.

For other reviewers, notifyUserActivation was meant as a signal to get beforeunload working more context at #23699, seems like this test accidentally got input focused because of the fake user interaction before. I think the current change is good.

@mlaurencin

Copy link
Copy Markdown
Member

@cucbin can you try rebasing on the latest main? That should hopefully resolve the build failures now

@cucbin
cucbin force-pushed the chore/add_live_guard_on_notify_user_activation branch from 278122e to e1744e4 Compare August 6, 2026 05:51
@jkleinsc
jkleinsc merged commit 1f4a30d into electron:main Aug 7, 2026
118 of 121 checks passed
@release-clerk

release-clerk Bot commented Aug 7, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed a potential crash when notifying user activation before the primary main frame was live.

@trop

trop Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "43-x-y", please check out #52697

@trop

trop Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "44-x-y", please check out #52698

@trop trop Bot removed the target/43-x-y PR should also be added to the "43-x-y" branch. label Aug 7, 2026
@trop

trop Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "42-x-y", please check out #52699

@trop trop Bot added in-flight/44-x-y in-flight/42-x-y and removed target/44-x-y PR should also be added to the "44-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. in-flight/42-x-y labels Aug 7, 2026
@trop trop Bot added merged/42-x-y PR was merged to the "42-x-y" branch. merged/44-x-y PR was merged to the "44-x-y" branch. merged/43-x-y PR was merged to the "43-x-y" branch. and removed in-flight/44-x-y in-flight/43-x-y labels Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

45-x-y merged/42-x-y PR was merged to the "42-x-y" branch. merged/43-x-y PR was merged to the "43-x-y" branch. merged/44-x-y PR was merged to the "44-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants