feat: createContentScriptUi helper (#143)

This commit is contained in:
Aaron
2023-09-30 21:57:57 -05:00
committed by GitHub
parent 8d7150653a
commit 4150e42c05
20 changed files with 1161 additions and 68 deletions
+12 -5
View File
@@ -1,3 +1,4 @@
import { ContentScriptDefinition } from '../../core/types';
import { browser } from '../browser';
import { logger } from './logger';
@@ -13,7 +14,10 @@ export class ContentScriptContext extends AbortController {
#isTopFrame = window.self === window.top;
constructor(private readonly contentScriptName: string) {
constructor(
private readonly contentScriptName: string,
public readonly options?: Omit<ContentScriptDefinition, 'main'>,
) {
super();
if (this.#isTopFrame) {
@@ -157,10 +161,13 @@ export class ContentScriptContext extends AbortController {
#stopOldScripts() {
// Use postMessage so it get's sent to all the frames of the page.
window.postMessage({
event: ContentScriptContext.SCRIPT_STARTED_MESSAGE_TYPE,
contentScriptName: this.contentScriptName,
});
window.postMessage(
{
event: ContentScriptContext.SCRIPT_STARTED_MESSAGE_TYPE,
contentScriptName: this.contentScriptName,
},
'*',
);
}
#listenForNewerScripts() {