Ask Your Question
0

How can an object be transferred from an injected page script to a content script?

asked 2022-03-22 11:00:00 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-12-17 15:00:00 +0000

djk gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-03-22 11:00:00 +0000

Seen: 11 times

Last updated: Dec 17 '22