mirror of
https://github.com/GoogleChrome/chrome-extensions-samples.git
synced 2026-03-27 13:29:34 +07:00
Web nav mv3 sample (#958)
* implemented webNavigation mv3 sample * Added mv3 webNavigation API sample * Changes based on review
This commit is contained in:
committed by
GitHub
parent
0af4863057
commit
cd11c730ea
13
api-samples/webNavigation/basic/README.md
Normal file
13
api-samples/webNavigation/basic/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# chrome.webNavigation
|
||||
|
||||
This sample demonstrates using the webNavigation API to send notifications.
|
||||
|
||||
## Overview
|
||||
|
||||
The extension calls the `chrome.webNavigation.onCompleted.addListener()` event listener to trigger a notification whenever a the user navigates to a new webpage.
|
||||
|
||||
## Running this extension
|
||||
|
||||
1. Clone this repository.
|
||||
2. Load this directory in Chrome as an [unpacked extension](https://developer.chrome.com/docs/extensions/mv3/getstarted/development-basics/#load-unpacked).
|
||||
3. Navigate the web with notifications on.
|
||||
BIN
api-samples/webNavigation/basic/icon.png
Normal file
BIN
api-samples/webNavigation/basic/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1001 B |
10
api-samples/webNavigation/basic/manifest.json
Normal file
10
api-samples/webNavigation/basic/manifest.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "webNavigation API Sample",
|
||||
"version": "2",
|
||||
"description": "A demonstration of the webNavigation API",
|
||||
"background": {
|
||||
"service_worker": "service-worker.js"
|
||||
},
|
||||
"permissions": ["webNavigation", "notifications"],
|
||||
"manifest_version": 3
|
||||
}
|
||||
27
api-samples/webNavigation/basic/service-worker.js
Normal file
27
api-samples/webNavigation/basic/service-worker.js
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright 2023 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
chrome.webNavigation.onCompleted.addListener((details) => {
|
||||
chrome.notifications.create({
|
||||
type: 'basic',
|
||||
iconUrl: 'icon.png',
|
||||
title: 'page loaded',
|
||||
message:
|
||||
'Completed loading: ' +
|
||||
details.url +
|
||||
' at ' +
|
||||
details.timeStamp +
|
||||
' milliseconds since the epoch.'
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user