-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PM-3783] feat: patch
chrome.runtime.onMessage
event listeners
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
apps/browser/src/platform/polyfills/zone-patch-chrome-runtime.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
Check warning on line 1 in apps/browser/src/platform/polyfills/zone-patch-chrome-runtime.ts CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (master)❌ New issue: Complex Method
|
||
* Monkey patch `chrome.runtime.onMessage` event listeners to run in the Angular zone. | ||
*/ | ||
Zone.__load_patch("ChromeRuntimeOnMessage", (global: any, Zone: ZoneType, api: _ZonePrivate) => { | ||
const onMessage = global.chrome.runtime.onMessage; | ||
if (typeof global?.chrome?.runtime?.onMessage === "undefined") { | ||
return; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
api.patchMethod(onMessage, "addListener", (delegate: Function) => (self: any, args: any[]) => { | ||
const callback = args.length > 0 ? args[0] : null; | ||
if (typeof callback === "function") { | ||
const wrapperedCallback = Zone.current.wrap(callback, "ChromeRuntimeOnMessage"); | ||
callback[api.symbol("chromeRuntimeOnMessageCallback")] = wrapperedCallback; | ||
return delegate.call(self, wrapperedCallback); | ||
} else { | ||
return delegate.apply(self, args); | ||
} | ||
}); | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
api.patchMethod(onMessage, "removeListener", (delegate: Function) => (self: any, args: any[]) => { | ||
const callback = args.length > 0 ? args[0] : null; | ||
if (typeof callback === "function") { | ||
const wrapperedCallback = callback[api.symbol("chromeRuntimeOnMessageCallback")]; | ||
if (wrapperedCallback) { | ||
return delegate.call(self, wrapperedCallback); | ||
} else { | ||
return delegate.apply(self, args); | ||
} | ||
} else { | ||
return delegate.apply(self, args); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import "core-js/stable"; | ||
import "date-input-polyfill"; | ||
import "zone.js"; | ||
|
||
import "../platform/polyfills/zone-patch-chrome-runtime"; |