I'm trying to use Polymer in a chrome extension. The overall goal is to leverage styling encapsulation so my content scripts run isolated from the CSS of the page being visited.
Beginning with a custom element in my-element.html
I'm using Vulcanize like so:
vulcanize -o build.html my-element.html
If I try something like this in my content script:
// content_script.js
$.get(chrome.extension.getURL('build.html'), function(data) {
var html = document.createElement('div');
html.innerHTML = data;
document.body.appendChild(html);
var custom = document.createElement('my-element');
document.body.appendChild(custom);
});
build.html loads ok, but my-element is not working. It just creates an empty tag with none of my shadow DOM contents.
I see a couple potential problems with what I'm doing:
- I'm loading the polymer stuff into a div. Does it need to be loaded directly into body? If so, how is this done?
- I'm assuming loading build.html with ajax will work in the first place. Is this an incorrect assumption?