0

We are having a chrome extension with Manifest V3 and we created a popup in the below code

async function openAlert({ html, title = chrome.runtime.getManifest().name, width = 300, height = 150, left, top }) {
  const w = left == null && top == null && (await chrome.windows.getCurrent());
  const w2 = await chrome.windows.create({
    url: `data:text/html,<title>${title}</title>${html}`.replace(/#/g, '%23'),
    type: 'popup',
    left: left ?? Math.floor(w.left + (w.width - width) / 2),
    top: top ?? Math.floor(w.top + (w.height - height) / 2),
    height,
    width,
  });
  return new Promise(resolve => {
    chrome.windows.onRemoved.addListener(onRemoved, { windowTypes: ['popup'] });
    function onRemoved(id) {
      if (id === w2.id) {
        chrome.windows.onRemoved.removeListener(onRemoved);
        resolve();
      }
    }
  });
}

Now are adding the input field in the below way

openAlert({
          html: `Foo <b>bar</b><div><input type="text" id="myInput" oninput="myFunction()"><script>function myFunction() {
          var x = document.getElementById("myInput").value;
          console.log("input field", x)
        }</script></div>`,
        }).then(() => console.log('alert closed'));

Then above invocation, we are doing in the service-worker(previously background.js).

No I am unable to fetch the value which is entered by the user in the above window/popup which we created into the servier-worker.Is there any way to get it

*Note:- We are creating the window in the service-worker

0 Answers0