Redirect URL from local filesystem to internet with browser WebExtension - redirect

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

Related

Is there a way to conditionally block a referer in Google Tag Manager?

We have an issue with GA where conversion sources are being lost after a user clicks on a link to our site, goes to the site, and then logs in using Facebook.
My understanding from GTM tips - implement referral exclusions is that our site sees the document.referrer as coming from Facebook and starts a new session, losing the original referrer. If we know the landing page on our site the user sees after logging into Facebook, is it possible to add code to exclude the FB referrer only for that page? I.e, on that one page we have something like (from the linked article):
function() {
var referrals = [
'facebook.com'
];
var hname = new RegExp('https?://([^/:]+)').exec({{Referrer}});
if (hname) {
for (var i = referrals.length; i--;) {
if (new RegExp(referrals[i] + '$').test(hname[1])) {
return null;
}
}
}
return {{Referrer}};
}
We can't simply add facebook.com to the GA exclusion list, as we have campaigns running on Facebook as well, so we'd still need visibility to organic traffic coming from Facebook.
You can copy GA tag and modify the copy with this code. Then fire that copy only on pages where you need to block referrer and block original GA tag on same pages.
If you don't want to have multiple GA pageview tags then use Lookup Table variable based on page paths. For some pages this variable should return your code as a Custom JavaScript variable and a default value should be {{Referrer}}.

when used /me/feed post, it seems that the facebook is using cached link url

I have made an web site using facebook api.
such as below
var params = {
method : "stream.publish",
message : $("#textareaForSns").val(),
picture : urlForGameIcon,
name : titleForSns,
description : descriptionForSns,
link : "http://hgurl.me/a5t"
};
FB.api("/me/feed", "post", params ...
but, I found a problem. :(
I used link url as http://hgurl.me/a5t. this url is operating to redirect to another web site according to device type. (mobile or pc)
I changed redirection url later but it doesn't redirect to new url in each post. it occasionally redirect to old url yet
old one is 183.110.213.149:10080/ds/install.php.
new one is drgfriends.hangame.com
I don't know exactly how the facebook is working internally. I think that facebook is using cache data.
how can I make this short url working to redirect to new url I changed?
can I remove the cache?
please help me sir
thank you

Facebook share to refer back traffic to the iframe page tab

SO here's what I am after. I have a FB page tab that runs the content of the site https://site.com/
I set up a FB share link to share a page aboutus.html. When I share it FB allows me to share this URL https://site.com/aboutus.html, but how can i send the traffic directly to the iFrame on the page tab? For example https://www.facebook.com/fan_page/app_331267943480920398/whatever_aboutus.html
I know it is possible because I saw it one day - cant remember now where.
Thanks.
You can't pass in filenames this way, that's only supported on Canvas Apps.
The best workaround to replicate this is using the app_data parameter. Basically, have your landing page (as defined in your app settings), be some kind of server side script which listens to the Signed Request, specifically the app_data parameter. Then you have that script load content based on the contents of that.
So as an example, let's imagine I want to load http://mybasedomain.com/foo.php or http://mybasedomain.com/bar.php. I direct users to https://www.facebook.com/PAGENAME/app_APPID?app_data=foo or https://www.facebook.com/PAGENAME/app_APPID?app_data=bar, then on my landing page, I have a simple if/else statement to parse that and render the relevant content -
<?php
// Assumes you have this parse_signed_request function - https://gist.github.com/872837
// And a $config array, which contains your app_secret
$signed_request = parse_signed_request($_REQUEST['signed_request'], $config['AppSecret']);
if ($signed_request['app_data'] === 'foo') {
include('foo.html');
} else if ($signed_request['app_data'] === 'bar') {
include('bar.html');
} else {
include('index.html');
}

Getting Actual Facebook and Twitter Profile Image URLS for Flex Security Policy

I'm trying to display the profile images from both facebook and twitter. For facebook, the URLs I'm receiving are something like this (not actual urls):
http://graph.facebook.com/965412145/picture
Which is then redirected to the 'actual' url like this:
http://profile.ak.fbcdn.net/hprofile-ak-snc4/370471_9631690_1796253478_r.jpg
I'm also doing this with twitter, with the same issue (redirected url).
So, when I load the image, it loads fine. But when I close the container that the image is in, then I get the security sandbox violation.
I can get this all to work if I add the URL from the 'actual' image url like this:
request = new URLRequest("http://profile.ak.fbcdn.net");
loader = new Loader();
context = new LoaderContext();
context.checkPolicyFile = true;
loader.load(request, context);
However, at run time, I do not actually know what the 'actual' image url is, so I can't hard-code that domain in (nor do I want to).
Is there a way to get the actual url (from within flex) of the image so that I can add the correct domain to the loadercontext?
Any ideas are appreciated!
If I understand correctly, your problem is that you're trying to load an image from a URL that redirects to another source. You need to know what the redirected URL is, so you can load a policy file that allow manipulation of image bytes.
If I've understood correctly, you need to detect the redirected URL by listening for the COMPLETE event (or an error event), then reference the LoaderInfo.url property. This property will reflect the end URL in the event of redirects. For example, you would have code like this in the listener:
var ldr:LoaderInfo = event.target as LoaderInfo;
var url:String;
try
{
url = ldr.url;
// Split off URL base, load policy file, etc here
}
catch (e:Error)
{
// Unable to detect final URL due to error.
}

Google Chrome Extension - Accessing The DOM

I have been searching around the web to find out how to access the current tabs DOM to extract information out of a page from the background.html. So far I have had no luck, or at least nothing I could get to work properly.
To state the problem simply. I would like to get src of a iFrame on the page. Any Suggestions?
One way, you an treat this as a single one time request to the content-script which will fetch the dom you want to access.
http://code.google.com/chrome/extensions/messaging.html#simple
Basically, your content script sets up the listener:
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
if (request.greeting == "hello")
sendResponse({farewell: "goodbye"});
else
sendResponse({}); // snub them.
});
And your background page sends a single lived request:
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {greeting: "hello"}, function(response) {
console.log(response.farewell);
});
});
When you send your response, you send it as JSON data, you can fetch whatever you want (such as html, dom, text, etc).
That is currently the only way to let the background page know anything about the contents of a page. Remember you would need content scripts and tab permissions.