View in English

  • Apple Developer
    • 시작하기

    시작하기 탐색

    • 개요
    • 알아보기
    • Apple Developer Program

    알림 받기

    • 최신 뉴스
    • Hello Developer
    • 플랫폼

    플랫폼 탐색

    • Apple 플랫폼
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    피처링

    • 디자인
    • 배포
    • 게임
    • 액세서리
    • 웹
    • 홈
    • CarPlay
    • 기술

    기술 탐색

    • 개요
    • Xcode
    • Swift
    • SwiftUI

    피처링

    • 손쉬운 사용
    • 앱 인텐트
    • Apple Intelligence
    • 게임
    • 머신 러닝 및 AI
    • 보안
    • Xcode Cloud
    • 커뮤니티

    커뮤니티 탐색

    • 개요
    • Apple과의 만남 이벤트
    • 커뮤니티 주도 이벤트
    • 개발자 포럼
    • 오픈 소스

    피처링

    • WWDC
    • Swift Student Challenge
    • 개발자 이야기
    • App Store 어워드
    • Apple 디자인 어워드
    • 문서

    문서 탐색

    • 문서 라이브러리
    • 기술 개요
    • 샘플 코드
    • 휴먼 인터페이스 가이드라인
    • 비디오

    릴리즈 노트

    • 피처링 업데이트
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • 다운로드

    다운로드 탐색

    • 모든 다운로드
    • 운영 체제
    • 애플리케이션
    • 디자인 리소스

    피처링

    • Xcode
    • TestFlight
    • 서체
    • SF Symbols
    • Icon Composer
    • 지원

    지원 탐색

    • 개요
    • 도움말
    • 개발자 포럼
    • 피드백 지원
    • 문의하기

    피처링

    • 계정 도움말
    • 앱 심사 지침
    • App Store Connect 도움말
    • 새로 추가될 요구 사항
    • 계약 및 지침
    • 시스템 상태
  • 빠른 링크

    • 이벤트
    • 뉴스
    • 포럼
    • 샘플 코드
    • 비디오
 

비디오

메뉴 열기 메뉴 닫기
  • 컬렉션
  • 전체 비디오
  • 소개

더 많은 비디오

  • 소개
  • 요약
  • 코드
  • Safari용 웹 확장 프로그램 생성하기

    Xcode 없이 처음부터 빌드하고 테스트하는 것으로 Safari 웹 확장 프로그램을 시작해 보세요. 콘텐츠 차단, 페이지 수정, 네이티브 메시지, 권한 모드를 함께 사용하여 다양한 플랫폼 전반에 걸쳐 강력하고 개인정보를 보호하는 브라우징 경험을 선사하는 방법을 살펴보세요.

    챕터

    • 0:00 - Introduction
    • 3:23 - Get started
    • 7:23 - Block content
    • 14:40 - Modify webpages
    • 19:53 - Package and distribute
    • 22:33 - Communicate with your app
    • 26:04 - Next steps

    리소스

    • w3.org — W3C WebExtensions Community Group
    • Packaging and distributing Safari Web Extensions with App Store Connect
    • WebKit.org – Report issues to the WebKit open-source project
    • Submit feedback
    • MDN Web Docs - Web Extensions API
      • HD 비디오
      • SD 비디오

    관련 비디오

    WWDC26

    • Safari 27용 WebKit의 새로운 기능
  • 비디오 검색…
    • 3:44 - Manifest file

      {
          "manifest_version": 3,
          "name": "Shiny OnTrack",
          "description": "Stay on track while you browse the web",
          "version": 1.0
      }
    • 4:29 - Adding an extension icon

      {
          "manifest_version": 3,
          "name": "Shiny OnTrack",
          "description": "Stay on track while you browse the web",
          "version": 1.0,
      
          "icons": {
              "512": "images/icon.svg"
          }
      }
    • 5:30 - Adding an action button

      {
          "manifest_version": 3,
          "name": "Shiny OnTrack",
          "description": "Stay on track while you browse the web",
          "version": 1.0,
      
          "action": {
              "default_popup": "popup.html"
          }
      }
    • 6:17 - Adding custom UI to your extension

      {
          "manifest_version": 3,
          "name": "Shiny OnTrack",
          "description": "Stay on track while you browse the web",
          "version": 1.0,
        
          "options_ui": {
              "page": "options.html"
          }
      }
    • 6:30 - Including the UI in the extension manifest

      {
          "manifest_version": 3,
          "name": "Shiny OnTrack",
          "description": "Stay on track while you browse the web",
          "version": 1.0,
      
          "icons": {
              "512": "images/icon.svg"
          },
      
          "options_ui": {
              "page": "options.html"
          }
      }
    • 6:40 - Hello World

      <!DOCTYPE html>
      <html>
          <body>
          <p>Hello World</p>
          </body>
      </html>
    • 8:18 - Adding declarativeNetRequest permission

      {
          "manifest_version": 3,
          "name": "Shiny OnTrack",
          "description": "Stay on track while you browse the web",
          "version": 1.0,
      
          "icons": {
              "512": "images/icon.svg"
          },
      
          "options_ui": {
              "page": "options.html"
          },
        
          "permissions": [ "declarativeNetRequest" ]
      }
    • 8:22 - Blocking network requests

      // block rule
      {
          id: 1,
          priority: 1,
          action: {
              type: "block"
          },
          condition: {
              urlFilter: "||webkit.org",
              resourceTypes: [ "main_frame" ]
          }
      }
    • 8:41 - Modifying network requests

      {
          "manifest_version": 3,
          "name": "Shiny OnTrack",
          "description": "Stay on track while you browse the web",
          "version": 1.0,
      
          "icons": {
              "512": "images/icon.svg"
          },
      
          "options_ui": {
              "page": "options.html"
          },
        
          "permissions": [ "declarativeNetRequest" ],
      
          "declarativeNetRequest": {
              "rule_resources": [
                  {
                      "id": "ruleset_id",
                      "enabled": true,
                      "path": "rules.json"
                  }
              ]
          }
      }
    • 8:50 - Updating dynamic rules

      await browser.declarativeNetRequest.updateDynamicRules({
          addRules: [ rule ]
      })
    • 9:19 - Wiring up the static declarativeNetRequest rules

      {
          "manifest_version": 3,
          "name": "Shiny OnTrack",
          "description": "Stay on track while you browse the web",
          "version": 1.0,
      
          "icons": {
              "512": "images/icon.svg"
          },
      
          "options_ui": {
              "page": "options.html"
          },
        
          "permissions": [ 
            "declarativeNetRequest" 
          ]
      }
    • 9:40 - Adding block rules dynamically

      // A helper function to map the host to the declarative net request rule ID.
      export function hostToRuleID(host) {
      	let hash = 0;
      	for (let i = 0; i < host.length; i++) {
      		hash = ((hash << 5) + hash) + host.charCodeAt(i);
      		hash |= 0;
      	}
      	return Math.abs(hash) || 1;
      }
      
      function createBlockRule(host) {
      	return {
      		id: hostToRuleID(host),
      		priority: 1,
      		action: {
      			type: "block"
      		},
      		condition: {
      			urlFilter: `||${host}`,
      			resourceTypes: ["main_frame"]
      		}
      	}
      }
      
      export async function createRules(hosts) {
      	try {
      		await browser.declarativeNetRequest.updateDynamicRules({
      			addRules: hosts.map(createBlockRule)
      		})
      	} catch {
      		console.log("Failed to create declarative net request rules")
      	}
      }
    • 10:10 - Handling adding hosts to the settings

      import { createRules, removeAllRules, removeRule } from './rules.js'
      
      export async function addHost(host, blockingMode) {
        if (!host)
          return
        
        if (blockingMode === "full")
          await createRules([host])
      }
    • 10:48 - Redirecting network requests

      {
          id: 1,
          priority: 1,
          action: {
              type: "redirect",
              redirect: {
                  extensionPath: "/blocked.html"
              }
          },
          condition: {
              urlFilter: "||webkit.org",
              resourceTypes: [ "main_frame" ]
          }
      }
    • 11:17 - Declaring optional host permissions

      {
          "manifest_version": 3,
          "name": "Shiny OnTrack",
          "description": "Stay on track while you browse the web",
          "version": 1.0,
      
          "icons": {
              "512": "images/icon.svg"
          },
      
          "options_ui": {
              "page": "options.html"
          },
        
          "permissions": [ "declarativeNetRequestWithHostAccess" ],
          "optional_host_permissions": [ "https://webkit.org/*" ]
      
      }
    • 11:54 - Declaring optional host permissions for all sites

      {
          "manifest_version": 3,
          "name": "Shiny OnTrack",
          "description": "Stay on track while you browse the web",
          "version": 1.0,
      
          "icons": {
              "512": "images/icon.svg"
          },
      
          "options_ui": {
              "page": "options.html"
          },
        
          "permissions": [ "declarativeNetRequestWithHostAccess" ],
          "optional_host_permissions": [ "*://*/*" ]
      
      }
    • 13:12 - Add the redirect rule

      // A helper function to map the host to the declarative net request rule ID.
      export function hostToRuleID(host) {
      	let hash = 0;
      	for (let i = 0; i < host.length; i++) {
      		hash = ((hash << 5) + hash) + host.charCodeAt(i);
      		hash |= 0;
      	}
      	return Math.abs(hash) || 1;
      }
      
      function createBlockRule(host) {
      	return {
      		id: hostToRuleID(host),
      		priority: 1,
      		action: {
      			type: "block"
      		},
      		condition: {
      			urlFilter: `||${host}`,
      			resourceTypes: ["main_frame"]
      		}
      	}
      }
      
      function createRedirectRule(host) {
      	return {
      		id: hostToRuleID(host),
      		priority: 1,
      		action: {
      			type: "redirect",
      			redirect: { extensionPath: "/blocked.html" }
      		},
      		condition: {
      			urlFilter: `||${host}`,
      			resourceTypes: ["main_frame"]
      		}
      	}
      }
      
      export async function createRules(hosts) {
      	try {
      		await browser.declarativeNetRequest.updateDynamicRules({
      			addRules: hosts.map(createRedirectRule)
      		})
      	} catch {
      		console.log("Failed to create declarative net request rules")
      	}
      }
    • 13:42 - Dynamically ask for host permissions

      import { createRules, removeAllRules, removeRule } from './rules.js'
      
      export async function addHost(host, blockingMode) {
        if (!host)
          return
        
        const granted = await browser.permissions.request({
          origins: [`*://${host}/*`, `*://*.${host}/*`]
        })
        if (!granted)
          return
        
        if (blockingMode === "full")
          await createRules([host])
      }
    • 14:55 - Defining content scripts

      {
          "manifest_version": 3,
          "name": "Shiny OnTrack",
          "description": "Stay on track while you browse the web",
          "version": 1.0,
      
          "icons": {
              "512": "images/icon.svg"
          },
      
          "options_ui": {
              "page": "options.html"
          },
        
          "permissions": [ "declarativeNetRequestWithHostAccess" ],
          "optional_host_permissions": [ "*://*/*" ],
        
          "content_scripts": [
              {
                  "js": [ "content.js" ],
                  "css": [ "content.css" ],
                  "matches": [ "*://*.webkit.org/*" ]
              }
          ]
      }
    • 15:13 - Dynamically registering content scripts

      let script = {
          id: "id",
          js: [ "content.js" ],
          css: [ "content.css" ],
          matches: [ "*://*.webkit.org/*" ],
          persistAcrossSessions: true
      }
      
      await browser.scripting.registerContentScripts([ script ])
    • 15:31 - Adding the scripting permission

      {
          "manifest_version": 3,
          "name": "Shiny OnTrack",
          "description": "Stay on track while you browse the web",
          "version": 1.0,
        
          "icons": {
              "512": "images/icon.svg"
          },
        
          "options_page": "options.html",
        
          "permissions": [
              "declarativeNetRequestWithHostAccess",
              "scripting"
          ],
        
          "optional_host_permissions": [ "*://*/*" ]
      }
    • 15:41 - Registering content scripts

      // scripting.js
      
      function contentScript(host) {
          return {
              id: `cs-${host}`,
              js: [ "content.js" ],
              css: [ "content.css" ],
              matches: [ `*://${host}/*`, `*://*.${host}/*` ],
              persistAcrossSessions: true
          }
      }
      
      export function registerScripts(hosts) {
          const scripts = hosts.map(contentScript)
          try {
              await browser.scripting.registerContentScripts(scripts)
          } catch {
              console.log("Failed to register content scripts")
          }
      }
    • 16:02 - Adding a host

      // host.js
      
      export async function addHost(host, blockMode) {
          if (!host)
              return
      
          const granted = await browser.permissions.request({
              origins: [`*://${host}/*`, `*://*.${host}/*`]
          })
      
          if (!granted)
              return
      
          if (blockingMode === "full")
              await createRules([ host ])
      
          await registerScripts([ host ])
      }
    • 17:06 - Web extensions storage APIs

      await browser.session.storage.set({
        key: value
      })
      
      await browser.local.storage.set({
        key: value
      })
    • 17:21 - Adding storage permission to the web extension manifest.json

      {
          "manifest_version": 3,
          "name": "Shiny OnTrack",
          "description": "Stay on track while you browse the web",
          "version": 1.0,
        
          "icons": {
              "512": "images/icon.svg"
          },
        
          "options_page": "options.html",
        
          "permissions": [
              "declarativeNetRequestWithHostAccess",
              "scripting",
              "storage"
          ],
        
          "optional_host_permissions": [ "*://*/*" ]
      }
    • 17:30 - Saving data with storage

      // storage.js
      
      export async function updateHosts(hosts) {
          await browser.storage.local.set({ hosts: hosts })
      }
      
      export async function getHosts() {
          const { hosts = [] } = await browser.storage.local.get("hosts")
          return hosts
      }
      
      export async function saveBlockMode(mode) {
          await browser.storage.local.set({ blockMode: mode })
      }
      
      export async function getBlockMode() {
          const { blockMode = "full" } = await browser.storage.local.get("blockMode")
          return blockMode
      }
    • 17:41 - Persisting hosts to storage

      // host.js
      
      export async function addHost(host, blockMode) {
          if (!host)
              return
      
          const granted = await browser.permissions.request({
              origins: [`*://${host}/*`, `*://*.${host}/*`]
          })
      
          if (!granted)
              return
      
          if (blockingMode === "full")
              await createRules([ host ])
      
          await registerScripts([ host ])
      
          let existingHosts = await getHosts()
          let updatedHosts = [ ...existingHosts, host ]
          await updateHosts(updatedHosts)
      }
    • 17:51 - Reading from storage

      // options.js
      
      let existingHosts = await getHosts()
      let blockMode = await getBlockMode()
      
      displayBlocklist(existingHosts)
    • 18:00 - Switching block modes

      // host.js
      
      export async function userDidSwitchMode(blockMode) {
          await saveBlockMode(blockMode)
      
          if (blockMode === "full") {
              let hosts = await getHosts()
              await createRules(hosts)
          } else
              await removeAllRules()
      }
    • 19:01 - Adding a background script

      {
          "manifest_version": 3,
          "name": "Shiny OnTrack",
          "description": "Stay on track while you browse the web",
          "version": 1.0,
        
          "icons": {
              "512": "images/icon.svg"
          },
        
          "options_page": "options.html",
        
          "permissions": [
              "declarativeNetRequestWithHostAccess",
              "scripting",
              "storage"
          ],
        
          "optional_host_permissions": [ "*://*/*" ],
        
          "background": {
              "scripts": [ "background.js" ],
              "type": "module"
          }
      }
    • 19:39 - Background script

      // background.js
      
      import { registerScripts } from "./utilities/scripting.js"
      import { getHosts } from "./utilities/storage.js"
      
      browser.runtime.onInstalled.addListener(async (details) => {
          if (details.reason !== "update")
              return
      
          const hosts = await getHosts()
          await registerScripts(hosts)
      })
    • 22:49 - Package your web extension into an app for Xcode

      xcrun safari-web-extension-packager --copy-resources /path/to/ShinyOnTrack
    • 23:32 - Adding the nativeMessaging permission

      {
          "manifest_version": 3,
          "name": "Shiny OnTrack",
          "description": "Stay on track while you browse the web",
          "version": 1.0,
        
          "icons": {
              "512": "images/icon.svg"
          },
        
          "options_page": "options.html",
        
          "permissions": [
              "declarativeNetRequestWithHostAccess",
              "scripting",
              "storage",
              "nativeMessaging"
          ],
        
          "optional_host_permissions": [ "*://*/*" ],
        
          "background": {
              "scripts": [ "background.js" ],
              "type": "module"
          }
      }
    • 23:40 - Sending a native message

      // background.js
      
      import { registerScripts } from "./utilities/scripting.js"
      import { getHosts } from "./utilities/storage.js"
      
      browser.runtime.onInstalled.addListener(async (details) => {
          if (details.reason !== "update")
              return
      
          const hosts = await getHosts()
          await registerScripts(hosts)
      })
      
      export async function requestBioAuth() {
          const message = { message: "requestBioAuth" }
          const response = await browser.runtime.sendNativeMessage(message)
          return response?.success
      }
    • 23:55 - Handling native messages

      // SafariWebExtensionHandler.swift
      
      import LocalAuthentication
      
      class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
          func beginRequest(with context: NSExtensionContext) {
              let request = context.inputItems.first as? NSExtensionItem
              let message = request?.userInfo?[SFExtensionMessageKey] as? [String: Any]
      
              if message?["message"] as? String == "requestBioAuth" {
                  let lAContext = LAContext()
                  Task {
                      do {
                          let success = try await lAContext.evaluatePolicy(
                              .deviceOwnerAuthenticationWithBiometrics,
                              localizedReason: "Authenticate to change blocked sites"
                          )
                          self.reply(context: context, success: success)
                      } catch {
                          self.reply(context: context, success: false)
                      }
                  }
              }
          }
      }
    • 24:25 - Replying to a native message

      // SafariWebExtensionHandler.swift
      
      import LocalAuthentication
      
      class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
          func beginRequest(with context: NSExtensionContext) {
              let request = context.inputItems.first as? NSExtensionItem
              let message = request?.userInfo?[SFExtensionMessageKey] as? [String: Any]
      
              if message?["message"] as? String == "requestBioAuth" {
                  let lAContext = LAContext()
                  Task {
                      do {
                          let success = try await lAContext.evaluatePolicy(
                              .deviceOwnerAuthenticationWithBiometrics,
                              localizedReason: "Authenticate to change blocked sites"
                          )
                          self.reply(context: context, success: success)
                      } catch {
                          self.reply(context: context, success: false)
                      }
                  }
              }
          }
      
          private func reply(context: NSExtensionContext, success: Bool) {
              let response = NSExtensionItem()
              response.userInfo = [SFExtensionMessageKey: ["success": success]]
              context.completeRequest(returningItems: [response], completionHandler: nil)
          }
      }
    • 0:00 - Introduction
    • Learn how Safari web extensions — built with HTML, CSS, and JavaScript and packaged inside an app — can run across iOS, iPadOS, macOS, and visionOS. Preview the distraction-blocker extension built throughout the session, which offers a 10-minute light mode and a full redirect mode.

    • 3:23 - Get started
    • Set up an extension from scratch by writing a manifest.json file, then add a popup UI so the extension is reachable from Safari's toolbar. The same project runs unchanged across every Apple platform that ships Safari.

    • 7:23 - Block content
    • Use the declarativeNetRequest API to block, modify, and redirect network requests, and declare the host permissions — including optional host permissions — that let users grant access on the sites where the extension should run.

    • 14:40 - Modify webpages
    • Inject content into pages with content scripts to render a countdown timer on distracting sites. Register scripts dynamically with the scripting API and persist user preferences and per-host state using the storage API and a background service worker.

    • 19:53 - Package and distribute
    • Submit a Safari web extension to the App Store using App Store Connect, and share beta builds with testers through TestFlight.

    • 22:33 - Communicate with your app
    • Generate an Xcode project with the Safari Web Extension Packager, then use native messaging to pass requests between the JavaScript extension and its containing app — unlocking platform features like Local Authentication that aren't available to web APIs.

    • 26:04 - Next steps
    • Download the sample project, explore the cross-browser WebExtensions documentation on MDN, and file feedback through Feedback Assistant or bugs.webkit.org.

Developer Footer

  • 비디오
  • WWDC26
  • Safari용 웹 확장 프로그램 생성하기
  • 메뉴 열기 메뉴 닫기
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    메뉴 열기 메뉴 닫기
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • SF Symbols
    메뉴 열기 메뉴 닫기
    • 손쉬운 사용
    • 액세서리
    • Apple Intelligence
    • 앱 확장 프로그램
    • App Store
    • 오디오 및 비디오(영문)
    • 증강 현실
    • 디자인
    • 배포
    • 교육
    • 서체(영문)
    • 게임
    • 건강 및 피트니스
    • 앱 내 구입
    • 현지화
    • 지도 및 위치
    • 머신 러닝 및 AI
    • 오픈 소스(영문)
    • 보안
    • Safari 및 웹(영문)
    메뉴 열기 메뉴 닫기
    • 문서(영문)
    • 튜토리얼
    • 다운로드
    • 포럼(영문)
    • 비디오
    메뉴 열기 메뉴 닫기
    • 지원 문서
    • 문의하기
    • 버그 보고
    • 시스템 상태(영문)
    메뉴 열기 메뉴 닫기
    • Apple Developer
    • App Store Connect
    • 인증서, 식별자 및 프로파일(영문)
    • 피드백 지원
    메뉴 열기 메뉴 닫기
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program(영문)
    • Mini Apps Partner Program
    • News Partner Program(영문)
    • Video Partner Program(영문)
    • Security Bounty Program(영문)
    • Security Research Device Program(영문)
    메뉴 열기 메뉴 닫기
    • Apple과의 만남
    • Apple Developer Center
    • App Store 어워드(영문)
    • Apple 디자인 어워드
    • Apple Developer Academy(영문)
    • WWDC
    최신 뉴스 읽기.
    Apple Developer 앱 받기.
    Copyright © 2026 Apple Inc. 모든 권리 보유.
    약관 개인정보 처리방침 계약 및 지침