All jobs

Reduce Host Permissions in a Chrome Extension from a Linear Issue

Yes. An agent picks up the Linear issue, replaces a Chrome extension's <all_urls> host permission with activeTab, keeps every feature working and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent starts from the issue text and the repository in its own cloud sandbox, and reads the manifest before it touches code, because the host permission usually exists for one feature that could be served another way. In an extension shaped like chibat/chrome-extension-typescript-starter, public/manifest.json is Manifest V3 with permissions: ["storage"], host_permissions: ["<all_urls>"], a content_scripts entry matching <all_urls> that loads js/vendor.js and js/content_script.js, a background.service_worker at js/background.js, an action popup and an options_ui page. The content script in src/content_script.tsx only listens for a color message and sets document.body.style.backgroundColor; src/popup.tsx sends that message with chrome.tabs.sendMessage to the active tab and reads tabs[0].url to show the current URL; src/background.ts is a polling stub; src/options.tsx uses chrome.storage.sync. Nothing reads page content on every site, so the broad grant buys nothing the extension needs.

The change replaces the always-on content script with an on-demand one. The agent removes host_permissions and the content_scripts block from the manifest, adds activeTab and scripting to permissions, and rewrites changeBackground in src/popup.tsx to call chrome.scripting.executeScript with target: { tabId } and a function that sets the background colour, which runs only in the tab the user invoked the popup on. The Current URL line keeps working because activeTab grants tabs[0].url for the active tab at the moment of the click. src/content_script.tsx goes away, and with it the content_script entry in webpack/webpack.common.js and the splitChunks rule that excluded only background from the vendor chunk, so vendor.js still serves the popup and options pages.

Tests follow the repository's Jest setup in jest.config.js, which runs ts-jest over src with tsconfig.test.json. The agent adds a test beside src/__tests__/sum.ts that reads public/manifest.json and asserts there is no host_permissions key, no content_scripts key and that permissions contains activeTab and scripting and nothing broader, so a later change that reintroduces <all_urls> fails CI. It then runs npm ci, npm run build and npm test, the three steps of .github/workflows/build.yml on Node 20 and 22, and loads the built dist directory in a headless Chromium in the sandbox to confirm the popup still changes the active tab's background and that chrome://extensions lists no site access warning.

The pull request links back to the Linear issue and lists what the extension accessed before, what it accesses now, and the one behaviour that changed: the background colour is set when the user clicks the popup rather than by a script injected into every page on load. The @types/chrome version pinned in package.json is kept, and the agent notes in the description if the types it needs for chrome.scripting require a newer pin.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "A Linear issue labelled agent says: \"Chrome Web Store review flagged our <all_urls> host permission. Reduce the extension to activeTab and keep every feature working.\" Read public/manifest.json, src/popup.tsx, src/content_script.tsx, src/background.ts, src/options.tsx, webpack/webpack.common.js, jest.config.js and .github/workflows/build.yml first, and list which feature each permission and the content script serve. Remove host_permissions and the content_scripts block, add activeTab and scripting to permissions, and replace the message to the content script with chrome.scripting.executeScript on the active tab from the popup. Delete the content script and its webpack entry. Add a Jest test that reads the manifest and fails if host_permissions or content_scripts come back or permissions grows beyond storage, activeTab and scripting. Run npm ci, npm run build and npm test, load dist in a headless Chromium and check the popup still changes the active tab's background, and paste the outputs in the pull request. Open a pull request that links the issue and lists what the extension could access before and after.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request that edits public/manifest.json, rewrites the click handler in src/popup.tsx, deletes src/content_script.tsx, trims webpack/webpack.common.js, and adds a manifest test under src/__tests__. The description shows the before-and-after permissions and host_permissions blocks, the npm run build and npm test output from the sandbox, and a note from the headless Chromium check that the popup still recolours the active tab.

The repository's build workflow runs npm ci, npm run build --if-present and npm test on the pull request on both Node versions in its matrix, so the new manifest test runs in CI. A reviewer checks that permissions lists exactly storage, activeTab and scripting, that no content_scripts entry remains, that the options page still reads and writes chrome.storage.sync, and that the injected function in src/popup.tsx does not close over anything from the popup's scope, which executeScript cannot serialise. Then they merge and resubmit to the Web Store with the smaller permission set.

Run it on every Linear issue labelled agent

In the console, an automation with a linear trigger on linear.issue.labeled and the label agent starts one run per labelled issue, with the issue as its context, in the Project's repository. Changes made by an app integration never fire it, so the agent's own updates to the issue do not start new runs.

From your own server, the same run is one POST /o/{org}/sessions per issue: put the repository in resources, and add the issue's https://linear.app/<workspace>/issue/<ID> URL there too to have Rush read it through your Linear connection into the prompt. A webhook on the API key posts run.completed or run.failed when the turn finishes, with the session_url to read the result.

The use case this job follows, with its automation and trigger: Turn a Linear label into a PR.

Why run it on Rush?

Permission reductions are the kind of change that is easy to describe and easy to get half right: the manifest shrinks, and a feature that depended on the injected script quietly stops working until a user reports it. In a Rush sandbox the agent builds the extension, runs the unit tests and drives the built dist in a headless browser, and every command and its output stays in the transcript, so the pull request carries evidence that the popup still works and not only a smaller manifest.

Starting the work from a Linear label means the Web Store rejection becomes a pull request without anyone opening the repository by hand. A team with several extensions starts one run per repository, each in its own sandbox, and reviews a set of pull requests whose descriptions all list what the extension could reach before and after.

Frequently asked questions

Does activeTab let the extension read every page?

No. activeTab grants access to the one tab the user is on, only after a user gesture such as clicking the toolbar action, and only until that tab navigates. That is why the colour change moves from an always-on content script to chrome.scripting.executeScript from the popup: the script runs when the user asks, in the tab they asked about.

What if a feature really needs to run on page load?

The prompt tells the agent to list which feature each permission serves before it changes anything. If a content script must run on load for a known set of sites, the agent narrows host_permissions and the matches pattern to those origins instead of <all_urls>, and says so in the pull request rather than removing the script.

Why add scripting as well as activeTab?

activeTab grants the host access; scripting grants the chrome.scripting API that injects the function. Neither triggers a site-access warning at install time. The manifest test the agent adds pins the list to storage, activeTab and scripting, so adding anything broader later is a visible CI failure.

Does it change the webpack build?

Only by removing the content_script entry and the splitChunks exception that existed for it. The popup, options and background bundles build as before, vendor.js is still shared by the popup and options pages, and the CopyPlugin still copies public/ into dist/.

More Chrome extension jobs

More jobs like this: Turn a Linear label into a PR

Keep reading