Reputation: 105
I'm creating a window in a Chrome Extension using chrome.windows.create
. It's of type panel
, so it's not a regular browser window or tab, but a free-standing window floating above all others. Having created it, I now need to insert some HTML and JavaScript into it. So how is that done? There's a Window Object returned from create, but it has no useful hooks in it - just a few attributes. Nothing in the documentation suggests how to do that, and I don't see and DOM tree fo it anywhere.
Any ideas?
Thanks a lot!
Upvotes: 3
Views: 1229
Reputation: 86
Try this I have not tested it myself but might give you some idea....
(function(){ chrome.windows.create({ type: 'panel', url: "https://www.google.co.in/" }, function (newWindow) { console.log(newWindow); chrome.tabs.executeScript(newWindow.tabs[0].id, { code: 'document.write("hello world");' }); }); })()
and also as mention in this Chromium Projects link about panels you can manipulate pane same as other windows types.
Upvotes: 0
Reputation: 105
I discovered the answer, after more reading and experimenting: When creating the window, you need to create a tab and attach it to the window. So, your create createData
object will contain a URL attribute which simply points to the HTML page (with CSS, JS, whatever you want) sitting in (by default) the root folder of the extension (so if you want your HTML files kept elsewhere, simply prefix the filename with a path). Now, when the window is created, it's created with one tab (which, from the UI perspective doesn't even show as a tab - which is nice) and that tab contains the content you want.
Upvotes: 3