-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(browser-extension): support pick client for browser ext main tra…
…nport
- Loading branch information
Showing
5 changed files
with
135 additions
and
28 deletions.
There are no files selected for viewing
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
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,16 +1,40 @@ | ||
import React from "react"; | ||
import { | ||
createRoot | ||
} from "react-dom/client"; | ||
import React from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
|
||
import App from "./components/app"; | ||
import browser from 'webextension-polyfill'; | ||
import { createTransport } from 'data-transport'; | ||
|
||
import "./index.scss"; | ||
import App from './components/app'; | ||
|
||
const container = document.createElement("popup"); | ||
import './index.scss'; | ||
|
||
const container = document.createElement('popup'); | ||
document.body.appendChild(container); | ||
|
||
const root = createRoot(container); | ||
root.render(<App />); | ||
|
||
console.log("Content Script 👋"); | ||
console.log('Content Script 👋'); | ||
|
||
const transport = createTransport('BrowserExtensionsClient', { | ||
browser: browser as any, | ||
}); | ||
|
||
transport.onConnect(() => { | ||
console.log('connect'); | ||
}); | ||
|
||
(global as any).transport = transport; | ||
|
||
console.log('transport:', transport); | ||
|
||
// @ts-ignore | ||
transport.listen('a', () => { | ||
console.log('a event in content script'); | ||
}); | ||
|
||
setTimeout(async () => { | ||
console.log('send contentToBg'); | ||
const a = await transport.emit('contentToBg', 1, 2); | ||
console.log('a:', a); | ||
}, 1000 * 10); |
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
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
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