-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
32 lines (30 loc) · 1.16 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const gasUrl = "https://script.google.com/macros/s/AKfycbw7HtwqpXNQ-MHIjurYNrbCZR9pVZ5kdprn2SpH8VDDW_cfozMLGHKMguFCfY2wClCbVg/exec";
chrome.runtime.onMessage.addListener(
function (request, sender, callback) {
console.log(request);
console.info(JSON.stringify(request));
var json_asocc = request;
fetch(gasUrl, {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: JSON.stringify(json_asocc)
})
.then(response => response.json())
.then(data => {
console.log(data);
console.log(JSON.stringify(data));
callback(data);
})
.catch(error => {
// ネットワークエラーでも !response.ok でもここで処理できる
console.error(error);
console.error(error.toString());
callback(error.toString());
});
// 非同期を同期的に扱うためのtrue
return true;
}
);