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