fetch('info.json').then(function (response) {
return response.json();
}).then(function (obj) {
console.log(obj);
}).catch(function (error) {
console.error('Something went wrong with retrieving the info!');
});
The file 'info.json' is in the same directory as this javascript file, and when I run it on chrome using dev tools, the console outputs 'Something went wrong with retrieving the data!' I'm not sure how to fix this as this is my first time working with developer tools and unloading a package via extensions on chrome. Any help would be appreciated! For those curious, I'm trying to create an autofiller for a site and the 'info.json' file contains info like name, address, etc.
This will make a request to https://example.com/info.json
You need to put this in your manifest:
"web_accessible_resources": [
"yourfolder/*"
],
Then in your script get the url
const myUrl = chrome.runtime.getURL('yourFolder/info.json')
fetch(myUrl).then(function (response) {
return response.json();
}).then(function (obj) {
console.log(obj);
}).catch(function (error) {
console.error('Something went wrong with retrieving the info!');
});