Skip to content

Instantly share code, notes, and snippets.

@F1LT3R
Created August 10, 2014 07:57
Show Gist options
  • Save F1LT3R/f3f8154090b6d3035d4a to your computer and use it in GitHub Desktop.
Save F1LT3R/f3f8154090b6d3035d4a to your computer and use it in GitHub Desktop.
Using Charles Proxy to load scripts into other webpages
<?xml version='1.0' encoding='UTF-8' ?>
<?charles serialisation-version='2.0' ?>
<rewriteSet-array>
<rewriteSet>
<active>true</active>
<name>Script Loader</name>
<hosts>
<locationPatterns>
<locationMatch>
<location>
<host>*.*</host>
</location>
<enabled>true</enabled>
</locationMatch>
<locationMatch>
<location>
<protocol>.*</protocol>
</location>
<enabled>true</enabled>
</locationMatch>
</locationPatterns>
</hosts>
<rules>
<rewriteRule>
<active>true</active>
<ruleType>7</ruleType>
<matchValue>(&lt;/[Hh][Ee][Aa][Dd](&gt;|\s))</matchValue>
<matchHeaderRegex>false</matchHeaderRegex>
<matchValueRegex>true</matchValueRegex>
<matchRequest>false</matchRequest>
<matchResponse>true</matchResponse>
<newValue>&lt;script data-provider=&quot;script-loader-proxy&quot; type=&quot;text/javascript&quot; src=&quot;//localhost/charles-script-load/loader-script.js&quot;&gt;&lt;/script&gt;</newValue>
<newHeaderRegex>false</newHeaderRegex>
<newValueRegex>false</newValueRegex>
<matchWholeValue>false</matchWholeValue>
<caseSensitive>true</caseSensitive>
<replaceType>1</replaceType>
</rewriteRule>
</rules>
</rewriteSet>
</rewriteSet-array>
// Served from localhost with Charles
(function () {
var scripts = [
'localhost/repos/repo1/src/repo1.js',
'localhost/repos/repo2/src/repo2.js'
];
scripts.forEach(function (url) {
var script = document.createElement('script'),
first = document.getElementsByTagName('script')[0];
script.src = document.location.protocol + '//'+ url;
script.type = 'text/javascript';
script.async = true;
first.parentNode.insertBefore(script, first);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment