PlasmoHQ / plasmo

🧩 The Browser Extension Framework
https://www.plasmo.com
MIT License
10.14k stars 350 forks source link

[EXP] Messaging from Background.ts to Tabs pages #827

Open Ademking opened 9 months ago

Ademking commented 9 months ago

What is the example you wish to see?

I would like to see more examples of how to use messaging from "Background" to "Tabs" pages.

Is there any context that might help us understand?

I want to send data from "background.ts" to a tab page... for example: (tabs/example.tsx)

background.ts

// context menu
chrome.contextMenus.create({
    id: "test",
    title: "Test",
    contexts: ["image"]
});

chrome.contextMenus.onClicked.addListener(function (info, tab) {
 if (info.menuItemId == "test") {
  // I want to send data from here to my custom Tab page.
  // what shoud I use ? Ports maybe ?
 }
});

tabs/example.tsx

import React from "react"
const Example= () => {
  // What should I use to receive data from background ?
  return (
    <>
      <h1>Example</h1>
    </>
  )
}

export default Example

Can you share an example how to do that ?

Code of Conduct

jiangzongyu commented 7 months ago

mark

Ademking commented 7 months ago

mark

I don't understand

boye commented 3 months ago

I have a similar scenario where I take a screenshot of the active tab (after clicking on the extension icon), and I'd like to send the screenshot image data to a newly opened tab.

Any pointers in how I can achieve this?

Thanks in advance!