Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove all variables and most functions from global scope #61

Merged
merged 1 commit into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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