Merge pull request #4052 from cwillisf/fix-globalThis

fix: remove use of 'globalThis' keyword
This commit is contained in:
Christopher Willis-Ford 2023-08-07 14:15:41 -07:00 committed by GitHub
commit ba01edcd7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1443,17 +1443,19 @@ class Runtime extends EventEmitter {
* One-time initialization for Scratch Link support.
*/
_initScratchLink () {
/* global globalThis */
// Check that we're actually in a real browser, not Node.js or JSDOM, and we have a valid-looking origin.
if (globalThis.document &&
globalThis.document.getElementById &&
globalThis.origin &&
globalThis.origin !== 'null' &&
globalThis.navigator &&
globalThis.navigator.userAgent &&
globalThis.navigator.userAgent.includes &&
!globalThis.navigator.userAgent.includes('Node.js') &&
!globalThis.navigator.userAgent.includes('jsdom')
// note that `if (self?....)` will throw if `self` is undefined, so check for that first!
if (typeof self !== 'undefined' &&
typeof document !== 'undefined' &&
document.getElementById &&
self.origin &&
self.origin !== 'null' && // note this is a string comparison, not a null check
self.navigator &&
self.navigator.userAgent &&
!(
self.navigator.userAgent.includes('Node.js') ||
self.navigator.userAgent.includes('jsdom')
)
) {
// Create a script tag for the Scratch Link browser extension, unless one already exists
const scriptElement = document.getElementById('scratch-link-extension-script');
@ -1464,7 +1466,7 @@ class Runtime extends EventEmitter {
// Tell the browser extension to inject its script.
// If the extension isn't present or isn't active, this will do nothing.
globalThis.postMessage('inject-scratch-link-script', globalThis.origin);
self.postMessage('inject-scratch-link-script', self.origin);
}
}
}