Welcome guest, is this your first visit? Create Account now to join.
Results 1 to 6 of 6

This is a discussion on Refreshing background.html? localStorage issue within the Plugins Development section, part of the Chrome Plugins category: Hello, I have developed a chrome extension that takes a variable in from a popup.html, stores it with localStorage. Then ...


  1. #1
    bryanosaurus is offline Junior Member
    Join Date
    May 2010
    Posts
    3

    Default Refreshing background.html? localStorage issue

    Hello,

    I have developed a chrome extension that takes a variable in from a popup.html, stores it with localStorage. Then background.html pulls that variable and sends it to the content_script via onRequest (because content script can't communicate directly with the localStorage data).

    Basically what the content script does is adds the input variable to links on various pages. My issue is that when someone puts a value in, since background.html is already running, the browser must be restarted before it starts using the new value. This is very annoying, especially since it must be done right after installing it when you put an initial value in.

    I have tried various ways of restarting the background.html to no avail.

    Any have any clue how I can go about this? I need it so when someone changes the value in the popup it will begin to reflect the changes as soon as a new page/tab is loaded.
    Any help would be much appreciated !

  2. #2
    gildas is offline Junior Member
    Join Date
    Feb 2010
    Posts
    26

    Default

    Hi bryanosaurus,

    Maybe you should use chrome.extension.getBackgroundPage() from your popup script in order to pass your value to a function from background page. For example, if "processValue" is the function sending the value to content scripts, you can write into your popup script :

    Code:
    chrome.extension.getBackgroundPage().processValue(myVariable)

  3. #3
    bryanosaurus is offline Junior Member
    Join Date
    May 2010
    Posts
    3

    Default

    That is how I'm passing it... something like

    Code:
    function store(){
    chrome.extension.getBackgroundPage().setItem(key1,val1);
    }
    the submit button triggers this, but all it does is go to background.html and store the value. background.html has already pulled the localStorage value when it loaded and will not look again to see if something new has been set.

  4. #4
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default

    Quote Originally Posted by bryanosaurus View Post
    That is how I'm passing it... something like

    Code:
    function store(){
    chrome.extension.getBackgroundPage().setItem(key1,val1);
    }
    the submit button triggers this, but all it does is go to background.html and store the value. background.html has already pulled the localStorage value when it loaded and will not look again to see if something new has been set.
    So make it look again. You don't need to refresh the page. This is what functions and the communication API are for.
    ~ Projects ~
    Specialized: Carapass Auction Watcher, Kongregate Chat
    Libraries: bliplib
    Tools: manifest syntax highlighting & snippits
    ~ Happy to make extensions for pay too ;D ~
    Portfolio: Search and Share

  5. #5
    gildas is offline Junior Member
    Join Date
    Feb 2010
    Posts
    26

    Default

    You also don't need localStorage to send your value from the popup to content scripts. You should only use localstorage to store data.

    I suspect you use a function listening the page load event in order to read the localStorage object... If it be so, just recall your "onload" function.
    Last edited by gildas; 05-18-2010 at 07:23 PM.

  6. #6
    bryanosaurus is offline Junior Member
    Join Date
    May 2010
    Posts
    3

    Thumbs up

    Thanks guys, I got it working as intended now!

Similar Threads

  1. localStorage wrapper
    By Skymt in forum Plugins Development
    Replies: 2
    Last Post: 02-18-2010, 09:50 PM
  2. localStorage on uninstall ?
    By Inco in forum Plugins Development
    Replies: 2
    Last Post: 10-31-2009, 06:23 AM
  3. Problem when refreshing a page
    By Philw in forum Chrome Troubleshooting
    Replies: 8
    Last Post: 05-21-2009, 02:09 AM
  4. Problem when refreshing a page
    By Philw in forum Chrome Troubleshooting
    Replies: 0
    Last Post: 05-13-2009, 11:13 PM
  5. Problem when refreshing a page
    By Philw in forum Chrome Troubleshooting
    Replies: 0
    Last Post: 05-12-2009, 12:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •