Run javascript in an "isolated world" (chrome)
<p>The chrome extension I developed injects Polymer and other web components into the host page via HTML imports as opposed to the typical method which is to use content scripts - which automatically run in an <a href="https://developer.chrome.com/extensions/content_scripts" rel="nofollow noreferrer">isolated world</a>.</p>

<p>The reason behind this has to do with two things:</p>

<ol>
<li>Chrome extensions cannot register custom elements from <a href="https://bugs.chromium.org/p/chromium/issues/detail?id=390807" rel="nofollow noreferrer">content scripts</a></li>
<li>The chrome extension manifest does not support HTML imports running in an isolated environment, only javascript</li>
</ol>

<p>Due to these limitations, I had to resort to loading my components into the host page's <code>&lt;head&gt;</code> as <a href="https://stackoverflow.com/questions/30022350/registering-a-custom-element-from-a-chrome-extension">described here</a>.</p>

<p>The obvious problem I am facing is having my javascript come in conflict with the host page's javascript [on certain sites] since the method I am using to inject my dependencies does not run in an "isolated world".</p>

<p>So far I have resolved most of these issues by having a gulp task rename Polymer &amp; my components to avoid conflicts but, unfortunately it is not perfect and a more robust approach is needed.</p>

<p>Finally to my question: Is it possible to create an "isolated world" for my javascript? Perhaps another document object? If not, are there any strategies I can employ to ensure my code run in isolation?</p>

<p><strong>Update:</strong></p>

<p>A few of you suggested using IIFE which is what I have been using thus far. I am looking for an answer along the lines of an isolated world, similar to how google chrome runs extensions under. This is mainly because Polymer must be attached to the global window object. </p>