回答編集履歴
1
async/promise や ; の有無を揃えた
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
browser.tabs.sendMessage(tabid , {data: 100})
|
16
16
|
|
17
|
-
.then(e => console.log(e)).catch(e => console.error(e))
|
17
|
+
.then(e => console.log(e)).catch(e => console.error(e))
|
18
18
|
|
19
19
|
// Error: Could not establish connection. Receiving end does not exist.
|
20
20
|
|
@@ -46,11 +46,11 @@
|
|
46
46
|
|
47
47
|
code: `
|
48
48
|
|
49
|
-
browser.runtime.onMessage.addListener(request => {
|
49
|
+
browser.runtime.onMessage.addListener(async request => {
|
50
50
|
|
51
51
|
console.log(request)
|
52
52
|
|
53
|
-
return
|
53
|
+
return {response: "ok"}
|
54
54
|
|
55
55
|
})
|
56
56
|
|
@@ -60,7 +60,7 @@
|
|
60
60
|
|
61
61
|
browser.tabs.sendMessage(tabid, {data: 100})
|
62
62
|
|
63
|
-
.then(e => console.log(e)).catch(e => console.error(e))
|
63
|
+
.then(e => console.log(e)).catch(e => console.error(e))
|
64
64
|
|
65
65
|
// Object { response: "ok" }
|
66
66
|
|
@@ -96,11 +96,11 @@
|
|
96
96
|
|
97
97
|
```javascript
|
98
98
|
|
99
|
-
browser.runtime.onMessage.addListener(request => {
|
99
|
+
browser.runtime.onMessage.addListener(async request => {
|
100
100
|
|
101
101
|
console.log(request)
|
102
102
|
|
103
|
-
return
|
103
|
+
return {response: "ok"}
|
104
104
|
|
105
105
|
})
|
106
106
|
|
@@ -119,3 +119,11 @@
|
|
119
119
|
|
120
120
|
|
121
121
|
あと、たしか拡張機能のページだと tabs でなく runtime で通信できたと思います。(Chrome では。Firefoxは試してないです)
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
---
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
コピペの影響でコードに統一性がなかったのでちょっと修正しました
|