Bug 210512

Summary: Storage events are fired for the same tab
Product: WebKit Reporter: Merih Akar <merihakar>
Component: New BugsAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: bdrasin, beidson, cdumez, jimmy, rkit.ru, sihui_liu, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 13   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=211503
Attachments:
Description Flags
testcase none

Description Merih Akar 2020-04-14 13:16:18 PDT
Created attachment 396456 [details]
testcase

As per specification storage events should be fired for the tabs other than the tab that's changing the storage area, however it's also fired on the same tab in Safari.

Note that the issue happens when the testcase file is served via a server, doesn't happen when you open it directly in the browser.
Comment 1 Radar WebKit Bug Importer 2020-04-14 17:47:07 PDT
<rdar://problem/61799443>
Comment 2 Jimmy Thomsen 2020-11-22 13:26:19 PST
I can confirm this with Safari 13.1 (14609.1.20.111.8) on macOS 10.14.6 (18G4032), as well as with Safari on iOS (iPhone) 13.7.

Work around: Only execute OnStorage logic if document is not focused:

if (!document.hasFocus())
{
    // Execute OnStorage logic - tab does not have focus
}

Notice though that hasFocus() will return false in the active tab if Developer Tools is open and has focus.
Comment 3 Jimmy Thomsen 2020-11-22 13:35:32 PST
Work around suggestion only makes sense if OnStorage events are triggered by user interaction, of course. Also, it seems Safari Developer Tools does not steal focus from the document - Chrome Developer Tools does.
Comment 4 Chris Dumez 2020-11-22 16:17:38 PST
This rings a bell and I thought I had fixed this. Are you able to try in Safari Technology Preview?
Comment 5 Chris Dumez 2020-11-22 16:21:34 PST
This looks a lot like
Comment 6 Chris Dumez 2020-11-22 16:22:08 PST
(In reply to Chris Dumez from comment #5)
> This looks a lot like

This looks a lot like https://bugs.webkit.org/show_bug.cgi?id=211503 which got fixed.
Comment 7 Jimmy Thomsen 2020-11-23 08:21:11 PST
(In reply to Chris Dumez from comment #6)
> (In reply to Chris Dumez from comment #5)
> > This looks a lot like
> 
> This looks a lot like https://bugs.webkit.org/show_bug.cgi?id=211503 which
> got fixed.

Chris Dumez: It sure does sound like the same thing. Safari Version 14.0.1 (14610.2.11.51.9) works as expected. I can no longer reproduce the problem with localStorage. I think its safe to close this bug report, although I'm not the one who initially reported the bug - I just confirmed it.

 - Thank you

Jimmy
Comment 8 Chris Dumez 2020-11-23 10:02:26 PST
(In reply to Jimmy Thomsen from comment #7)
> (In reply to Chris Dumez from comment #6)
> > (In reply to Chris Dumez from comment #5)
> > > This looks a lot like
> > 
> > This looks a lot like https://bugs.webkit.org/show_bug.cgi?id=211503 which
> > got fixed.
> 
> Chris Dumez: It sure does sound like the same thing. Safari Version 14.0.1
> (14610.2.11.51.9) works as expected. I can no longer reproduce the problem
> with localStorage. I think its safe to close this bug report, although I'm
> not the one who initially reported the bug - I just confirmed it.
> 
>  - Thank you
> 
> Jimmy

Awesome. Thank you for confirming!

*** This bug has been marked as a duplicate of bug 211503 ***