Skip to content

Commit

Permalink
Clarify again
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob--W committed May 17, 2023
1 parent 017d5c0 commit ba07083
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
16 changes: 13 additions & 3 deletions dnr-block-only/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ This example shows how to:
- use the "resourceTypes" and "excludedResourceTypes" conditions of a declarativeNetRequest rule.
- block network requests without host permissions using the "declarativeNetRequest" permission, which triggers the "Block content on any page" permission warning at install time.

This is the only cross-browser way to block network requests (at least in
Firefox, Chrome, and Safari). While the extension uses `"manifest_version": 3`,
it also works identically with `"manifest_version": 2`.
This example is the only cross-browser way to block network requests (at least
in Firefox, Chrome, and Safari). The webRequest API is an alternative way to
implement this functionality, but is only available in Firefox (MV2 and MV3)
and in Chrome (MV2 only). Safari does not support the webRequest API.

## Comparison with Manifest Version 2

While this example uses `"manifest_version": 3`, the functionality is not
specific to Manifest Version 3.

To create a MV2 version of the extension, modify `manifest.json` as follows:

- Set `manifest_version` to 2.
4 changes: 2 additions & 2 deletions dnr-dynamic-with-options/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ How to retrieve and dynamically register declarativeNetRequest rules, using:

- `declarativeNetRequest.getDynamicRules` and
`declarativeNetRequest.updateDynamicRules` to manage DNR rules that persist
across extension restarts. When loaded non-temporarily, these rules also
persist across browser restarts.
across extension restarts. These rules also persist across browser restarts,
unless the extension is loaded temporarily or unloaded.
- `declarativeNetRequest.getSessionRules` and
`declarativeNetRequest.updateSessionRules` to manage DNR rules that are
session-scoped, that is, cleared when an extension unloads or the browser quits.
Expand Down
16 changes: 11 additions & 5 deletions dnr-redirect-url/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ This extension redirects requests from the example.com domain to other destinati

- example.com/ to `redirectTarget.html` packaged with the extension.
- example.com/ew to extensionworkshop.com
- https://www.example.com/[anything] to the same URL but the domain changed to example.com and `?redirected_from_www=1` appended to the URL.
- URLs matching regular expression `^https?://([^?]+)$` to the same URL but with scheme changed to https and `?redirected_by_regex` appended.
- https://www.example.com/[anything] to the same URL but the domain changed to
example.com and `?redirected_from_www=1` appended to the URL.
- example.com URLs matching regular expression `^https?://([^?]+)$` to the same URL but with the
scheme set to `https:` (if it was `http:` before), and with `?redirected_by_regex` appended.

Redirecting requires host permissions for the pre-redirect URLs. Manifest V3 extensions do not have access to these by default.
Redirecting requires host permissions for the pre-redirect URLs. In Firefox
(and Safari), Manifest V3 extensions do not have access to these by default.
The permission to these can be granted from the extension action popup.

# What it shows
Expand All @@ -27,9 +30,12 @@ This extension shows how to:
- redirect requests to another website.
- redirect requests to a page packaged in the extension and listed in `web_accessible_resources`.
- redirect requests and transform the URL with the `transform` and `queryTransform` options.
- redirect a URL matching a regular expression in `regexFilter` and generate a redirect target in `regexSubstitution`.
- redirect a URL matching a regular expression in `regexFilter` to `regexSubstitution`.
- use "priority" to specify the rule to action when multiple rule conditions are matched to a request.
- specify the "declarativeNetRequestWithHostAccess" permission in the manifest.json, which does not trigger a permission warning. (Compared to the"declarativeNetRequest" permission, which has the same effect but displays the "Block content on any page" permission warning.)
- specify the "declarativeNetRequestWithHostAccess" permission in the
manifest.json, which does not trigger a permission warning. (Compared to
the "declarativeNetRequest" permission, which has the same effect but displays
the "Block content on any page" permission warning.)

## Comparison with Manifest Version 2

Expand Down

0 comments on commit ba07083

Please sign in to comment.