Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing HTML into a new tab

In my extension, I'm creating a new tab and would like to write my own html to it - that's generated dynamically.

Can it be done.

I'm calling chrome.tabs.create() to create a new tab - now I just need to write my data as an HTML file to it.

like image 925
s g Avatar asked Dec 22 '22 02:12

s g


1 Answers

Easiest way to do this would be using a data: URL. E.g. something like this:

var htmlCode = "<html><body>Hi!</body></html>";
var url = "data:text/html," + encodeURIComponent(htmlCode);
chrome.tabs.create({url: url});
like image 185
Wladimir Palant Avatar answered Dec 28 '22 05:12

Wladimir Palant