Commit 9ee91a20 authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Extensions] Restrict tabs.executeScript() and insertCSS() to MV2

tabs.executeScript() and tabs.insertCSS() are being replaced by
methods on the new chrome.scripting API. Restrict the old features to
MV2.

Bug: 987838
Change-Id: I3bf76ac9cf4821765531d08379bfb8eb21bf92e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2535996Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827126}
parent ffecec38
......@@ -59,7 +59,7 @@ IN_PROC_BROWSER_TEST_F(ManifestV3BrowserTest, ProgrammaticScriptInjection) {
"background": {
"service_worker": "worker.js"
},
"permissions": ["tabs"],
"permissions": ["tabs", "scripting"],
"host_permissions": ["*://example.com/*"]
})";
constexpr char kWorker[] =
......@@ -70,15 +70,26 @@ IN_PROC_BROWSER_TEST_F(ManifestV3BrowserTest, ProgrammaticScriptInjection) {
let url = new URL(tab.url);
if (url.hostname != 'example.com')
return;
// The tabs API equivalents of script injection are removed in MV3.
chrome.test.assertEq(undefined, chrome.tabs.executeScript);
chrome.test.assertEq(undefined, chrome.tabs.insertCSS);
chrome.tabs.onUpdated.removeListener(listener);
chrome.tabs.executeScript(
tabId,
{code: "document.title = 'My New Title'; document.title;"},
function injectedFunction() {
document.title = 'My New Title';
return document.title;
}
chrome.scripting.executeScript(
{
target: {tabId: tabId},
function: injectedFunction,
},
(results) => {
chrome.test.assertNoLastError();
chrome.test.assertTrue(!!results);
chrome.test.assertEq(1, results.length);
chrome.test.assertEq('My New Title', results[0]);
chrome.test.assertEq('My New Title', results[0].result);
chrome.test.notifyPass();
});
});
......
......@@ -799,12 +799,18 @@
],
"platforms": ["chromeos"]
}],
"tabs.executeScript": {
"max_manifest_version": 2
},
"tabs.getAllInWindow": {
"max_manifest_version": 2
},
"tabs.getSelected": {
"max_manifest_version": 2
},
"tabs.insertCSS": {
"max_manifest_version": 2
},
"tabs.onActiveChanged": {
"max_manifest_version": 2
},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment