Skip to content

Commit

Permalink
fix: Remove all variables and most functions from global scope (#61)
Browse files Browse the repository at this point in the history
To avoid name collisions on sites due to common names, e.g. Uncaught
SyntaxError: Identifier 'options' has already been declared

This also updates to use version 1.0.2 of trace-anything.

Changes have been formatted with Chromium's JavaScript formatter.

Fixes #44
  • Loading branch information
jrummell-chromium authored Jan 10, 2023
1 parent b461595 commit 3b8ed85
Show file tree
Hide file tree
Showing 4 changed files with 411 additions and 401 deletions.
48 changes: 25 additions & 23 deletions content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,30 @@
* @fileoverview Does necessary set up for the EME Logger extension.
*/

// Load required scripts into the current web page.
const urls = ['/trace-anything.js', '/eme-trace-config.js'];
for (const url of urls) {
const absoluteUrl = chrome.runtime.getURL(url);
(() => {
// Load required scripts into the current web page.
const urls = [ '/trace-anything.js', '/eme-trace-config.js' ];
for (const url of urls) {
const absoluteUrl = chrome.runtime.getURL(url);

// Insert a script tag and force it to load synchronously.
const script = document.createElement('script');
script.type = 'text/javascript';
script.defer = false;
script.async = false;
script.src = absoluteUrl;
(document.head || document.documentElement).appendChild(script);
}

// Listen for message events posted from eme-trace-config, then forward the
// log to the log window. If the log window is closed, this message gets
// dropped.
window.addEventListener('message', (event) => {
if (event.data.type == 'emeTraceLog') {
chrome.runtime.sendMessage({
type: 'EME_LOGGER_TRACE',
log: event.data.log,
});
// Insert a script tag and force it to load synchronously.
const script = document.createElement('script');
script.type = 'text/javascript';
script.defer = false;
script.async = false;
script.src = absoluteUrl;
(document.head || document.documentElement).appendChild(script);
}
});

// Listen for message events posted from eme-trace-config, then forward the
// log to the log window. If the log window is closed, this message gets
// dropped.
window.addEventListener('message', (event) => {
if (event.data.type == 'emeTraceLog') {
chrome.runtime.sendMessage({
type : 'EME_LOGGER_TRACE',
log : event.data.log,
});
}
});
})();
Loading

0 comments on commit 3b8ed85

Please sign in to comment.