Bug 237912

Summary: REGRESSION(r288307): instanceof value wrong in MutationObserver callback for Safari extensions
Product: WebKit Reporter: Jeff Johnson <opendarwin>
Component: BindingsAssignee: Alexey Shvayka <ashvayka>
Status: RESOLVED FIXED    
Severity: Blocker CC: ashvayka, cdumez, ews-watchlist, jond, saam, timothy, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
See Also: https://bugs.webkit.org/show_bug.cgi?id=232387
Attachments:
Description Flags
Sample Xcode project
none
Patch none

Description Jeff Johnson 2022-03-15 11:42:12 PDT
Created attachment 454735 [details]
Sample Xcode project

This bug occurs with Safari Technology Release 141 (Safari 15.4, WebKit 16614.1.3.7) on macOS 11.6.5. The bug does not occur with Safari 15.3 or Safari 15.4 (released yesterday), only with Safari Technology Preview.

The bug is that JavaScript instanceof is returning false when it should return true in the callback of MutationObserver for Safari extensions, both Safari web extensions and Safari app extensions. This bug does not seem to affect scripts in the web pages, only extension scripts.

Attached is a sample Safari web extension Xcode project that demonstrates the bug. Just enable the extension, run it on any web site, such as cnn.com, and look at the console log. For HTML <div> elements, it should log true true for instanceof HTMLElement and instanceof HTMLDivElement, but it logs false false in Safari Technology Preview 141.

This bug is a massive problem for me, a showstopper for several of my Safari extensions in the App Store. It totally breaks essential functionality in my extensions.
Comment 1 Jeff Johnson 2022-03-15 11:44:40 PDT
Note that instanceof works correctly in the setTimeout function. It's only wrong in the MutationObserver callback.
Comment 2 Jeff Johnson 2022-03-15 12:10:15 PDT
I can also reproduce with Safari Technology Preview 141 on macOS 12.3 on Apple Silicon. Safari 15.4 (17613.1.17.1.6) is not affected.
Comment 3 Jon Davis 2022-03-15 13:39:52 PDT
Thank you for the bug report. I’ve cc’d some engineers to investigate.
Comment 4 Radar WebKit Bug Importer 2022-03-15 15:12:14 PDT
<rdar://problem/90333276>
Comment 5 Alexey Shvayka 2022-03-22 09:01:29 PDT
Created attachment 455377 [details]
Patch
Comment 6 EWS 2022-03-22 13:25:31 PDT
Committed r291694 (248736@main): <https://commits.webkit.org/248736@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 455377 [details].