Chrome API identity.getAuthToken在Opera浏览器中返回undefined
引言
我开发了一个小型Chrome扩展,使用identity.getAuthToken方法对用户进行授权。在Chrome浏览器中一切正常,但切换到Opera浏览器时,获取到的token为undefined。
AppId和OAuth2已在Google Cloud控制台及manifest.json中配置完成,这部分应该不存在问题。
代码示例
window.onload = function () { // Read scores from local storage to display while authentication happens and actual scores are being fetched chrome.storage.local.get(["scores"], (data) => { if (Object.keys(data).length === 0 && data.constructor === Object) { return; } updateScores(data.scores); }); chrome.identity.getAuthToken( { interactive: true, }, function (token) { console.log("Identity token is: " + token); if (token === undefined) return; chrome.runtime.sendMessage( { command: "token", data: token }, (response) => retrieveScoreValues() ); } ); };
chrome.runtime.sendMessage用于将token发送至服务工作线程,retrieveScoreValues方法则向Google Sheets发送API请求以获取数据。
该扩展在Chrome浏览器中运行正常,仅在Opera浏览器中出现问题。
已尝试的解决方法
我尝试通过直接API请求获取authToken,但未成功。也曾从Chrome实例中复制token并硬编码到Opera的扩展中,这在token过期前可以正常工作,说明仅authToken的获取环节存在问题。
内容的提问来源于stack exchange,提问作者L30N74
相关产品推荐
相关产品推荐

