Skip to content

Commit

Permalink
fix(extensions): try harder to avoid Scratch Link init in non-browser…
Browse files Browse the repository at this point in the history
… 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...
  • Loading branch information
cwillisf committed Aug 17, 2022
1 parent e289448 commit 56dd49a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -1444,8 +1444,17 @@ class Runtime extends EventEmitter {
*/
_initScratchLink () {
/* global globalThis */
// Check if we're actually in a browser
if (globalThis.document && document.getElementById) {
// 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')
) {
// Create a script tag for the Scratch Link browser extension, unless one already exists
const scriptElement = document.getElementById('scratch-link-extension-script');
if (!scriptElement) {
Expand Down

0 comments on commit 56dd49a

Please sign in to comment.