-
What’s new in Safari Web Extensions
Learn how you can use the latest improvements to Safari Web Extensions to create even better experiences for people browsing the web. We'll show you how to upgrade to manifest version 3, adopt the latest APIs for Web Extensions, and sync extensions across devices.
Recursos
- Modernizing Safari Web Extensions
- Messaging a Web Extension’s Native App
- Developing a Safari Web Extension
- Learn more about bug reporting
- MDN Web Docs - Web Extensions API
- Safari web extensions
Vídeos relacionados
WWDC23
WWDC22
WWDC21
-
Buscar neste vídeo...
-
-
2:43 - Executing script on webpages
// Manifest version 2 browser.tabs.executeScript(1, { frameId: 1, code: "document.body.style.background = 'blue';" }); -
3:00 - scripting.executeScript API
// Manifest version 3 function changeBackgroundColor(color) { document.body.style.background = color; }; browser.scripting.executeScript({ target: { tabId: 1, frameIds: [ 1 ] }, func: changeBackgroundColor, args: [ "blue" ] }); -
4:02 - tabs.executeScript file
// Manifest version 2 browser.tabs.executeScript({ 1, file: "file.js" }); -
4:09 - scripting.executeScript API files
// Manifest version 3 browser.scripting.executeScript({ target: { tabId: 1 }, files: [ "file.js", "file2.js" ] }); -
4:15 - scripting.insertCSS
// Add styling browser.scripting.insertCSS({ target: { tabId: 1, frameIds: [ 1, 2, 3 ] }, files: [ "file.css", "file2.css" ] }); -
4:21 - scripting.removeCSS
// Remove styling browser.scripting.removeCSS({ target: { tabId: 1, frameIds: [ 1, 2, 3 ] }, files: [ "file.css", "file2.css" ] }); -
5:08 - Manifest version 3 web_accessible_resources
// Manifest version 3 "web_accessible_resources": [ { "resources": [ "pie.png" ], "matches": [ "*://*.apple.com/*" ] }, { "resources": [ "cookie.png" ], "matches": [ "*://*.webkit.org/*" ] } ] -
5:42 - Manifest version 3 action
// Manifest version 3 "action": { "default_icon": { "16": "Images/icon16.png" }, "default_title": "defaultTitle" } -
5:57 - Manifest version 2 content_security_policy
// Manifest version 2 "content_security_policy" : "script-src 'unsafe-eval' https://*apple.com 'self'" -
6:08 - Manifest version 3 content_security_policy
// Manifest version 3 "content_security_policy" : { "extension_pages" : "script-src 'unsafe-eval' 'self'" } -
10:31 - Specifying a ruleset
// manifest.json "permissions": [ "declarativeNetRequest" ], "declarative_net_request": { "rule_resources": [ { "id": "my_ruleset", "enabled": true, "path": "rules.json" } ] } -
11:44 - updateSessionRules
// Rules that won't persist browser.declarativeNetRequest.updateSessionRules({ addRules: [ rule ] }); // Rules that will persist browser.declarativeNetRequest.updateDynamicRules({ addRules: [ rule ] }); -
14:33 - externally connectable
// In the webpage let extensionID = "com.apple.Sea-Creator.Extension (GJT7Q2TVD9)"; browser.runtime.sendMessage(extensionID, { greeting: "Hello!" }, function(response) { console.log("Received response from the background page:"); console.log(response.farewell); }); -
15:00 - Message from webpage to extension (in the webpage)
// In the webpage let extensionID = "com.apple.Sea-Creator.Extension (GJT7Q2TVD9)"; browser.runtime.sendMessage(extensionID, { greeting: "Hello!" }, function(response) { console.log("Received response from the background page:"); console.log(response.farewell); }); -
15:33 - Message from webpage to extension (in the background page)
// In the background page browser.runtime.onMessageExternal.addListener(function(message, sender, sendResponse) { console.log("Received message from the sender:"); console.log(message.greeting); sendResponse({ farewell: "Goodbye!" }); }); -
16:17 - Determining the correct identifier
// Determining the correct identifier function determineExtensionID(extensionID) { return new Promise((resolve) => { try { browser.runtime.sendMessage(extensionID, { action: 'determineID' }, function(response) { if (response) resolve({ extensionID: extensionID, isInstalled: true, response: response }); else resolve({ extensionID: extensionID, isInstalled: false }); }); } }); }; -
17:09 - background.js
// background.js browser.runtime.onMessageExternal.addListener(function(message, sender, sendResponse) { if (message.action == "determineID") { sendResponse({ "Installed" }); } }); -
18:07 - Unlimited storage
// manifest.json "permissions": [ "storage", "unlimitedStorage" ]
-