Files
webextensions-examples/dnr-redirect-url/redirectTarget.html
Rob Wu 06330a69c2 Add declarativeNetRequest (DNR) + MV3 examples (#526)
These examples are designed to be cross-browser compatible.
In particular, these extensions do not use `background` because there is
currently no single manifest that can support both Firefox and Chrome,
due to the lack of event page support in Chrome, and the lack of service
worker support in Firefox.

Three examples demonstrating the use of the declarativeNetRequest API:
- dnr-block-only: One minimal example demonstrating the use of static
  DNR rules to block requests.
- dnr-redirect-url: One minimal example demonstrating the use of static
  DNR rules to redirect requests.
- dnr-dynamic-with-options: A generic example demonstrating how host
  permissions can be requested and free forms to input DNR rules.
2023-05-17 18:13:55 +02:00

39 lines
1.3 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width"> <!-- mobile-friendly -->
<title>redirectTarget.html</title>
</head>
<body>
This page is the redirect target of requests matching rule 1 from <a href="redirect-rules.json">redirect-rules.json</a>.<br>
The pattern <code>||example.com/|</code> means: (sub)domain of <code>example.com</code>, with path "/" and nothing else before the end of the URL.
<pre>
{
"id": 1,
"priority": 4,
"condition": {
"urlFilter": "||example.com/|",
"resourceTypes": ["main_frame"]
},
"action": {
"type": "redirect",
"redirect": {
"extensionPath": "/redirectTarget.html"
}
}
},
</pre>
For the redirect to have succeeded, three conditions must be met:
<ul>
<li> The declarativeNetRequest (DNR) rule should match the request.</li>
<li> The extension must declare the pre-redirect URL in <code>host_permissions</code> (in manifest.json) and the user should grant the permission.</li>
<li> The extension path in <code>extensionPath</code> must be declared in <code>web_accessible_resources</code> (in manifest.json), and the pre-redirect URL should match the pattern in <code>matches</code>.</li>
</ul>
See <a href="popup.html">popup.html</a> for the permissions UI and examples.
</body>
</html>