I've got a constants.js
file that contains export statements like:
const domains = ['target.com', 'amazon.com', '88rising.com'];
When I import from another file, which looks like this:
const domains = ['target.com', 'amazon.com', '88rising.com'];
document.addEventListener('DOMContentLoaded', () => {
chrome.tabs.query({active: true, currentWindow: true}, tabs => {
const currentUrl = tabs[0].url;
const truncatedUrlElement = document.getElementById('truncated-url');
const siteIndexElement = document.getElementById('index-number');
truncatedUrl = new URL(currentUrl).hostname.replace(/^www\./, '');
truncatedUrlElement.textContent = truncatedUrl;
console.log(truncatedUrl)
siteIndex = domains.indexOf(truncatedUrl) + 1;
siteIndexElement.textContent = siteIndex.toString();
});
});
domains
actually does properly log to the console, but is not properly logging from inside the document.addEventListener
block. I'm having a really tough time understanding why this would be the case, and how to properly reference and import constants from my constants.js
file across my entire Chrome extension project.
Tried to import a variable from another file, constants.js
and expected the reference to be correctly handled.
It's strangely working at the beginning of the file, but not in the middle where it needs to?