Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit b031a18

Browse files
QuovadisqcCaerusKaru
authored andcommitted
fix(preboot): use CustomEvent rather than Event
* Use CustomEvent for PrebootComplete event notification to simplify polyfill usage and improve browser support. * Check CustomEvent type before creating a CustomEvent using the constructor. If the type is not a function, a warning is logged in the console to notify the user that PrebootComplete event could not be dispatched. * Addition of a section in the README.md documenting the need of a CustomEvent polyfill. Closes #64
1 parent c6c9805 commit b031a18

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,7 @@ res.render('index', (req, res) => {
219219
res.send(html);
220220
});
221221
```
222+
223+
#### Browser support
224+
225+
If you wish to support Internet Explorer 9-11, you will need to include a [Polyfill](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill) for `CustomEvent`.

src/lib/api/event.replayer.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,15 @@ export class EventReplayer {
189189
prebootData.apps = [];
190190
this.clientNodeCache = {};
191191

192-
// sent event to documernt that signals preboot complete
193-
const completeEvent = new Event('PrebootComplete');
194-
doc.dispatchEvent(completeEvent);
192+
// send event to document that signals preboot complete
193+
// constructor is not supported by older browsers ( i.e. IE9-11 )
194+
// in these browsers, the type of CustomEvent will be "object"
195+
if (typeof CustomEvent === 'function') {
196+
const completeEvent = new CustomEvent('PrebootComplete');
197+
doc.dispatchEvent(completeEvent);
198+
} else {
199+
console.warn('Could not dispatch PrebootComplete event. You can fix this by including a polyfill for CustomEvent.');
200+
}
195201
}
196202

197203
setFocus(activeNode: NodeContext) {

0 commit comments

Comments
 (0)