const url = chrome.runtime.getURL('./config/names.json');
fetch(url)
.then(
function(response) {
if (response.status !== 200) {
console.log('Looks like there was a problem. Status Code: ' +
response.status);
return;
}
// Examine the text in the response
response.json().then(function(data) {
console.log(data);
});
}
)
.catch(function(err) {
console.log('Fetch Error :-S', err);
});
2条答案
按热度按时间gdrx4gfi1#
如果此文件随扩展名一起提供,那么您可以在后台页面中使用
XMLHttpRequest
加载它(使用相对路径,/
是扩展根文件夹)。您也可以将您的文件设置为JavaScript(
var config=[...]
),然后将其与<script>
一起加载到后台页面。wkyowqbh2#
假设您的json文件是以下文件夹中的names.json
在manifest.json中添加资源路径
使用**fectch()* API访问资源