Javascript oAuth交换后关闭Chrome窗口
我有打开窗口的代码Javascript oAuth交换后关闭Chrome窗口,javascript,dom,google-chrome-extension,gmail,Javascript,Dom,Google Chrome Extension,Gmail,我有打开窗口的代码 let mywindow = window.open("utl", "title", "resizable=yes,width=600,height=400,toolbar=no,titlebar=no,menubar=no,scrollbars=yes"); 我想访问窗口的当前URL,我已尝试: 窗口位置 window.document.url 每次尝试都会返回: 未捕获DOMEException:阻止原点为“”的帧访问跨原点帧。 评估时(评估时)(铬)-extens
let mywindow = window.open("utl", "title", "resizable=yes,width=600,height=400,toolbar=no,titlebar=no,menubar=no,scrollbars=yes");
我想访问窗口的当前URL,我已尝试:
- 窗口位置
- window.document.url
const orgURL = '<URL>';
chrome.tabs.create({url: orgURL}, createdTab => {
function updateListener(tabId, tab) => {
if (tabId == createdTab.id && tab.url !== orgURL) {
const redirectURL = tab.url;
// Do something with the redirect URL
chrome.tabs.remove(tabId); // Close the tab.
chrome.tabs.onUpdated.removeListener(updateListener);
}
}
chrome.tabs.onUpdated.addListener(updateListener);
});
您可以使用API执行此操作,以下是一个示例:
const orgURL = '<URL>';
chrome.tabs.create({url: orgURL}, createdTab => {
function updateListener(tabId, tab) => {
if (tabId == createdTab.id && tab.url !== orgURL) {
const redirectURL = tab.url;
// Do something with the redirect URL
chrome.tabs.remove(tabId); // Close the tab.
chrome.tabs.onUpdated.removeListener(updateListener);
}
}
chrome.tabs.onUpdated.addListener(updateListener);
});
我用
chrome.windows
API尝试了这一点,但窗口/选项卡的URL没有更新,因此URL属性没有更改。这是预期的吗?如何从窗口获取当前URL?@SanketDG我不知道为什么,您可能正在重定向(URL更改后)后添加更新侦听器(chrome.tabs.onUpdated.addListener
)。要获取选项卡的URL,您可以使用以下命令:chrome.windows.create({URL:..},win=>console.log(win.tabs[0].URL))
,基本上,创建新窗口后,访问第一个选项卡(win.tabs[0]
)并检查其url
属性。@SanketDG我已经编辑了我的问题,使用chrome.windows
API添加了一个示例。我用chrome.windows
API尝试了这一点,但窗口/选项卡的url没有更新,因此url属性没有更改。这是预期的吗?如何从窗口获取当前URL?@SanketDG我不知道为什么,您可能正在重定向(URL更改后)后添加更新侦听器(chrome.tabs.onUpdated.addListener
)。要获取选项卡的URL,您可以使用以下内容:chrome.windows.create({URL:..},win=>console.log(win.tabs[0.URL))
,基本上,在创建新窗口后,访问第一个选项卡(win.tabs[0]
),并检查其URL
属性。@SanketDG我已经编辑了我的问题,以使用chrome.windows
API添加一个示例。