Skip to content

Commit

Permalink
Check for self in scope instead of window.
Browse files Browse the repository at this point in the history
  • Loading branch information
Demonstrandum committed Jul 24, 2023
1 parent fb077a2 commit e9a5f1a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/BasicCanvas.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
// Identify Node.js
const in_node = !!(typeof process !== 'undefined'
&& typeof process.versions.node !== 'undefined');
const is_worker = !!(typeof window === 'undefined'
&& typeof self !== 'undefined');
if (in_node) {
console.log('Running under Node.js!');
const window = global;
global.window = window;
global.HTMLElement = function HTMLElement() {
this.width = this.height = 300;
};
} else if (is_worker) {
console.log('Running in web context without `window`.');
const window = self;
self.window = self;
self.HTMLElement = function HTMLElement() {
this.width = this.height = 300;
}
}

// Basic semi-related tools.
Expand Down

1 comment on commit e9a5f1a

@vercel
Copy link

@vercel vercel bot commented on e9a5f1a Jul 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

BasicCanvas – ./

basiccanvas-git-master-demonstrandum.vercel.app
basiccanvas-demonstrandum.vercel.app
canvas.knutsen.co

Please sign in to comment.