Bug 204912

Summary: Prevent synchronous XHR in beforeunload / unload event handlers
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebCore Misc.Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, commit-queue, darin, dbates, ews-watchlist, ggaren, japhet, rniwa, sam, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
URL: https://www.chromestatus.com/feature/4664843055398912
Bug Depends on: 206315    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch none

Description Chris Dumez 2019-12-05 14:02:01 PST
Prevent synchronous XHR in beforeunload / unload event handlers. They are terrible for performance and the Beacon API (or Fetch keepalive) are more efficient & supported alternatives.
Comment 1 Radar WebKit Bug Importer 2019-12-05 14:02:42 PST
<rdar://problem/57676394>
Comment 2 Chris Dumez 2019-12-05 14:39:06 PST
Created attachment 384955 [details]
Patch
Comment 3 Chris Dumez 2019-12-05 15:41:59 PST
Created attachment 384970 [details]
Patch
Comment 4 Ryosuke Niwa 2019-12-05 17:01:20 PST
Comment on attachment 384970 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=384970&action=review

> Source/WebCore/loader/DocumentThreadableLoader.cpp:134
> +    if (!m_async && (!document.page() || !document.page()->areSynchronousLoadsAllowed())) {

Seems like we want to put this behind some kind of a setting / feature flag?
Comment 5 Ryosuke Niwa 2019-12-05 17:01:33 PST
Do other browsers forbid this as well?
Comment 6 Sam Weinig 2019-12-06 06:42:04 PST
It seems like if we want to make this kind of change, we should first understand the compatibility story and if it's ok, make a change to HTML5 to standardize this.

Otherwise, it's not clear why this is an ok change to make.
Comment 7 Chris Dumez 2019-12-06 08:12:59 PST
(In reply to Ryosuke Niwa from comment #5)
> Do other browsers forbid this as well?

No, other browsers do not do this at this time.
Comment 8 Chris Dumez 2019-12-06 08:15:05 PST
(In reply to Ryosuke Niwa from comment #5)
> Do other browsers forbid this as well?

Please see https://www.chromestatus.com/feature/4664843055398912
Comment 9 Chris Dumez 2019-12-06 08:16:09 PST
(In reply to Chris Dumez from comment #7)
> (In reply to Ryosuke Niwa from comment #5)
> > Do other browsers forbid this as well?
> 
> No, other browsers do not do this at this time.

Sorry, I meant the opposite. Not sure what happened there:

Chrome has been testing this for a while:
https://www.chromestatus.com/feature/4664843055398912
Comment 10 Chris Dumez 2019-12-06 08:25:28 PST
(In reply to Ryosuke Niwa from comment #4)
> Comment on attachment 384970 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=384970&action=review
> 
> > Source/WebCore/loader/DocumentThreadableLoader.cpp:134
> > +    if (!m_async && (!document.page() || !document.page()->areSynchronousLoadsAllowed())) {
> 
> Seems like we want to put this behind some kind of a setting / feature flag?

Good idea, will do.
Comment 11 Chris Dumez 2019-12-06 08:37:24 PST
Created attachment 385015 [details]
Patch
Comment 12 Chris Dumez 2019-12-06 10:25:38 PST
Created attachment 385025 [details]
Patch
Comment 13 WebKit Commit Bot 2019-12-06 13:05:19 PST
Comment on attachment 385025 [details]
Patch

Clearing flags on attachment: 385025

Committed r253213: <https://trac.webkit.org/changeset/253213>
Comment 14 WebKit Commit Bot 2019-12-06 13:05:21 PST
All reviewed patches have been landed.  Closing bug.