0

So I recently implemented a chrome extension to grab images in an active tab and extract them to a popup for downloading. I would like to give users the option to view the popup window (including the extracted images) in a new Chrome tab.

However, since the popup is created dynamically by appending children to the body of my popup.html, I'm not sure how to pass the HTML for my popup to the new chrome tab.

I tried using chrome.tabs.create({url: chrome.extension.getURL('popup.html#window')});

as found at Open chrome extension in a new tab

but this doesn't seem to be working. Any suggestions?

Community
  • 1
  • 1
  • This is *really* hacky and I definitely do not suggest it as a first course of action, but if you can't find a solution, two possibilities include using `sessionStorage` to save your HTML as text and read it on the popup window, or doing the same with a query variable (i.e. `chrome.tabs.create({url: chrome.extension.getURL('popup.html#window?contents=

    your content here

    ')});`).
    – Hydrothermal Jan 23 '15 at 05:35
  • What you suggest (transplanting generated HTML) is not practical at all. I suggest you rethink this; save the data you used to generate the children, and pass it to a new page to re-create the UI you need. – Xan Jan 23 '15 at 11:10

1 Answers1

0

I'm also developing a Chrome Extension that involves saving down a user's browser data.

Since each time an Extension opens a page (such as popup.html in your case) it opens a new instance of it, the pages and their relevant activity will be independent from each other.

In short you will have to implement some storage. The silver lining is it's pretty simple. Everything you need from manifest to example functions is here: https://developer.chrome.com/extensions/storage

In your case what I'd imagine you'd want to do is this: When you pass image urls to your popup page you also save them as items in an array in storage. Then your pop up page can load in the array as the list to set downloading (or preview depending on use case). Then either users can delete items from the array, or they are deleted programatically once downloaded.

I can't really be more specific without knowing exactly what your extension is trying to do or how it works, but hopefully that's enough to set you in the right direction.

Niazipan
  • 995
  • 2
  • 8
  • 16