ServiceWorker: scriptURL 屬性

Baseline 已廣泛支援

此功能已成熟,可跨多種裝置和瀏覽器版本工作。它自 ⁨2018 年 4 月⁩ 起已在所有瀏覽器中可用。

安全上下文: 此功能僅在安全上下文(HTTPS)中可用,且支援此功能的瀏覽器數量有限。

注意:此功能在 Web Workers 中可用。

返回作為 ServiceWorkerRegistration 的一部分定義的 ServiceWorker 序列化指令碼 URL。必須與註冊 ServiceWorker 的文件同源。

字串。

示例

js
const sw = navigator.serviceWorker.controller;
console.log(sw.scriptURL);
// https://example.com/scripts/service-worker.js

規範

規範
Service Workers
# service-worker-url

瀏覽器相容性