mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
fix(extensions): try harder to avoid Scratch Link init in non-browser environments
Prior to this change, the Scratch Link init would fail in JSDOM. That means it fails in the scratch-gui integration tests, so that's no good...
This commit is contained in:
parent
e289448cd3
commit
56dd49aaed
1 changed files with 11 additions and 2 deletions
|
@ -1444,8 +1444,17 @@ class Runtime extends EventEmitter {
|
||||||
*/
|
*/
|
||||||
_initScratchLink () {
|
_initScratchLink () {
|
||||||
/* global globalThis */
|
/* global globalThis */
|
||||||
// Check if we're actually in a browser
|
// Check that we're actually in a real browser, not Node.js or JSDOM, and we have a valid-looking origin.
|
||||||
if (globalThis.document && document.getElementById) {
|
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')
|
||||||
|
) {
|
||||||
// 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');
|
||||||
if (!scriptElement) {
|
if (!scriptElement) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue