I've tried to look this up but nothing really helped me. I have created a chrome extension and I need to check a cookie value from a given site.
this is my manifest file:
{
"name": "MyExtension",
"version": "1.0",
"description": "First version of My Extension",
"browser_action": {
"default_icon": "bmark.ico",
"popup": "extension.html"
},
"permissions": [
"tabs",
"cookies",
"http://www.example.com"
]
}
in my html file this is my code:
chrome.cookies.get({ url: "http://www.example.com", name: 'user' }, function (cookie) {
alert(cookie != null);
});
the result is false (my cookie is null). according to the google API that means that there isn't such a cookie BUT.... when I look in chrome to see my cookies (chrome://settings/cookies) I can see the cookie I was looking for. Any one knows why the chrome.cookies.get function doesn't work for me?
OK, i figured it out. i was missing the following permissions in the manifest.json file:
"http://*/*",
"https://*/*"
apparently they are needed to access the cookies.
Related
Regarding getting Cookie from my chrome extension, it works perfectly when the chrome setting "On all sites".
But when I set "On [current site]" or "When you click the extension" in chrome extension setting, I couldn't get any cookies..
https://support.google.com/chrome_webstore/answer/2664769?hl=en
"Let extensions read and change site data"
※ When I keep opening the url where I want to get the cookie, it's success...
I tried to look for the solution, but there were nothing.
{
"name": "myapp",
"version": "1.0.0",
"description": "desc",
"permissions": [
"contextMenus",
"tabs",
"cookies"
],
"host_permissions": [ "https://wanna-get-cookie-this-domain.com/*" ],
"background": { "service_worker": "service_worker.js" },
"content_scripts": [
{
"js": ["scripts/contentscript.js"],
"matches": ["https://*/*"]
}
],
"manifest_version": 3
}
service_woeker.js
chrome.contextMenus.create({
id: "testapp",
title: "title",
contexts: ["all"],
type: "normal"
});
chrome.contextMenus.onClicked.addListener(function(info, tab) {
chrome.windows.create({
url: `/views/popup.html`,
type: 'popup',
focused: true,
width: 395, height: 230
});
})
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.type == "getCookie") {
chrome.cookies.getAll({}, function(cookies) {
console.log(cookies);
// "On all sites" works.
// "On [current site]" or "When you click the extension" doesn't work
// even after I clicked and enabled the extension.
});
}
return true;
});
views/popup.html
<html>
...
<script src="/scripts/popup.js"></script>
</html>
scripts/popup.js
// After user clicked, below code
chrome.runtime.sendMessage({type: 'getCookie'}));
Thanks,
This is a bug:
the cookies API is only checking the host permissions, and not checking tab-specific permissions, since the request isn't associated with a tab.
Until it's fixed you'll have add the host permissions for all sites in manifest.json:
"host_permissions": ["<all_urls>"]
Note that your content script already runs on all https sites (why not all sites though?), which means that your extension is already requesting the "broad host permission" under the hood, so adding the same pattern to host_permissions doesn't increase the internal permissions of your extension, it's more of a cosmetic requirement to allow the use of chrome API in the non-content scripts like the background script.
I have built a Query API for AWS DynamoDB through the AWS API Gateway. Here's a sample response I get after a successful query :
{
"Count":2,
"Items":[
{
"StoreID":{
"S":"STR100"
},
"OrderID":{
"S":"1019"
},
"Date":{
"S":"22nd May"
}
},
{
"StoreID":{
"S":"STR100"
},
"OrderID":{
"S":"1020"
},
"Date":{
"S":"22nd May"
}
}
],
"ScannedCount":2
}
What I want to do is, when the response reaches the API Gateway (before it reaches the user) I want to modify it. I would like to do the following changes to the coming response -
Firstly, remove the ScannedCount value. (keep the Count one)
Then remove all the "S": "<value>" : value should appear directly, like "StoreID": "STR100"
So, the modified response should look like :
{
"Count":2,
"Items":[
{
"StoreID":"STR100",
"OrderID":"1019",
"Date":"22nd May"
},
{
"StoreID":"STR100",
"OrderID":"1020",
"Date":"22nd May"
}
]
}
I hope you understand my problem - Any help is appreciated!
Thanks! :)
Following the blog article Using Amazon API Gateway as a proxy for DynamoDB
Navigate to Integration Response and expand the 200 response code by choosing the arrow on the left. In the 200 response, expand the Mapping Templates section. In Content-Type choose application/json then choose the pencil icon next to Output Passthrough.
And for your example the template should look like this:
#set($inputRoot = $input.path('$'))
{
"Count": "$inputRoot.Count",
"Items": [
#foreach($elem in $inputRoot.Items) {
"StoreID": "$elem.StoreID.S",
"OrderID": "$elem.OrderID.S",
"Date": "$elem.Date.S"
}#if($foreach.hasNext),#end
#end
]
}
I can't find a way to do it in the docs, and I have looked into as well here on Stack Overflow. I want to show a user a limited view of my JSON response from the API, before they have logged in.
So, as an example, I have a e-book I want to sell online. I want them only to see a preview link (epubFile.notAuthoried) of the book when not logged in, and the full link (epubFile.authorized) of the book when logged in. Both links are represented in the same table.
[
{
"title": "string",
"subTitle": "string",
"isPublished": true,
"publicationDate": "2017-10-20T11:07:31.258Z",
"epubFile": {
"notAuthorized": "filename-noauth.epub"
"authorized": "filename-auth.epub"
}
"id": "string",
"createdOn": "2017-10-20T11:07:31.258Z",
"updatedOn": "2017-10-20T11:07:31.258Z"
}
]
Is it even possible to filter out fields from the API Endpoints in loopback?
Or do I need to build a new custom API Endpoint?
first you'll have to set the permissions on your find and findById methods to $everyone so that both authorized and unauthorized users can call them
{
"name": "eBook",
"base": "PersistedModel",
[...]
"acls": [
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property":["find", "findById]
]
}
Next, you'll have to hook into the remote methods and modify the response depending on if hte user is logged in or not
const previewProperites = ['title', 'subTitle', etc...]
Ebook.afterRemote('find', (ctx, ebooks, next) => {
// pseudo code
if(!ctx.options.accessToken){
// no user logged in, only keep preview properties
ebooks.forEach(book => {
// get the properties of the book
var eBookProperties = Object.keys(book.__data);
eBookProperties.forEach(bookProp =>{
if(!previewProperties.some(pProp => pProp === bookProp)){
// ebook property not in preview list, so remove it
delete book.__data[bookProp]; // .__data is where loopback keeps its actual data
}
});
});
}
next();
}
I am attempting to submit invalid data via a POST request to a JSONAPI-based API with Ember Data 2.10.
The API responds correctly with a 422 code and this payload in the response (note that these are error objects, not a "normal" JSONAPI payload response):
{
"errors": [{
"title": "Title can't be blank",
"id": "title",
"code": "100",
"source": {
"pointer": "/data/attributes/title"
},
"status": "422"
}, {
"title": "Layout can't be blank",
"id": "layout",
"code": "100",
"source": {
"pointer": "/data/relationships/layout"
},
"status": "422"
}, {
"title": "Page type can't be blank",
"id": "page-type",
"code": "100",
"source": {
"pointer": "/data/attributes/page-type"
},
"status": "422"
}]
}
The errors seem to be loading mostly OK into the model, but I get this error in the console:
ember.debug.js:19160 Error: The adapter rejected the commit because it was invalid
at ErrorClass.EmberError (ember.debug.js:19083)
at ErrorClass.AdapterError (errors.js:23)
at ErrorClass (errors.js:49)
at Class.handleResponse (rest.js:821)
at Class.handleResponse (data-adapter-mixin.js:100)
at Class.superWrapper [as handleResponse] (ember.debug.js:24805)
at ajaxError (rest.js:1342)
at Class.hash.error (rest.js:916)
at fire (jquery.js:3305)
at Object.fireWith [as rejectWith] (jquery.js:3435)
What is causing this error? Is there something wrong in the JSON payload being returned by the server? One thing that changed recently was the introduction of a pointer to /data/relationships/layout; is Ember Data choking on that?
I may also note that submitting similar bad data via a PATCH request does not trigger this error in the console.
The main problem is that this is causing an acceptance test to fail, and I can't seem to find a way around it. It would be nice to be able to test this behavior in the application, but I'll just need to leave it commented out for now.
I've also tried this on Ember Data 2.7 before updating to 2.10 to see if that would fix it. Getting the same error with both versions.
since your app uses the default adapter, make sure JSON:API conventions are followed for building the response
Handful of guide is provided over here
I am getting the following back as a webhook (Message-Delivered Callback) but I need to get the actual content of the message that was delivered. The Message-Received Callback has a "text" field that contains this information, but this one does not.
{
"object": "page",
"entry": [{
"id": 2880130XXXX7538,
"time": 1462299418787,
"messaging": [{
"sender": {
"id": 1261XXXX3865793
},
"recipient": {
"id": 2880XXXX7977538
},
"delivery": {
"mids": ["mid.146XXXX412750:6bd62757XXXXd68848"],
"watermark": 1462XXXX12769,
"seq": 50
}
}]
}]
}
I have tried unsuccessfully to use graph api with the message id but the docs are a little unclear if this is possible (https://developers.facebook.com/docs/graph-api/reference/v2.6/message/)
The token I am using has the following permissions: read_page_mailboxes, manage_pages, pages_messaging.
Any help would be greatly appreciated!!
Add "m_" to your delivery mids, so in this case:
m_mid.146XXXX412750:6bd62757XXXXd68848
And then make a facebook-graph-api request using that as the "message-id" in the URL. Use fields=message to get the message text.
Reference:
https://developers.facebook.com/docs/graph-api/reference/v2.6/message/
You can try this code:
$M = $input['entry'][0]['messaging'][0]['message']['text'];
AND "$M" is what you want.
it's work! But i can't explain why