|
| 1 | +## MODIFIED Requirements |
| 2 | +### Requirement: The background service SHALL execute custom JavaScript payloads securely |
| 3 | +The background service SHALL keep automatic Custom JS/CSS page-load injection on the legacy MAIN-world execution path, and it SHALL provide a background-backed fetch helper only to manual, user-triggered Run Code snippets executed through the user-scripts path. |
| 4 | + |
| 5 | +#### Scenario: Execute JS on behalf of the content script |
| 6 | +- **GIVEN** the content script requests `{ type: 'INJECT_CUSTOM_JS', ruleId, code }`, |
| 7 | +- **THEN** the background service worker MUST verify `sender.tab.id` exists and `code` is non-empty, call `chrome.scripting.executeScript()` with the MAIN-world eval path, and reply `{ success: true }`, |
| 8 | +- **AND** host-page CSP MAY block this automatic custom-code path on pages that disallow eval, so stored rules do not gain new page-load execution privileges unexpectedly, |
| 9 | +- **AND** errors (invalid tab, injection failure, runtime exceptions) MUST be caught and responded to with `{ success: false, error }` so the caller can log and avoid retry storms. |
| 10 | + |
| 11 | +#### Scenario: Manual Run Code receives a background-backed fetch helper |
| 12 | +- **GIVEN** the user manually runs a "Run Code in page" snippet, |
| 13 | +- **WHEN** the background builds the user-script wrapper, |
| 14 | +- **THEN** it MUST expose a fetch-like helper to the snippet that sends the request through the extension background instead of the page origin, |
| 15 | +- **AND** the helper MUST only be available to manual Run Code snippets, not automatic page-load Custom JS/CSS rules. |
| 16 | + |
| 17 | +#### Scenario: Background-backed fetch executes with explicit validation |
| 18 | +- **GIVEN** a manual Run Code snippet calls the helper with a URL and optional init object, |
| 19 | +- **WHEN** the request reaches the background through the user-script messaging channel, |
| 20 | +- **THEN** the background MUST validate that the URL is absolute and that only supported request fields are honored, |
| 21 | +- **AND** it MUST perform the network request from the extension origin so matching host permissions can bypass page-origin CORS limits, |
| 22 | +- **AND** it MUST return a serializable response object that includes `ok`, `status`, `statusText`, `url`, `redirected`, `headers`, plus body readers that allow the snippet to call `text()` or `json()` on the returned value, |
| 23 | +- **AND** request failures or response-body parse failures MUST reject the snippet call with a descriptive error instead of silently returning an unusable result. |
0 commit comments