antfu / vitesse-webext

⚡️ WebExtension Vite Starter Template

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why I can't get `browser.downloads` in background.js

jacktang opened this issue · comments

In background/main.ts I tried to save some filed on some specified message. And the code snippet

onMessage('save-me', async () => {
  console.log("downloads?", browser.downloads);

  const blob = new Blob(["array of", ' parts of ', "text file"], {type: "text/plain"});
  const url = URL.createObjectURL(blob);
  try {
    await browser.downloads.download({
      url, 
      filename: 'test.txt', 
    })
  } catch (error) {
    console.log('saved failed', error);
  }
})

browser.downloads always undefined. Do you know why?

i got it. I missed opening permission.