Puppeteer redirect throws ERR_BLOCKED_BY_CLIENT - redirect

I am using puppeteer to bring up chromium and launch a page. For my scenario the page URL has to be intercepted along with the css/js/img requests coming from the page.
My puppeteer code for page interception looks like this,
await page.setRequestInterception(true);
page.on("request", async (request: HTTPRequest) => {
if (request.url().endsWith(".html") ||
request.url().endsWith(".js") ||
request.url().endsWith(".css") ||
request.url().endsWith(".png")) {
let redirectUrl = await getNewUrl(request.url());
request.continue({ url: redirectUrl });
} else {
request.continue();
}
}
My initial HTML page load happens properly with the redirect URL.
Then the HTML page has a few browser requests the redirect URL is also fetched and the request is continued with redirect URL.
All the browser requests return an error looking like this,
I am still new to puppeteer and chrome extension development, kindly let me know if any way to figure out the issue here.

I am also suffering from same issue but I have a solution for this issue. If you are using ajax method and give static url path so remove this path and fix from dynamic path.

Related

Redirect URL from local filesystem to internet with browser WebExtension

To summarize the problem, I have several PDF files on my computer that contain links to other pages. Those links, however, direct you to the local filesystem instead of the internet (i.e. clicking the link opens the browser and takes you to file:///page instead of http://domain/page).
Getting these files modified to include the full URL is not an option. My question is almost identical to the question I asked a year and a half ago. The difference is that I need to port my existing extension (made with the Firefox SDK) to the new WebExtensions API for Firefox (same as Chrome extensions).
There are methods available for redirection, such as
browser.webRequest.onBeforeRequest.addListener(
redirect,
{urls:[pattern]},
["blocking"]
);
but that only accepts http:// and https:// URL patterns.
I am currently trying to use the following code:
var id;
browser.tabs.onCreated.addListener( details => id = details.id )
browser.tabs.onUpdated.addListener( (tabId, changeInfo, tab) => {
var url = changeInfo.url;
if (tabId == id && url.includes("file:///")) {
url = url.replace("file:///page", http://domain/page");
browser.tabs.update(
id,
{ url: url }
);
}
});
Unfortunately, I have the same fundamental issue as with my original problem, resulting in the onUpdated listener not firing (or if it does fire, it's not because of a URL change). But regardless of the listener used (e.g. onCreated, onActivated, etc.), I get about:blank for the URL.
I have tried injecting code to change the value of the address bar, but that doesn't seem to work either:
browser.tabs.executeScript( {
code: "window.location.href = window.location.href.replace('file:///', 'http://domain/')"
});
Thanks for any help!
redirectUrl : chrome.extension.getURL("hello.html")
Worked for me

Facebook Live Stream Static URL

I was curious as to if there is anyway to have a certain page on Facebook have a static URL for it's Live Streams. I want this so I can use that static URL and embed it on a website (Weebly or Wordpress). Does anyone know of a way to do this?
Any and all input is greatly appreciated.
Thanks much!
No, currently there is no such direct feature provided by Facebook to achieve what you want to do. But there is definitely an indirect way of doing this using Facebook Graph API.
Indirect method of doing so:
Use your page ID to get status of last live video of your page.
/Page_ID?fields=live_videos.limit(1){status}
If you get status field as 'LIVE', it means your video is still LIVE on your page. Then, use the returned Video Id of Live video to make next request.
You can get the embed html of the live video using this request:
/Video_ID?fields=embed_html
Use the returned embed_html to embed live video in your wordpress site.
You just need to write the script that executes the above task and embed video conditionally if the status of video is LIVE otherwise not.
This is a pretty old question, but here's my solution:
Make a GET request to https://facebook.com/PAGE_ID/live
Capture the redirect - this request redirects to the URL you want
How I did it in Node.JS
const https = require("follow-redirects").https;
const PageID = "nexe32"
let redirected = false;
https.get({
host: 'facebook.com',
path: `/${PageID}/live`,
headers: {
"User-Agent": 'curl/7.43.0'
},
beforeRedirect: (opts) => {
if(!redirected) {
redirected = true;
} else {
console.log(opts.href); // the URL you want
redirected = false;
}
}
});
``

redirect uri causing issues when navigating to an oauth url

I am trying to navigate to the Microsoft Live oauth authentication page so that I can authorize my user and get a token for use by the app. When I use the following NSURL string, I am able to navigate to the site and authorize my app, retrieving the token.
let stringUrl = "https://login.live.com/oauth20_authorize.srf?client_id=\(clientId)&scope=\(scope)&response_type=code"
let url = NSURL(string: stringUrl)!
However, I want to redirect back to my app (using SFSafariViewController). In order to do so, I added a URL Scheme to my app, and passed that in as the redirect_uri in the URL.
let stringUrl = "https://login.live.com/oauth20_authorize.srf?client_id=\(clientId)&scope=\(scope)&response_type=code&redirect_uri=Lifestream://onedrive-oauth-callback"
let url = NSURL(string: stringUrl)!
However the Live login site gives me an error saying something went wrong and it couldn't continue. This error occurs before the oauth login page is displayed. It happens immediately upon navigating to the URL.
Am I creating my URL scheme incorrectly, or passing the scheme in to the redirect uri improperly? I'm confused as to why it works fine without the redirect_uri, but the site can't load when I provide it.
Can someone point me in the right direction on how I am supposed to pass a redirect url for my app, into an oauth redirect?
Update
It seems that Microsoft does not allow you to register a redirect URL that is a App URL scheme. I dont know how to get this info back into my app then, other than just paying for a site I can point MSFT to, which would then do nothing but redirects into the app for me.
I had a similar OAuth problem and didn't want to mess around with a web server so instead what I did was kinda cheeky. Make a UIWebView and put the request on the web view. Then delegate it to yourself and pass the redirect URL to be http://localhost:8000 (it can be anything like that it really doesn't matter). Then inside the delegate do this:
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool
{
if let URL = request.URL?.absoluteString
{
// This should be the redirect URL that you pass it can be anything like local host mentioned above.
if URL.hasPrefix(redirectURL)
{
// Now you can simply do some string manipulation to pull out the relevant components.
// I'm not sure what sort of token or how you get it back but assuming the redirect URL is
// YourRedirectURL&code=ACCESS_TOKEN and you want access token heres how you would get it.
var code : String?
if let URLParams = request.URL?.query?.componentsSeparatedByString("&")
{
for param in URLParams
{
let keyValue = param.componentsSeparatedByString("=")
let key = keyValue.first
if key == "code"
{
code = keyValue.last
}
}
}
// Here if code != nil then it has the ACCESS_TOKEN and you are done! If its nil something went wrong.
return false // So that the webview doesnt redirect to the dummy URL you passed.
}
}
return true
}
This is sorta hacky but it works great and you don't need any server nor do you need a redirect URI on your app, its an awesome way to do it in my opinion. You could optimize this for swift 2 to reduce the indentation by using guards but I wrote this before it came out so...
Hope this helps!

Do not receive a response from FBAS.init

It was working till Thursday of last week, but I'm wondering if something changed cause the code has been the same since then.
I pass the following JSON information to the FBAS.init call from my app in facebook
{"oauth":true,"appId":"MYAPPID"}
Here's the relevant code:
//We call Facebook API init call like so:
trace("init");
Facebook.init(_appKey, _fbInitResponse);
//Here's our callback
protected function _fbInitResponse(success:Object, fail:Object):void
{
trace("fbInitResponse: success = " + success);
// User logged in successfully
if (success)
{
trace("\t session recieved!");
_session = success;
dispatchEvent(new Event(FacebookEvent.INIT));
}
else
{
trace("ERROR: " + fail);
}
}
Actually: It looks like a bug with Facebook not redirecting to the Secure Canvas URL properly. The hack below is a short-term work-around, but this looks like a bug on Facebooks end.
Ran into the same problem as you. Was a mismatch when a user was using https to access the Facebook app, but the app page was being served in http.
A Facebook auth change has been propagating to users since March.
I assume this was the change to cause the bustage:
https://developers.facebook.com/roadmap/#enhanced-auth-dialog
The tip found in this answer helped me:
Facebook JavaScript SDK over HTTPS loading non-secure items
I put the: FB._https = (window.location.protocol == "https:");
I put it right after the fb-root div in a script element. Very hacky.

mobile version of Facebook app going into redirect loop

I have developed a Facebook app using the C# SDK and it is working fine. Now I want to also enable it on mobiles, so I tried to set the "mobile url" to the same one as my canvas url (which is a cloudapp.net address). However, when I try to access it from a mobile, it seems to go into a redirect loop involving my canvas url, the apps.facebook url and the m.facebook/apps url. Sometimes it goes out of the loop and I get the facebook error message saying : "the mobile version of the app is unavailable because it is misconfigured. It appears to be caught in a redirect loop."
I think it may have to do with the fact that the facebooksettings in the webconfig file specify that my cloudapp page should redirect to the apps.facebook.com page, which then redirects to the mobile url and so on. Can someone tell me how to solve this problem - I just want my mobile url to be the same as my canvas url.
Thanks.
If the request is from mobile add extra logic
For v6,
var fb = new FacebookClient();
var desktopLoginUrl = fb.GetLoginUrl(new { .... });
var mobileLoginUrl = fb.GetLoginUrl(new { ...., mobile = true });
For v5,
var urlBuilder = new UrlBuilder(oauthClient.GetLoginUrl(...));
urlBuilder.Host = "m.facebook.com";
var loginUrl = urlBuilder.Uri;