-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.md
289 lines (268 loc) · 10.2 KB
/
index.md
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
---
title: page_action
slug: Mozilla/Add-ons/WebExtensions/manifest.json/page_action
---
{{AddonSidebar}}
<table class="fullwidth-table standard-table">
<tbody>
<tr>
<th scope="row" style="width: 30%">型</th>
<td><code>Object</code></td>
</tr>
<tr>
<th scope="row">必須</th>
<td>いいえ</td>
</tr>
<tr>
<th scope="row">例</th>
<td>
<pre class="brush: json no-line-numbers">
"page_action": {
"browser_style": true,
"default_icon": {
"19": "button/geo-19.png",
"38": "button/geo-38.png"
},
"default_title": "Whereami?",
"default_popup": "popup/geo.html"
}</pre
>
</td>
</tr>
</tbody>
</table>
ページアクションは拡張機能がブラウザーの URL バーの中に追加できるアイコンです。
拡張機能では関連したポップアップをつけて、そこで HTML、CSS、 JavaScript を使ったコンテンツを提供することもできます。
ポップアップを提供した場合、ユーザーがアイコンをクリックした時にポップアップが開いて、ポップアップ内で実行する JavaScript にてユーザーのインタラクションを扱います。ポップアップをつけない場合、ユーザーがアイコンをクリックした時のクリックイベントは拡張機能の [background scripts](/ja/Add-ons/WebExtensions/Anatomy_of_a_WebExtension#Background_pages) に送られます。
[pageAction API](/ja/Add-ons/WebExtensions/API/pageAction) を使用してプログラムでページアクションを作成および操作することもできます。
ページアクションはブラウザーアクションと似ていますが、ブラウザー全体ではなく特定のウェブページに関連付けられている点が異なります。アクションが特定のページにのみ関連している場合は、ページアクションを使用して関連するページにのみ表示する必要があります。アクションがすべてのページまたはブラウザー自体に関連している場合は、ブラウザーアクションを使用してください。
ブラウザーアクションはデフォルトで表示されますが、ページアクションはデフォルトで非表示になります。タブの ID を渡して [`pageAction.show()`](/ja/Add-ons/WebExtensions/API/pageAction/show) を呼び出すことで、それらを特定のタブに対して表示できます。show_matches プロパティを使用してこのデフォルトの動作を変更することもできます。
## 構文
The `page_action` key is an object that may have any of three properties, all optional:
<table class="fullwidth-table standard-table">
<thead>
<tr>
<th scope="col">名前</th>
<th scope="col">型</th>
<th scope="col">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code
><a
href="/ja/docs/Mozilla/Add-ons/WebExtensions/user_interface/Browser_styles"
>browser_style</a
></code
>
</td>
<td><code>Boolean</code></td>
<td>
<p>Optional, defaulting to <code>false</code>.</p>
<p>
Use this to include a stylesheet in your popup that will make it look
consistent with the browser's UI and with other extensions that use
the <code>browser_style</code> property. Although this key defaults to
<code>false</code>, it's recommended that you include it and set it to
<code>true</code> in order to make your popups consistent with the
look of the rest of the browser user interface.
</p>
<p>
In Firefox, the stylesheet can be seen at
chrome://browser/content/extension.css, or
chrome://browser/content/extension-mac.css on OS X.
</p>
<p>
The
<a href="https://firefoxux.github.io/StyleGuide/#/controls"
>Firefox Style Guide</a
>
describes the classes you can apply to elements in the popup in order
to get particular styles.
</p>
<p>
The
<a
href="https://github.com/mdn/webextensions-examples/tree/master/latest-download"
>latest-download</a
>
example extension uses <code>browser_style</code> in its popup.
</p>
</td>
</tr>
<tr>
<td><code>default_icon</code></td>
<td><code>Object</code> or <code>String</code></td>
<td>
<p>Use this to specify an icon for the action.</p>
<p>
It's recommended that you supply two icons here, one 19x19 pixels, and
one 38x38 pixels, and specify them in an object with properties named
"19" and "38", like this:
</p>
<pre class="brush: json no-line-numbers">
"default_icon": {
"19": "geo-19.png",
"38": "geo-38.png"
}</pre
>
<p>
If you do this, then the browser will pick the right size icon for the
screen's pixel density.
</p>
<p>You can just supply a string here:</p>
<pre class="brush: json no-line-numbers">"default_icon": "geo.png"</pre>
<p>
If you do this, then the icon will be scaled to fit the toolbar, and
may appear blurry.
</p>
</td>
</tr>
<tr>
<td><code>default_popup</code></td>
<td><code>String</code></td>
<td>
<p>
The path to an HTML file containing the specification of the popup.
</p>
<p>
The HTML file may include CSS and JavaScript files using
<code><a href="/ja/docs/Web/HTML/Element/link"><link></a></code>
and
<code
><a href="/ja/docs/Web/HTML/Element/script"><script></a></code
>
elements, just like a normal web page. However, don't use
<code
><a href="/ja/docs/Web/HTML/Element/script"><script></a></code
>
with embedded code, because you'll get a Content Violation Policy
error. Instead,
<code
><a href="/ja/docs/Web/HTML/Element/script"><script></a></code
>
must use the
<code><a href="/ja/docs/Web/HTML/Element/script">src</a></code>
attribute to load a separate script file.
</p>
<p>
Unlike a normal web page, JavaScript running in the popup can access
all the
<a href="/ja/Add-ons/WebExtensions/API">WebExtension APIs</a>
(subject, of course, to the extension having the appropriate
<a
href="/ja/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions"
>permissions</a
>).
</p>
<p>
これは<a
href="/ja/Add-ons/WebExtensions/Internationalization#Internationalizing_manifest.json"
>ローカライズ可能なプロパティ</a
>です。
</p>
</td>
</tr>
<tr>
<td><code>default_title</code></td>
<td><code>String</code></td>
<td>
<p>
Tooltip for the icon, displayed when the user moves their mouse over
it.
</p>
<p>
This is a
<a
href="/ja/Add-ons/WebExtensions/Internationalization#Internationalizing_manifest.json"
>localizable property</a
>.
</p>
</td>
</tr>
<tr>
<td><code>hide_matches</code></td>
<td>
<code>Array</code> of <code>Match Pattern</code> except
<code><all_urls></code>
</td>
<td>
<p>
Hide the page action 既定では for pages whose URLs match any of the
given
<a href="/ja/Add-ons/WebExtensions/match_patterns">match patterns</a>.
</p>
<p>
Note that page actions are always hidden 既定では unless
<code>show_matches</code> is given. Therefore it only makes sense to
include this property if <code>show_matches</code> is also given, and
in this case it will override the patterns in
<code>show_matches</code>. 例えば、consider a value like:
</p>
<pre class="brush: json">
"page_action": {
"show_matches": ["https://*.mozilla.org/*"],
"hide_matches": ["https://developer.mozilla.org/*"]
}</pre
>
<p>
This shows the page action 既定では for all HTTPS URLs under the
"mozilla.org" domain, except for pages under "developer.mozilla.org".
</p>
</td>
</tr>
<tr>
<td><code>show_matches</code></td>
<td><code>Array</code> of <code>Match Pattern</code></td>
<td>
<p>
Show the page action 既定では for pages whose URLs match any of the
given patterns.
</p>
<p>See also <code>hide_matches</code>.</p>
</td>
</tr>
<tr>
<td><code>pinned</code></td>
<td><code>Boolean</code></td>
<td>
<p>Optional, defaulting to <code>true</code>.</p>
<p>
Controls whether or not the page action should appear in the location
bar 既定では when the user installs the extension.
</p>
</td>
</tr>
</tbody>
</table>
## 例
```json
"page_action": {
"default_icon": {
"19": "button/geo-19.png",
"38": "button/geo-38.png"
}
}
```
A page action with just an icon, specified in 2 different sizes. The extension's background scripts can receive click events when the user clicks the icon using code like this:
```js
browser.pageAction.onClicked.addListener(handleClick);
```
```json
"page_action": {
"default_icon": {
"19": "button/geo-19.png",
"38": "button/geo-38.png"
},
"default_title": "Whereami?",
"default_popup": "popup/geo.html"
}
```
A page action with an icon, a title, and a popup. The popup will be shown when the user clicks the icon.
## ブラウザーの互換性
{{Compat}}
## 関連情報
- [`browser_action`](/ja/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_action)
- [`sidebar_action`](/ja/docs/Mozilla/Add-ons/WebExtensions/manifest.json/sidebar_action)
- [Browser styles](/ja/docs/Mozilla/Add-ons/WebExtensions/user_interface/Browser_styles)