0

I'm trying to send a file from my webpage to my chrome extension but I don't have a clue how to do it. Could somebody help me please?

Cheers! Imox

droidBomb
  • 850
  • 5
  • 8

1 Answers1

0

You can send the file's URI to your server. Then your server-side code will download it from the page into the server and process it.

Then proceed to the following steps:

  1. Add file path to the web_accessible_resources property in the manifest.json file
  2. Get the URL of the file using chrome.runtime.getURL('path/to/file').
  3. Make a GET request to the URL:

    const url = chrome.runtime.getURL('path/to/file');
    
    fetch(url)
         .then((response) => response.json()) //assuming file contains json
         .then((json) => doSomething(json));
    

Related SO post:

Related Blog Post:

Chrome Extension Documentation:

piet.t
  • 11,718
  • 21
  • 43
  • 52
Jessica Rodriguez
  • 2,899
  • 1
  • 12
  • 27