Skip to content

Commit 9230a50

Browse files
authored
[Side Panel API] Add copyright to sidepanel samples (#908)
* Add copyright to sidepanel samples * Fix year * Add error catching and async
1 parent 064dde6 commit 9230a50

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

functional-samples/cookbook.sidepanel-multiple/service-worker.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2023 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
const welcomePage = 'sidepanels/welcome-sp.html';
216
const mainPage = 'sidepanels/main-sp.html';
317

functional-samples/cookbook.sidepanel-site-specific/service-worker.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
1+
// Copyright 2023 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
const GOOGLE_ORIGIN = 'https://www.google.com';
216

317
// Allows users to open the side panel by clicking on the action toolbar icon
4-
chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: true });
18+
chrome.sidePanel
19+
.setPanelBehavior({ openPanelOnActionClick: true })
20+
.catch((error) => console.error(error));
521

6-
chrome.tabs.onUpdated.addListener((tabId, info, tab) => {
22+
chrome.tabs.onUpdated.addListener(async (tabId, info, tab) => {
723
if (!tab.url) return;
824
const url = new URL(tab.url);
925
// Enables the side panel on google.com
1026
if (url.origin === GOOGLE_ORIGIN) {
11-
chrome.sidePanel.setOptions({
27+
await chrome.sidePanel.setOptions({
1228
tabId,
1329
path: 'sidepanel.html',
1430
enabled: true
1531
});
1632
} else {
1733
// Disables the side panel on all other sites
18-
chrome.sidePanel.setOptions({
34+
await chrome.sidePanel.setOptions({
1935
tabId,
2036
enabled: false
2137
});

functional-samples/sample.sidepanel-dictionary/service-worker.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2023 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
function setupContextMenu() {
216
chrome.contextMenus.create({
317
id: 'define-word',

functional-samples/sample.sidepanel-dictionary/sidepanel.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2023 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
const words = {
216
extensions:
317
'Extensions are software programs, built on web technologies (such as HTML, CSS, and JavaScript) that enable users to customize the Chrome browsing experience.',

0 commit comments

Comments
 (0)