How to redirect url chrome-extension? - javascript

I'm using Google Developer Console and Oauth to develop a chrome extension so that user can login by google account.But I can not redirect to url like this
chrome-extension://<id>.
So how can this be solved ?

I know this is an older question, but I wondered too. You have to use the built in chrome API for accessing your extension's HTML.
chrome.extension.getURL('options.html')

Send redirect url from a content script to a background page:
chrome.extension.sendRequest({redirect: "http://redirect"});
In a background page update tab's url which would cause redirect:
chrome.extension.onRequest.addListener(function(request, sender) {
chrome.tabs.update(sender.tab.id, {url: request.redirect});
});
Refer: How do I redirect to a URL using a Google Chrome Extension & Content Script?

Related

Failed to load URL because the scheme does not have a registered handler, using extension URL

I'm trying to use window.open to open an extension page, I don't care about checking if the user has the extension, I just want to open a window that starts with extension://, it's not working and says failed to load url because the scheme does not have a registered handler. My code looks like this:
const openedWindow = window.open("extension://<extension url>", "", "width=300, height=300");
openedWindow.onload = () => {
openedWindow.close();
}
this code works with normal urls, but not with ones starting with extension://. Is there any way to open a url like this?
edit: needed to use chrome-extension:// instead of just extension. Now there's a new problem, chrome is blocking the page. How do I fix this?
It's because the correct URL for a chrome extension is chrome-extension://1234
Also popups should be explicitly allowed by a user interaction on the popup permission that Chrome asks in the URL bar

How to open a tab to a file:/// URL Firefox extension developement?

I don't know much about JavaScript. I am trying to open a tab with a file URL and it keeps reverting to the about:newtab page. Is it possible to open a file URL in Firefox extension?
Currently I am using:
var updating = browser.tabs.update(tab.id, { url: result.data.url });
updating.then(onUpdated, onError);
Where result.data.url is a file URL. It works with HTTP and HTTPS URL.
I am using Firefox 56.0.1
Currently it's not possible. You can follow bug https://bugzilla.mozilla.org/show_bug.cgi?id=1266960 to stay up to date.

Google Login For Phonegap

After the authentication page does not return the redirect url and showing 404 error. I need the run project in mobile . I am building with phonegap but mobile does not have localhost. how to define local file to redirect_uri ?
Returns This url after
http:// localhost /cevap/redirect.html?state=%7B%22client_id%22:%2275055614045-a999nkehht0jk3i46548qg32imu0toqg.apps.googleusercontent.com%22,%22network%22:%22google%22,%22display%22:%22popup%22,%22callback%22:%22_hellojs_8ws7jbej%22,%22state%22:%22%22,%22oauth_proxy%22:%22https://auth-server.herokuapp.com/proxy%22,%22scope%22:%22friends,basic%22,%22oauth%22:%7B%22version%22:2,%22auth%22:%22https://accounts.google.com/o/oauth2/auth%22,%22grant%22:%22https://accounts.google.com/o/oauth2/token%22%7D%7D&code=4/x9MedwZ8NJN6qUgq2rXAVaBtFuOk.QpP5N0crfbAbYFZr95uygvVVqe1rjwI&authuser=0&num_sessions=1&hd=veriyazilim.com.tr&session_state=f715c83530f60300552e4920948401332014eeea..224b&prompt=none
hello.init({
google : '75055614045-a999nkehht0jk3i46548qg32imu0toqg.apps.googleusercontent.com'
}, {
redirect_uri : 'http://localhost/cevap/redirect.html',
response_type:'code',
scope:'friends'
});
I created Client ID for web application in google .
This is my folder directionary :
For developing in a desktop browser:
A dev domain is required which matches the domain you defined as a callback url when registering your app - define this callback url in redirect_uri, and ensure it points a document containing ./hello.js.
in your case this file would be located at http:// localhost /cevap/redirect.html
For phonegap this isn't the case as apps are run as "file://path/to/installed/apps/myproject" or something. But phonegap apps can watch the URL of popup windows it intitiates, and thats exactly how hello.js works to extract the access_token from the popup windows querystring. in this case there is no need for the redirect_uri to be a valid path, but for a better user experience i would have it point to a web resource which can display something like a spinning wheel.
Problem does not in url.
inappbrowser doesnt load to project. I changed config.xml plugin to this and inappbrowser loaded and problem fixed.
<gap:plugin name="org.apache.cordova.inappbrowser" />

How to open a page with information about the browser?

Is it possible via window.open to open a page with information about the version of the browser? My browser is Google Chrome.
window.open("chrome://version/");
This code opens a new tab "about:blank".
You cannot use any of the usual APIs from the Web platform to open chrome:// pages.
These pages can be opened using chrome.tabs.create though:
chrome.tabs.create({
url: 'chrome://version'
});
You're not allowed to do this (security reason, probably):
Try typing that in the console:
window.location.href = "chrome://version/"
output: Not allowed to load local resource: chrome://version/

How do I redirect to a URL using a Google Chrome Extension & Content Script?

I'm currently building a Google Chrome extension which tests for certain patterns and if found, redirects them to a new URL.
I've gotten the pattern checking done via a content script, and now I'm not sure how can I proceed with getting the redirect done. Any suggestions ?
Send redirect url from a content script to a background page:
chrome.runtime.sendMessage({redirect: "http://redirect"});
In a background page update tab's url which would cause redirect:
chrome.runtime.onMessage.addListener(function(request, sender) {
chrome.tabs.update(sender.tab.id, {url: request.redirect});
});
If you want to access a file inside your WebExtension, you can add the file and its prerequisites to web_accessible_resources in manifest.json, as in
{
...
"web_accessible_resources": [
"images/*.png",
"style/double-rainbow.css",
"script/double-rainbow.js",
"script/main.js",
"templates/*"
],
...
}
Ive not worked with Google Chrome extensions... but you may be able to use one of these ways.
As I understand, these extension APIs allow you to inject javascript into the page... after that its simple manipulation of window.location ...

Categories