Bug 187386 - Sometimes "x instanceof Worker" inappropriately returns false
Summary: Sometimes "x instanceof Worker" inappropriately returns false
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 11
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-06 08:08 PDT by jdscheff
Modified: 2018-07-09 20:35 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jdscheff 2018-07-06 08:08:10 PDT
This code should clearly print "true":

    blob = new Blob(["self.onmessage = function() {};"], { type: "text/javascript" });
    worker = new Worker(window.URL.createObjectURL(blob));
    console.log(worker instanceof Worker);

I tested that in Safari 11.1 and it does indeed print "true" when I run it. However for some small subset of Safari 11.x users, it will print "false".

From my client-side error tracker, this bug has occurred in Safari versions 11.0.2, 11.0.3, 11.1.0, 11.1.1. But only to a small fraction of Safari users. Out of a total of ~5000 Safari 11 users in the past month, only 14 of them experienced this error. I even got one of these users to run the above code in the JS console and he confirmed that even that simple code does indeed print "false" for him.
Comment 1 Chris Dumez 2018-07-09 08:58:09 PDT
One common way this happens is when the page's JavaScript messes with the Worker's prototype chain in some way (so Worker or EventTarget). Some script does this to extend the API of a particular type.
Comment 2 Chris Dumez 2018-07-09 09:02:13 PDT
(In reply to Chris Dumez from comment #1)
> One common way this happens is when the page's JavaScript messes with the
> Worker's prototype chain in some way (so Worker or EventTarget). Some script
> does this to extend the API of a particular type.

To be clear, unless we have specific evidence (reproduction case), my instinct would be to say that this is an issue with the page's script, not WebKit. We've investigated many instances of this in the past and every time, it was the page's script modifying the prototype chain in some way.
Comment 3 jdscheff 2018-07-09 20:35:50 PDT
Can you be more specific about how messing with the prototype chain might cause this problem? Mostly just for my curiosity, since in my app I already switched from relying on "instanceof Worker" to be correct.

Also it's curious because this error only appears in my error tracker for Safari, not any other browser. And while I do have a little third party JS running, it's not much. It'd be weird if something like Google Analytics was destructively messing with built in prototypes.