1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-18 15:47:57 +01:00

wip: ping command from web

This commit is contained in:
Andreas Coroiu 2024-12-17 15:19:12 +01:00
parent 45a1ff7f04
commit 483a5f27e7
No known key found for this signature in database
GPG Key ID: E70B5FFC81DFEC1A
5 changed files with 24 additions and 3 deletions

View File

@ -39,7 +39,7 @@
{ {
"all_frames": false, "all_frames": false,
"js": ["content/ipc-content-script.js"], "js": ["content/ipc-content-script.js"],
"matches": ["https://vault.bitwarden.com/*"], "matches": ["https://vault.bitwarden.com/*", "https://localhost:4200/*"],
"run_at": "document_start" "run_at": "document_start"
} }
], ],

View File

@ -40,7 +40,7 @@
{ {
"all_frames": false, "all_frames": false,
"js": ["content/ipc-content-script.js"], "js": ["content/ipc-content-script.js"],
"matches": ["https://vault.bitwarden.com/*"], "matches": ["https://vault.bitwarden.com/*", "https://localhost:4200/*"],
"run_at": "document_start" "run_at": "document_start"
} }
], ],

View File

@ -1,6 +1,12 @@
import { Observable } from "rxjs"; import { Observable } from "rxjs";
import { IpcLink, IpcService, isIpcMessage } from "@bitwarden/common/platform/ipc"; import {
IpcLink,
IpcService,
isIpcMessage,
PingMessagePayload,
PongMessagePayload,
} from "@bitwarden/common/platform/ipc";
export class WebIpcService extends IpcService { export class WebIpcService extends IpcService {
private static LinkToExtensionBackground = new IpcLink( private static LinkToExtensionBackground = new IpcLink(
@ -25,5 +31,17 @@ export class WebIpcService extends IpcService {
await super.init(); await super.init();
this.manager.register_link(WebIpcService.LinkToExtensionBackground); this.manager.register_link(WebIpcService.LinkToExtensionBackground);
void this.ping();
}
async ping() {
await this.manager.send("BrowserBackground", PingMessagePayload);
const message = await this.manager.receive("BrowserBackground");
if (message[0] === PongMessagePayload[0]) {
// eslint-disable-next-line no-console
console.log("Connected to extension background");
}
} }
} }

View File

@ -1,3 +1,4 @@
export * from "./ipc-link"; export * from "./ipc-link";
export * from "./ipc-message"; export * from "./ipc-message";
export * from "./ipc.service"; export * from "./ipc.service";
export * from "./ping.message";

View File

@ -0,0 +1,2 @@
export const PingMessagePayload = new Uint8Array([9001]);
export const PongMessagePayload = new Uint8Array([9002]);