mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-25 07:22:33 -05:00
Merge pull request #4052 from cwillisf/fix-globalThis
fix: remove use of 'globalThis' keyword
This commit is contained in:
commit
ba01edcd7c
1 changed files with 13 additions and 11 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue