回答編集履歴
1
じっさいのコード
test
CHANGED
@@ -1,3 +1,37 @@
|
|
1
1
|
locationで見分ける方法があることは思いつきました。
|
2
2
|
|
3
|
+
|
4
|
+
|
5
|
+
typescriptの例です。
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
```
|
10
|
+
|
11
|
+
type RunContext = 'content' | 'background' | 'sidebar';
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
// 実行環境の取得
|
16
|
+
|
17
|
+
export function runContext(): RunContext {
|
18
|
+
|
19
|
+
if (location.origin + location.pathname === chrome.runtime.getURL('pages/sidebar.html')) {
|
20
|
+
|
3
|
-
|
21
|
+
return 'sidebar';
|
22
|
+
|
23
|
+
}
|
24
|
+
|
25
|
+
if (location.href === chrome.runtime.getURL('_generated_background_page.html')) {
|
26
|
+
|
27
|
+
return 'background';
|
28
|
+
|
29
|
+
}
|
30
|
+
|
31
|
+
return 'content';
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
```
|