Chrome DevTolls protocol's Fetch.enable does not cause all requests to be intercepted - chrome-devtools-protocol

I issue a message like this via DevTools Protocol to a running Google Chrome instance:
{
"id": 0,
"method": "Fetch.enable",
"params": {
"patterns": [{
"urlPattern": "*.js*",
"resourceType": "Script",
"requestStage": "Response"
}
]
}
}
I was expecting it would cause "Fetch.requestPaused" event for each script file downloaded by a page. It works only for the resources provided in the <head> section of the page, like <script src="..."/>
If the <script src="..."/> is included in any other part of the page (ie. outside of header) it is not being intercepted and no "Fetch.requestPaused" event is issued. Anyone knows how to intercept those reuests (I need to modify the responses before they get to the browser).

Related

Trigger Botframework v4 on Facebook Messenger from an external website call

i am trying to open a specific messenger page and trigger a dialog to display carousels based on the parameters that my users entered on my website.
i am leveraging the m.me link to open my messenger page (where my botframeowrk bot is deployed). After opening the page I am not able to invoke a dialog.
How can I achieve this ???
I went through the Ms Botframework V4 docs and didn't find any mention of channel specific trigger.I want to pass 4 parameters to my Bot from the website and then further make an api call in the dialog that i will invoke to display results.
Thanks in Advance.
You need to enable Messaging Referrals in the Facebook Developer portal to use m.me links. In the portal, click on the settings blade on the left, scroll down to webhooks, and click edit events. A window should pop up where you can enable messaging_referrals.
Facebook only lets you add the ref parameter to the m.me link, so to send additional data to the bot using this link, you will have to encode the values in the ref parameter and parse the data on the bot side - I would recommend using a separator value like a comma or a slash to organize your data.
https://m.me/<PAGE_NAME>?ref=my,additional,data
The event will be send to the bot as a message activity with a referral attribute where you can grab your data.
m.me link bot activity
{
"type": "message",
"id": "CDbQi3u62J7",
"timestamp": "2019-03-19T19:30:11.219Z",
"serviceUrl": "https://facebook.botframework.com/",
"channelId": "facebook",
"from": {
"id": "2031650190235097",
"name": "TJ Durnford"
},
"conversation": {
"isGroup": false,
"id": "2031650190235097-218838049015546"
},
"recipient": {
"id": "218838049015546",
"name": "thdurn-all-channels"
},
"channelData": {
"sender": {
"id": "2031650190235097"
},
"recipient": {
"id": "218838049015546"
},
"timestamp": 1553023811219,
"referral": {
"ref": "my,additional,data",
"source": "SHORTLINK",
"type": "OPEN_THREAD"
}
}
Hope this helps!

Google Schema Tag for site ratings/reviews not working

I've added Schema Tags in order to show star ratings in google search like in the screenshot
I've added the below code
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "WebSite",
"url": "https://mysiteexample.com",
"potentialAction": { "#type": "SearchAction",
"target": "https://mysiteexample.com/search/?keyword={search_term_string}",
"query-input": "required name=search_term_string" },
"aggregateRating": {
"#type": "AggregateRating",
"ratingValue": "4.8",
"bestRating": "5.0",
"ratingCount": "45"
}
}
</script>
But it not being shown by google. I don't know what the problem is. I've also verified the schema tag from schema analyzer and its alright. Please help me understand what i'm I doing wrong here. Thanks in advance.
Google does not always show review stars, even if the markup is syntactically correct. Check the Google structured data guidelines.
Some possible reasons:
WebSite is not a specified type that can get review stars
The page with the markup should clearly relate to what is being
reviewed
The reviews should be very visible on the page
The reviews should be directly acquired by the page (submit review
option?)
Home pages do not get review stars

How do I specify the API version in a Facebook batch API request?

A Facebook batch API request allows the caller to specify multiple API endpoints in a single HTTP POST.
The post is made to a base URL: https://graph.facebook.com.
The body of the post contains a JSON hash with relative URLs to call in the "relative_url" field, e.g. "me/feed".
How do I specify an API version in this call?
For example, to hit the 2.2 version of the API, do I post to https://graph.facebook.com/v2.2/ or do I specify "v2.2/me/feed" in the relative_url?
As of Feb 26, 2015 the Facebook API documentation is not clear on this point:
https://developers.facebook.com/docs/graph-api/making-multiple-requests
You probably have to put in the relative url . Here's an example from the marketing batch API docs
curl -F 'access_token=______'
-F 'test1=#./test1.jpg'
-F 'batch=[
{
"method": "POST",
"name": "create_creative",
"relative_url": "<API_VERSION>/act_187687683/adcreatives",
"attached_files": "test1",
"body": "title=Test title&body=Test body&link_url=http://www.test12345.com&image_file=test1.jpg"
},
{
"method": "POST",
"relative_url": "<API_VERSION>/act_187687683/adgroups",
"body": "campaign_id=6004163746239&redownload=1&bid_type=CPC&bid_info={\"clicks\":150}&creative={\"creative_id\":\"{result=create_creative:$.id}\"}&targeting={\"countries\":[\"US\"]}&name=test1"
},
{
"method": "POST",
"relative_url": "<API_VERSION>/act_187687683/adgroups",
"body": "campaign_id=6004163746239&redownload=1&bid_type=CPC&bid_info={\"clicks\":150}&creative={\"creative_id\":\"{result=create_creative:$.id}\"}&targeting={\"countries\":[\"GB\"]}&name=test2"
},
{
"method": "POST",
"relative_url": "<API_VERSION>/act_187687683/adgroups",
"body": "campaign_id=6004163746239&redownload=1&bid_type=CPC&bid_info={\"clicks\":150}&creative={\"creative_id\":\"{result=create_creative:$.id}\"}&targeting={\"countries\":[\"IE\"]}&name=test3"
}
]' https://graph.facebook.com/
I'm assuming this is common to other requests as well.
Various other sources for reading
1.) From here
Pre-pend the version identifier to the start of the request path. For
example, here's a call to v2.2:
GET graph.facebook.com
/v2.2/me
This works for all versions, in this general form:
GET graph.facebook.com
/vX.Y/{request-path}
2.) Putting it in the url seems to be for Dialogs and Social plugins
Dialogs
Versioned paths aren't just true for API endpoints, they're also true
for dialogs and social plugins. For example, if you want to generate
the Facebook Login dialog for a web app, you can prepend a version
number to the endpoint that generates the dialog:
https://www.facebook.com/v2.0/dialog/oauth?
client_id={app-id}
&redirect_uri={redirect-uri}
Social Plugins
If you're using the HTML5 or xfbml versions of our social plugins, the
version rendered will be determined by the version specified when
you're initialising the JavaScript SDK.
If you're inserting an iframe or plain link version of one of our
plugins, you'd prepend the version number to the source path of the
plugin:
<iframe
src="//www.facebook.com/v2.0/plugins/like.php?href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&width&layout=standard&action=like&show_faces=true&share=true&height=80&appId=634262946633418" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:80px;" allowTransparency="true"> </iframe>

How to keep cookies with webview-based Chrome Hosted App

I've just built my first Chrome app (https://chrome.google.com/webstore/detail/gitter/ldhcdmnhbafhckhidlhdbeekpifobpdc) and am experiencing a problem with cookies.
The app effectively boots an index.html page in a window, which has a webview pointing at our regular web application.
If I Quit Chrome on my Mac, every time I launch the Gitter Chrome App, any cookies seem to have been wiped out and so I have to login again (and also login to GitHub again).
I can't quite exactly figure out where to start looking, if anyone has any pointers, I would much appreciate it.
PS. I've checked this question & answer out (chrome Extension : Set persistent cookie in chrome extension?) and as far as I can tell my problem isn't related to non-expiring cookies as we do set expiration on the cookies.
My manifest looks like this:
{
"app": {
"background": {
"scripts": [ "launch.js" ]
}
},
"description": "Chat for GitHub.",
"icons": {
"128": "icon-128.png",
"16": "icon-16.png"
},
"manifest_version": 2,
"name": "Gitter",
"short_name": "Gitter",
"offline_enabled": true,
"permissions": [
"unlimitedStorage",
"notifications",
"webview",
"http://*/*"
],
"version": "1.0.0.3"
}
and the page it boots into a window basically does this:
<webview id="wv1" style="width:100%; height:100%;"
src="https://gitter.im/">
</webview>
I think you need to add a partition attribute to your webview tag with a value starting with persist:
partition
Storage partition ID used by the webview tag. If the storage partition ID starts with persist: (partition="persist:googlepluswidgets"), the webview will use a persistent storage partition available to all guests in the app with the same storage partition ID. If the ID is unset or if there is no persist: prefix, the webview will use an in-memory storage partition.

Chrome packaged application - downloading file from Webview

I am working on getting an existing Ajax style web application functional as a Chrome packaged app. The Ajax app is running in a Webview inside the packaged app and is mostly working great.
The Ajax app allows users to upload documents using standard HTML 5 upload and drag/drop. Uploads work fine but downloads are not working.
This is a simplified sample of the logic in the Ajax app. It uses Javascript to handle the click event, performs some logic, and then eventually triggers the download by setting the location of a hidden IFrame.
<html>
<head>
<script type="text/javascript">
function downloadFile(url) {
window.frames['dataTransfer'].location = url;
}
</script>
</head>
<body>
Google<br/>
Download PDF<br/>
Download PDF JS<br/>
<iframe name="dataTransfer" style="width: 0; height: 0; border: none;"></iframe><br/>
</body>
</html>
If you run this in a standard Chrome tab all 3 links work fine. However in a Chrome App only the first 2 links work - clicking the 3rd link does nothing. In the network section of the Developer tools it actually appears to start the download but then is quickly cancelled.
The manifest of the Chrome app allows Webview and the relevant domains involved.
{
"manifest_version": 2,
"name": "Test Download",
"version": "0.1.0",
"permissions": [
"webview",
"<DOMAIN OF THE SAMPLE PAGE ABOVE>",
"https://s3.amazonaws.com/"
],
"app": {
"background": {
"scripts": ["background.js"]
}
},
"icons": {},
"minimum_chrome_version": "28"
}
The Chrome App has some simple newwindow handling in it as well.
window.onload = function() {
var webview = document.querySelector('#app-webview');
webview.src = '<URL TO SAMPLE PAGE ABOVE>';
webview.addEventListener('newwindow', function(e) {
e.preventDefault();
e.stopPropagation();
window.open(e.targetUrl);
});
};
Any suggestions on how to get downloads working (hopefully without requiring significant changes to the Ajax app)?
File downloads from the webview guest are gated by a permissionrequest event per download attempt. The default response is to deny download permission.
Note: The download permissionrequest will not land until Chrome 30 now, and it appears that documentation has not yet been made available. It is generally a stable API though, and it is unlikely to change between now and then.
In order to override this behavior, you need to handle the event and explicitly allow the download to happen. As an example:
var webview = document.querySelector('#app-webview');
webview.addEventListener('permissionrequest', function(e) {
if (e.permission === 'download') {
e.request.allow();
}
});
The event includes additional information (such as the download URL in e.url) in case you want to further filter your grants.
Be aware that this will only permit the download to happen using the regular Chrome file download experience, which isn't necessarily what you'll want from within a packaged app. Your options are limited until the chrome.downloads API is made available to apps.
One possibility is to deny the download request, grab the URL from the event, and manually manage the download process with XHR, the fileSystem API, and whatever UX you want to build.