I'm having a hard time understanding why this won't work:
I'm using a listener on oncompleted to trigger when one of two urls is visited.
chrome.webNavigation.onCompleted.addListener(details => {
console.log('this function is doing things once you visit the website');
},
);
this is functional code that will trigger correctly.
But the thing is is that I want these urls to be able to be changed by the user instead of being static.
When I replace the whole array of objects with a variable it works fine.
i.e.
if I use this code:
{url: urlFilterList}
then this is functional code that triggers correctly.
But I want to build is array of objects from a user-inputted list of strings.
Mapping and ForEach are giving me errors, so I built a quick function to do it myself -
let urlFilterFromScratch = [ ];
function mapObjectsToArray(arrIn, arrOut) {
for (let i = 0; i < arrIn.length; i++) {
let temp = { hostContains: arrIn[i] };
arrOut.push(temp);
}
};
mapObjectsToArray(urlInput, urlFilterFromScratch);
I now have a built array of length two that looks exactly like the web navigation array I was using before.
But when I apply it to the url filter section
{url: urlFilterFromScratch}
the code doesn't give an error, but instead acts like there's no url filter at all. Which means the onCompleted trigger triggers on any website that the user navigates to, instead of just the ones listed.
I've also tried to build an object containing the url: property filled with an array of the different properties, but when I put that in the place of the {url:} object the code threw an error and wouldn't register the service worker on upload.
Why is this? What can I do about it?
Is there something I'm doing wrong?
Or is this the wrong direction and I need to do something totally different?
Thanks for your time,
Tyler