JerseyDuke
JerseyDuke

Reputation: 79

Chrome Extension component communication

I have an extension that has 3 components that do the following:

  1. Popup script - in the document ready function utilizes native messaging to get an ENV variable (user id). So now I have this value in a variable here, but I need the value in the Background scrpit

  2. Content script adds code to the target page, and when a certain event occurs, gets data from that page and passes it to the background script - this works fine.

  3. Background script - gets the payload from the content scprit, and makes an HTTP call with it - this works fine.

The problem I am having is in one "flavor" of this extension, I need to get that User ID from the popup script to the background script, as it becomes part of the URL I need to invoke. I need to basically construct 'http://URLBase/UserId/suffix' in the background script.

Upvotes: 0

Views: 38

Answers (1)

Keith
Keith

Reputation: 155692

You can use chrome.storage to set and retrieve values available to all your scripts.

For things like user settings you can add an options page rather than your browser action popup.

Upvotes: 1

Related Questions