Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

350
Views
How to send a variable back from foreground.js to background.js

I tried to send my variable back from foreground.js to background.js by using an unchanged variable, and it works. Now I can't send some data that I use my AddEventListener syntax to store the data into the variable to call its back to background.js here are my code on foreground.js

foreground.js

console.log("foreground.js injected");

var pswdBtns = [];
let hrefLists = [];
var data = {};
var i;

function readUUID(){
    var navigator_info = window.navigator;
    var screen_info = window.screen;
    var uid = navigator_info.mimeTypes.length;
    uid += navigator_info.userAgent.replace(/\D+/g, '');
    uid += navigator_info.plugins.length;
    uid += screen_info.height || '';
    uid += screen_info.width || '';
    uid += screen_info.pixelDepth || '';
    return uid;
}

async function passwordProtected(pointerList){
    const date = new Date();
    const uid = readUUID();

    alert("You are in dangerous on \'"+ pointerList.title + "\' row = " + pointerList.id.slice(20));
    data = {
        "Webtitle": pointerList.href,
        "Title": pointerList.title,
        "Time": date.toString(),
        "UUID": uid
    }
    console.log("foreground = ", data);
    return data;
}

console.log("Start loop")
//This function made for collect each id in passwordShowPasswordButton
for(i = 0; i<=pswdBtns.length; i++){
    if(document.querySelector("#passwordShowPasswordButton_"+ i) == null){
        console.log("This is your limit!!");
    }
    else{
        hrefLists[i] = document.querySelector("#passwordWebsitelink_"+ i);
        pswdBtns[i] = document.querySelector("#passwordShowPasswordButton_"+ i);;
        data = pswdBtns[i].addEventListener('click', passwordProtected.bind(pswdBtns[i], hrefLists[i]));
        console.log(hrefLists[i].title);  /* Title VARCHAR(30) */
        console.log(hrefLists[i].href);  /* Website VARCHAR(50) */
    }
}
console.log("End");

and these are my code on background.js

background.js

const edgePswd = "edge://settings/passwords";
const settingPage = "edge://settings/";

chrome.tabs.onActivated.addListener(async (tab) => {
  await chrome.tabs.get(tab.tabId, (current_tab_info) => {
    var pswdPageChecked = 1;
    while(pswdPageChecked < 2) {
      if (edgePswd == current_tab_info.url) {
        chrome.tabs.executeScript(null, { file: "/extension/foreground.js" }, (data) => {
          console.log("Coming to foreground");
          console.log(data);
        });
        pswdPageChecked++;
      }
    }
  });
});

It would be a pleasure if someone can figure this.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!