FedCM:Chrome 131 中 Storage Access API 的信任信號

原始碼試用成功後,Chrome 131 現在會使用 FedCM 做為 Storage Access API 的信任信號

Storage Access API (SAA) 可讓跨來源 iframe 在瀏覽器設定會拒絕存取要求的情況下,要求儲存空間存取權限。

部分網站可能會同時使用 FedCM 進行驗證,並使用 SAA 允許跨來源 iframe 存取必要儲存空間。舉例來說,如果 idp.example 嵌入 rp.example,且 idp.example 需要存取自己的頂層 Cookie,才能顯示個人化內容。

在這種情況下,使用者需要核准兩項不同的提示:一項用於驗證,另一項用於授予 Cookie 存取權,因為 SAA 會觸發權限提示。FedCM 可做為信任訊號,簡化 Storage Access API 程序。使用者透過 FedCM 登入後,系統會自動授予 IdP 啟動的儲存空間存取要求,因此不需要額外的 SAA 提示。

// In top-level rp.example:

// Ensure FedCM permission has been granted.
const cred = await navigator.credentials.get({
  identity: {
    providers: [{
      configURL: 'https://idp.example/fedcm.json',
      clientId: '123',
    }],
  }
});

// In an embedded IdP iframe:

// Returns `true` if the user already has access to cookies, and `false` if
// the user doesn't have access yet and needs to request it.
const hasAccess = await document.hasStorageAccess()
if(!hasAccess){
    // No user gesture is needed to approve storage access, and the call will be auto-granted.
    document.requestStorageAccess().then(e=>{
        //access cookies
    })
} else{
    //the iframe already has access to third-party cookies
}

原始碼試用參與者給予正面回饋,強調相較於一般儲存空間存取權 API 提示,針對特定情境的 FedCM 提示可提升使用者體驗。

如要進一步瞭解如何使用 FedCM 自動授予儲存空間存取權,請參閱儲存空間存取權 API 說明文件

參與討論並提供意見

如要提供意見或回報問題,請提出問題。我們會持續更新 FedCM 開發人員指南,以及累積更新記錄頁面