Commit 1fbe9bdf authored by Eduardo Sanz García's avatar Eduardo Sanz García Committed by Eduardo

Fix a check for browsers that doesn't support ServiceWorker

The current version of `isSourceWindow` raised an error for (1) older
browser that doesn't support ServiceWorker and (2) web pages served from
non-secured http connections.

I tested this alternative fix but it didn't work for me in the latest
version of Chrome:
https://stackoverflow.com/questions/6229301/a-clean-way-of-checking-whether-an-object-is-an-instance-of-window-constructor/6229603#6229603
parent de6e521c
...@@ -60,12 +60,12 @@ export function isMessageEqual(data, message) { ...@@ -60,12 +60,12 @@ export function isMessageEqual(data, message) {
*/ */
export function isSourceWindow(source) { export function isSourceWindow(source) {
if ( if (
// `source` can be of type Window | MessagePort | ServiceWorker. // `source` can be of type Window, MessagePort, ServiceWorker, or null.
// The simple check `source instanceof Window`` doesn't work here. // `source instanceof Window` doesn't work in Chrome if `source` is a
// Alternatively, `source` could be casted `/** @type{Window} */ (source)` // cross-origin window.
source === null || source === null ||
source instanceof MessagePort || source instanceof MessagePort ||
source instanceof ServiceWorker (window.ServiceWorker && source instanceof ServiceWorker)
) { ) {
return false; return false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment