I create a contextMenu with contexts is ['all'] and documentUrlPatterns is [':///*.pdf'].It works well in pages.But it always appear in browser_action even throught the page url's suffix isn't '.pdf'. I want this contextMenu don't appear in browser_action when page url don't endsWith '.pdf'. How to resolve this problem?
contextMenu create code:
chrome.contextMenus.create({
id: 'PDF_TOP',
title: 'PDF编辑/打印/转换',
contexts: ['all'],
documentUrlPatterns: ['*://*/*.pdf']
})
contextMenu in page behavior: enter image description here enter image description here
contextMenu in browser_action beahvior: enter image description here enter image description here
You can listen to chrome.tabs.onActivated and add or remove the context menu based on if the current page is PDF. It won't show in browser_action.
You can refer to the code below: