At the moment I'm writing a Chrome extension and in the popup.html
I want to use some Polymer elements, but my problem is that none of them are rendered in the popup. My popup.html
looks like this:
<!doctype html>
<html>
<head>
<title>Getting Started Extension's Popup</title>
<script src="js/popup.js"></script>
</head>
<body>
<paper-tabs id="tabBar" class="bottom fit" selected="{{selected}}">
<paper-tab>TAB 1</paper-tab>
<paper-tab>TAB 2</paper-tab>
<paper-tab>TAB 3</paper-tab>
</paper-tabs>
</body>
</html>
This is my popup.js
window.onload = function() {
chrome.tabs.query({active: true, currentWindow: true});
}
And here is my content script:
function loadRes(res) {
return new Promise( function(resolve, reject) {
var link = document.createElement('link');
link.setAttribute('rel', 'import');
link.setAttribute('href', res);
link.onload = function() {
resolve(res);
};
document.head.appendChild(link);
});
}
chrome.runtime.onMessage.addListener( function(request, sender, sendResponse) {
loadRes(chrome.extension.getURL("polymer/webcomponentsjs/webcomponents-lite.js"))
.then(loadRes(chrome.extension.getURL("polymer/paper-tabs/paper-tabs.html")))
});
This code comes from this answer and it should work, so do you have any ideas what is wrong with my code or have I misunderstood something? I thought that the code from popup.js
is executed when the popup is loading and and referenced polymer files are injected into the popup.html
file. Isn't that right? I also added all polymer files to web_accessible_resources
and my content_scripts
runs at document_start
.