I have a chrome extension to block YouTube as a whole, but it's only blocking some requests. For example, all embedded videos are blocked, but when I go to https://www.youtube.com or https://www.youtube.com/watch?v=dQw4w9WgXcQ it'll block only some elements.
https://www.youtube.com as far as I can tell loads everything except for elements loaded due to user navigation--for example, the collapsed hamburger menu doesn't load when clicked.
manifest.json:
{
"manifest_version": 2,
"name": "Test",
"version": "0.0.1",
"permissions": [
"*://*.youtube.com/*",
"declarativeNetRequest"
],
"declarative_net_request": {
"rule_resources": [
{
"id": "1",
"enabled": true,
"path": "rules.json"
}
]
}
}
rules.json:
[
{
"id": 3,
"priority": 1,
"action": {
"type": "block"
},
"condition": {
"urlFilter": "youtube.com"
}
}
]
Related
I'm trying to block a website with a chrome extension that uses the new declarative net request API for Manifest V3, but it isn't working. I have added the permission in the manifest and made sure to add the priority, id, action and conditions, but it still doesn't do anything at all. I am trying to modify the response headers. Here is the applicable part of my manifest.
Manifest.json
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": ["https://mail.google.com/*"],
"css": ["base.css"],
"js": [
"jquery-1.10.2.js",
"inboxsdk.js",
"loader.js"
]
},
{
"matches": [
"https://mail.google.com/*",
"https://localhost:1234/*",
"http://localhost:1234/*",
"http://localhost:5000/*"
],
"js": [
"version.js"
]
}
],
"host_permissions": [
"*://*.google.com/*",
"*://*.googleusercontent.com/*",
"https://localhost:1234/*",
"http://localhost:1234/*",
"http://localhost:5000/*"
],
"web_accessible_resources": [{
"resources": [
"icon128.png",
"logo-pink.svg",
"logo-white.png",
"logo.png"
],
"matches": [
"https://mail.google.com/*",
"https://localhost:1234/*",
"http://localhost:1234/*",
"http://localhost:5000/*"
]
}],
"declarative_net_request": {
"rule_resources": [{
"id": "ruleset_1",
"enabled": true,
"path": "rules.json"
}]
},
"permissions": [
"scripting",
"declarativeNetRequest",
"declarativeNetRequestWithHostAccess",
"declarativeNetRequestFeedback"
],
"manifest_version": 3
}
rules.json
[
{
"id": 1,
"priority": 1,
"action": {
"type": "modifyHeaders",
"responseHeaders": [
{
"header": "script-src",
"operation": "set",
"value": "script-src https://localhost:7000"
}
]
},
"condition": {
"regexFilter": "/content-security-policy/i",
"resourceTypes": [
"main_frame",
"sub_frame",
"script",
"object",
"xmlhttprequest",
"csp_report"
]
}
}
]
Is there any Idea how to test whether the headers are being modified or not
There are several problems.
regexFilter doesn't support JS RegExp literal syntax.
Solution: Remove / and the i flag.
regexFilter is for the URL of the request, not for a header name. Currently there's no way to match requests by checking a header.
Solution: Remove regexFilter or use a valid expression for the URL or use other types of conditions like urlFilter or requestDomains, see the documentation.
"header": "script-src" should be "header": "content-security-policy"
Example:
[{
"id": 1,
"action": {
"type": "modifyHeaders",
"responseHeaders": [{
"header": "content-security-policy",
"operation": "set",
"value": "script-src https://localhost:7000"
}]
},
"condition": {
"requestDomains": ["example.com"],
"resourceTypes": ["main_frame", "sub_frame"]
}
}]
P.S. To change script-src it's sufficient to process main_frame and sub_frame types.
In Manifest V3 Chrome's team introduced declarativeNetRequest. We can't seem to make sure those rules are applied only to sites of a certain domain:
[
{
"id": 1,
"priority": 1,
"action": {
"type": "block"
},
"condition": {
"urlFilter": "main.js",
"resourceTypes": ["script"]
}
}
]
We defined, those rules are fired in every webpage you visit. Can we filter the rules by this host of rule and not by the destination of the script? We couldn't find indication for it in the docs or the examples.
Needless to say any off-docs improvisation in the manifest.json failed to leave a mark. For instance:
{
...
"declarative_net_request": {
"matches": ["https://SUB_DOMAIN_NAME.domain.com/*"], <====== this
"rule_resources": [
{
"id": "ruleset_1",
"enabled": true,
"path": "rules.json"
}
]
}
}
I'm trying to redirect a URL using the Chrome declarativeWebRequest API but it does not work.
The match pattern in the "permissions" key worked with Manifest V2 but it's now throwing a Permission '*://www.youtube.com/*' is unknown or URL pattern is malformed error in V3.
manifest.json:
{
"manifest_version": 3,
"name": "Redirect Test",
"version": "0.0.1",
"permissions": [
"declarativeNetRequest",
"*://www.youtube.com/*"
],
"host_permissions": [
"*://www.youtube.com/*"
],
"declarative_net_request": {
"rule_resources": [
{
"id": "1",
"enabled": true,
"path": "rules.json"
}
]
}
}
rules.json:
[
{
"id": 1,
"priority": 1,
"action": {
"type": "redirect",
"redirect": {"url": "https://www.google.com"}
},
"condition": {
"urlFilter": "*://www.youtube.com/*",
"resourceTypes": [
"main_frame"
]
}
}
]
I'm using Chrome 88.0.4324.104
The manifest documentation for declarative net requests at the time of posting isn't exactly accurate.
This is the
Permissions key in manifest.json from the documentation:
"permissions": [
"declarativeNetRequest",
"declarativeNetRequestFeedback",
"*://example.com/*"
],
However, the site should be specified in just host_permissions instead:
"host_permissions": [
"*://example.com/*"
],
It should be noted that this explicit declaration is only necessary if action.redirect is specified like in this example:
{
"id": 1,
"priority": 3,
"action": {
"type": "redirect",
"redirect": {
"regexSubstitution": "www.youtube.com/embed/"
}
},
"condition": {
"regexFilter": "(www\\.youtube\\.com\/watch\\?v=)",
"resourceTypes": [
"main_frame"
]
}
}
I am trying to develop a custom app with a tab I have installed the app successfully but when i open the tab it states connection refused to the website from where the content has to be displayed. I am a newbie to Microsoft team app. Below is the manifest.json.
{
"$schema": "https://developer.microsoft.com/en-us/json-
schemas/teams/v1.7/MicrosoftTeams.schema.json",
"manifestVersion": "1.7",
"version": "1.0.0",
"isFullScreen": true,
"id": "e23cbae9-8598-4b64-bd35-d8dcd9552372",
"packageName": "com.uber",
"developer": {
"name": "Mphasis",
"websiteUrl": "https://www.mphasis.com",
"privacyUrl": "https://www.mphasis.com",
"termsOfUseUrl": "https://www.mphasis.com"
},
"icons": {
"color": "color.png",
"outline": "outline.png"
},
"name": {
"short": "uberApp",
"full": "Uber App1"
},
"description": {
"short": "testing app",
"full": "uber test app"
},
"accentColor": "#FFFFFF",
"staticTabs": [
{
"entityId": "12346",
"name": "mytab",
"contentUrl": "https://capgemini.com/in-en/careers/",
"scopes": [
"personal"
]
}
],
"permissions": [
"identity",
"messageTeamMembers"
],
"validDomains": [
"capgemini.com"
]
}'''
{
"manifestVersion": 1,
"id": "build-release-task",
"name": "",
"version": "1.1.9",
"publisher": " ",
"targets": [
{
"id": "Microsoft.VisualStudio.Services"
}
],
"description": "",
"categories": [
"Azure Pipelines"
],
"icons": {
"default": "images/extension-icon.png"
},
"files": [
{
"path": "buildAndReleaseTask"
},
{
"path": "images",
"addressable": true
}
],
"contributions": [
{
"id": "custom-build-release-task",
"type": "ms.vss-distributed-task.task",
"targets": [
"ms.vss-distributed-task.tasks"
],
"properties": {
"name": "buildAndReleaseTask",
"icon": "images/extension-icon.png"
}
}
]
}
You should put the icon file also in the task folder (where the .ts/.ps1 files).