当我更改YouTube页面上的标签标题并刷新页面时,该标题会被默认的视频标题覆盖。我使用chrome.tabs.onUpdated
来确保在更改标题之前页面已完全加载,但是在刷新页面时,在将新标题替换为原始页面标题之前,我可以短暂地看到它。这也发生在Twitch上,所以也许与视频网站有关?
/* keeps the tab's title and color persistent tab refresh */
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab)
{
/* once content script has finished loading in the new tab, send a message with the tab's title to the content script; */
if (changeInfo.status === "complete")
{
// tab's title was changed
if (saveTitle[tabId] != null)
{
// tab's title sent to content script
chrome.tabs.sendMessage(tabId, {title: saveTitle[tabId]}, function(response){});
}
}
})
/* sets the title of the tab */
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse)
{
if (request.title)
{
document.title = request.title;
}
})