Skip to content

Commit

Permalink
fix(firefox): firing with custom Object become restrictions data
Browse files Browse the repository at this point in the history
communicate with plain json string instead of custom Object
more: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent

re #25
  • Loading branch information
guanbinrui committed Aug 3, 2019
1 parent 8e966c5 commit c3cb73e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/extension/injected-script/addEventListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ export interface CustomEvents {
}
;(Object.keys(hacks) as (keyof DocumentEventMap)[]).concat(['keyup', 'input']).forEach(hijack)
const invokeCustomEvent: EventListenerOrEventListenerObject = e => {
const ev = e as CustomEvent<[keyof CustomEvents, CustomEvents[keyof CustomEvents]]>
const [eventName, param] = ev.detail
const ev = e as CustomEvent<string>
const [eventName, param]: [keyof CustomEvents, CustomEvents[keyof CustomEvents]] = JSON.parse(ev.detail)

for (const f of store[eventName] || []) {
try {
const hack = hacks[eventName]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function getUrl(path: string, fallback: string = '') {
* @param x parameters
*/
export function dispatchCustomEvents<T extends keyof CustomEvents>(event: T, ...x: CustomEvents[T]) {
document.dispatchEvent(new CustomEvent(CustomEventId, { detail: [event, x] }))
document.dispatchEvent(new CustomEvent(CustomEventId, { detail: JSON.stringify([event, x]) }))
}
Object.assign(window, { dispatchCustomEvents })
/**
Expand Down

0 comments on commit c3cb73e

Please sign in to comment.