Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are a few ways to transfer an object from an injected page script to a content script:

  1. Use message passing: In this approach, you can use the chrome.runtime.sendMessage() method to send a message from the injected page script to the content script. The message can contain the object data, and the content script can receive the message using the chrome.runtime.onMessage() method.

  2. Use the DOM: If the injected page script and the content script share the same DOM, you can use the DOM to transfer the object data. For example, you can add the object data as an attribute to a DOM element, and then retrieve the data in the content script using the getAttribute() method.

  3. Use localStorage or chrome.storage: You can store the object data in the browser's localStorage or chrome.storage, and then retrieve the data in the content script. This approach requires both the injected page script and the content script to have access to the same storage location.