I'm trying to update my chrome extension from V2 to V3.
The part that doesn't seem to work right now is where I modify incoming headers
V2:
function modifyHeadersForUrls(urls: string[]) {
chrome.webRequest.onHeadersReceived.addListener((details) => {
details.responseHeaders.testHeader = 'barfoo';
return details.responseHeaders;
}, { urls }, ['blocking', 'responseHeaders']);
}
For this code to work in V2 I needed to add 2 permission to my manifest:
"webRequest",
"webRequestBlocking"
In V3 I get the impression that I should switch to
"declarativeNetRequest",
"declarativeNetRequestWithHostAccess",
"declarativeNetRequestFeedback"
Or at least to one of them. I think I need declarativeNetRequestWithHostAccess
but I'm not sure what I should do here. It is needed to declare a declarative_net_request block in the manifest, but in my case the urls are dynamic.
Normally I can figure it out with the docs and a couple of examples, but the problem is, is that I can't find any example using declarativeNetRequestWithHostAccess.
Any help would be appreciated!
Based on the example given below I was able to produce the following code
const urls = ['localhost:8000'];
chrome.declarativeNetRequest.updateDynamicRules({
// chrome.declarativeNetRequest.updateSessionRules({
// removeRuleIds: ....,
addRules: [
{
id: 1,
priority: 1,
condition: {
initiatorDomains: urls,
resourceTypes: ['main_frame']
},
action: {
type: 'modifyHeaders',
responseHeaders: [
{ header: 'Content-Security-Policy', operation: 'remove' },
{ header: 'Content-Security-Policy-Report-Only', operation: 'remove' },
],
}
}
]
});
In my case I need to remove the CSP headers for a given url. What the above code is suppose to do, is to remove these headers for any url from localhost:8000? Unfortunate, it didn't work. Any ideas what might be wrong in my code?
Also, it is unclear what exactly updateSessionRules does? What is a session in terms of the background service worker?
Thanks alot!
Related
I'm writing Chrome extension with the manifest v3. I use the rule of declarativeNetRequest to block request like this example below:
const adblockRuleID = 2; // give any id to indetify the rule but must be greater than 1
chrome.declarativeNetRequest.updateDynamicRules(
{
addRules: [
{
action: {
type: "block",
},
condition: {
urlFilter: "adservice.google.com/adsid/google/ui", // block URLs that starts with this
domains: ["example.com"], // on this domain
},
id: adblockRuleID,
priority: 1,
},
],
removeRuleIds: [adblockRuleID], // this removes old rule if any
},
() => {
console.log("block rule added");
}
);
That works !
But I want to count number of requests blocked to display on extension icon like AdBlock.
Do you know how to get this number dynamically ? I don't see that in the documentation. Thank you
I am using Indicative in my project to validate my controller, but, Indicative don't have a "Unique" rule in "Validation Rules", but the framework Adonis have a rule call "unique" that does exactly what i need.
My project is made in Adonis, but i prefer to use "Indicative" and not "Validator" in Adonis, because i think is more easy and beautiful write the code direct in the Controller
code: 'required|string|max:255',
description: 'required|string|max:255|unique:tabela',
authors: 'string|max:255',
status: 'boolean',
user_id: 'integer',
created_at: [
importValidate.validations.dateFormat(['YYYY-MM-DD HH:mm:ss'])
],
updated_at: [
importValidate.validations.dateFormat(['YYYY-MM-DD HH:mm:ss'])
]
}
In the example above, I need the "code" to be "Unique" and return an error message and a response status. How can I do this?
The unique method of Validator will automatically search in the database. I don't think it's possible to do it with Indicative
I propose this solution (in your controller):
const { validate } = use('Validator')
...
const rules = {
code: 'unique:<table_name>,<field_name>'
}
const messages = {
'code.unique': '...'
}
const validation = await validate({ code: ... }, rules, messages)
if (validation.fails()) {
...
}
To use this command it is necessary to use Validator. I don't think there's an equivalent with Indicative
I currently have an app running on actions on google using API.AI. I have modified all the response members to be camelCase as suggested and got it working. Now I am trying to return a basic card, but I can not figure out how to properly return it.
Does anyone have the most basic JSON response, returning a basic card to the Google assistant?
currently, the most basic v2 API response I can have is the following:
{
speech: "",
displayText: "",
data: {
google: {
expectUserResponse: true,
isSsml: true,
permissionsRequest: null
}
},
contextOut: [ ],
source: "webhook"
}
I have some Gists showing the JSON responses here.
Right now, it includes Lists, Basic Card and Carousel, but I will add Transactions hopefully soon. Hope it might help somehow
This is what I use for Voice Tic Tac Toe
"google": {
"expect_user_response": true,
"rich_response": {
"items": [
{
"simple_response": {
"text_to_speech": "Your move was top. I moved left"
}
},
{
"basic_card": {
"image": {
"url": "https://server/010200000.png",
"accessibility_text": "Tic Tac Toe game board"
}
}
}
]
}
}
I ran the facts about google action and looked at the fulfillment JSON output to learn how to do this.
https://github.com/actions-on-google/apiai-facts-about-google-nodejs
Note that all responses must include at least one, and no more than two, simple_response items.
Folks,
I am having difficult time understanding the docs http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/frames.html
I need to grab all the running instances with the following tags assigned to them:
project=foo
environment=production
The following does not seem to work.
var params = {
DryRun: false,
Filters: [
{
Name: 'instance-state-name',
Values: [
'running'
],
},
{
Name: 'tag:key=value',
Values: [
'foo',
'production'
],
},
]
};
ec2.describeInstances(params, function (err, data) {
...
If your tag's key is 'foo' and its value is 'production', you should change your code to the following. The Name is in the 'tag:key' format, and the Values are the data you are looking for that correspond to that key.
{
Name: 'tag:foo',
Values: [
'production'
],
},
This is slightly related, and may help anyone who found there way here like I did.
I was trying check if an Instance with a tag Name=myInstance, was running in my aws account.
It's pretty difficult to check existence of resources in aws, but clairestreb's answer led me to the work around for this case.
I've begun developing a library of other such work arounds, and with it you can now do this:
Find Running Instance with tag Name=myInstance
var ex = require('aws-existence')
var ec2 = ex.ec2({region: 'us-west-2'})
ec2.doesInstanceExist('myInstance', 'running')
.then(doSomething)
function doSomething (exists) {
if (exists) {
// stop it?
} else {
// start it?
}
}
So that's doesInstanceExist(identifier, instanceState) where the identifier is a name tag, or an InstanceId. And state is optionally any one of the instance-state-name values. If you omit the state, it will tell you if an instance in any of the states exists.
You can find the library here:
nackjicholson/aws-existence
My basic question is how do you setup Firebase rules to only allow access certain leaf nodes from their parent?
Lets say I have data that looks like this:
root: {
posts: {
post1: {
user: "foo",
post: "this is a post",
restricted: false
},
post2: {
user: "bar",
post: "this is another post",
restricted: true
},
post3: {
user: "bar",
post: "this is my final post",
restricted: false
}
}
}
I want to $bind to the posts node and get all the posts which that user is allowed to get. I might want the admin to access all of the posts but non-admins to only be able to access post1 and post3.
Note: I'm using angularFire's $bind to synchronize nodes.
I don't believe this is possible but I would like to be able to set up my rules kinda like this:
{
"rules": {
"posts": {
".read": "auth.admin || $post.hasChild('restricted').val() !== true",
"$post": {
}
}
}
}
How are other users accomplishing this? Thanks.
You can use the data.hasChild expression to achieve this:
{
"rules": {
"posts": {
".read": "auth.admin || data.hasChild('restricted').val() !== true"
}
}
}
However, this is not the recommended approach and won't work in practice. Security rules are not a good fit for filtering data based on access - you'll see permission denied errors in the console because angularFire will try to read all the posts from /blog and it will fail.
Instead, each user should know which posts they have access to and only fetch those directly. You can use push() (or $add in angularFire) to generate random post IDs and set the security rules such that you can access the data if you know the post ID, for example.
I believe the canonical way to do that is to place a rule directly on the element to be read, not on the collection.
{
"rules": {
"posts": {
"$post": {
".read": "auth.admin || data.hasChild('restricted').val() !== true"
}
}
}
}