mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-17 15:37:57 +01:00
wip: ping command from web
This commit is contained in:
parent
45a1ff7f04
commit
483a5f27e7
@ -39,7 +39,7 @@
|
||||
{
|
||||
"all_frames": false,
|
||||
"js": ["content/ipc-content-script.js"],
|
||||
"matches": ["https://vault.bitwarden.com/*"],
|
||||
"matches": ["https://vault.bitwarden.com/*", "https://localhost:4200/*"],
|
||||
"run_at": "document_start"
|
||||
}
|
||||
],
|
||||
|
@ -40,7 +40,7 @@
|
||||
{
|
||||
"all_frames": false,
|
||||
"js": ["content/ipc-content-script.js"],
|
||||
"matches": ["https://vault.bitwarden.com/*"],
|
||||
"matches": ["https://vault.bitwarden.com/*", "https://localhost:4200/*"],
|
||||
"run_at": "document_start"
|
||||
}
|
||||
],
|
||||
|
@ -1,6 +1,12 @@
|
||||
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 {
|
||||
private static LinkToExtensionBackground = new IpcLink(
|
||||
@ -25,5 +31,17 @@ export class WebIpcService extends IpcService {
|
||||
await super.init();
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
export * from "./ipc-link";
|
||||
export * from "./ipc-message";
|
||||
export * from "./ipc.service";
|
||||
export * from "./ping.message";
|
||||
|
2
libs/common/src/platform/ipc/ping.message.ts
Normal file
2
libs/common/src/platform/ipc/ping.message.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export const PingMessagePayload = new Uint8Array([9001]);
|
||||
export const PongMessagePayload = new Uint8Array([9002]);
|
Loading…
Reference in New Issue
Block a user