我试图使用以下代码来区分vSphere登录页面和工作页面的URL。
vSphere登录页面的URL如下所示:
https://0.0.0.0/vsphere-client/?csp
登录后的工作页面如下所示:
https://0.0.0.0/vsphere-client/?csp#extensionId%3Dvsphere.core.controlcenter.shortcutsView
因此,我想在登录页面显示我的扩展图标,而不是在工作页面显示。
我尝试了以下代码,但是它没有工作,我的意思是图标在这两个URL上是可用的:
chrome.runtime.onInstalled.addListener(function () {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function () {
chrome.declarativeContent.onPageChanged.addRules([
{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { querySuffix: 'csp' },
})
],
actions: [new chrome.declarativeContent.ShowPageAction()]
}
]);
});
});关于这一行:
pageUrl: { querySuffix: 'csp' },
我还通过$尝试了到URL末尾的正则表达式,但没有工作:
pageUrl: { urlMatches: 'csp$' },
我知道片段标识符#后的部分不会在pageUrl: { xxx },中进行处理,请参考https://developer.chrome.com/extensions/events#property-UrlFilter-hostEquals。
上面写着:
如果URL (没有片段标识符)匹配指定的正则表达式,则匹配。如果端口号与默认端口号匹配,则从URL中删除端口号。正则表达式使用RE2语法。
因此,也许pageUrl将登录页面和工作页面视为相同的URL。
这里有办法识别这两个网址吗?
谢谢!
https://stackoverflow.com/questions/45932792
复制相似问题