Skip to content

Commit

Permalink
Check whether document is defined (#340)
Browse files Browse the repository at this point in the history
* Check whether document is defined

* CHANGELOG

* Update wasm-node/javascript/src/index-browser.ts

Co-authored-by: Josep M Sobrepere <[email protected]>

---------

Co-authored-by: Josep M Sobrepere <[email protected]>
  • Loading branch information
tomaka and josepot authored Mar 24, 2023
1 parent 52d0fd0 commit 6e8fd53
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Fixed

- Fix runtime transactions not being handled properly when multiple transactions are stacked. ([#335](https://github.com/smol-dot/smoldot/pull/335))
- No longer generate a JavaScript exception due to `document` being undefined when executing inside of a WebWorker. ([#340](https://github.com/smol-dot/smoldot/pull/340))

## 1.0.0 - 2022-03-12

Expand Down
2 changes: 2 additions & 0 deletions wasm-node/javascript/src/index-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export function start(options?: ClientOptions): Client {
return Promise.resolve(inflate(classicDecode(input)))
},
registerShouldPeriodicallyYield: (callback) => {
if (typeof document === 'undefined') // We might be in a web worker.
return [false, () => {}];
const wrappedCallback = () => callback(document.visibilityState === 'visible');
document.addEventListener('visibilitychange', wrappedCallback);
return [document.visibilityState === 'visible', () => { document.removeEventListener('visibilitychange', wrappedCallback) }]
Expand Down

0 comments on commit 6e8fd53

Please sign in to comment.