Recently we migrated a Chrome extension to Microsoft Edge. For Edge hasn't implemented native messaging, so we want to communicate with native app by websocket via Edge extension background page.
After testing, we found that, in the background page websocket can access external host successfully, but localhost, even though access '127.0.0.1' failed.
And we try to access localhost in the web page, it did!
Edge browser info:
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; ServiceUI 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"
We have checked "Allow localhost loopback (this might put your device at risk)" from about:flags.
Does Edge extension background page support access localhost? If it does, how can we achieve it? If not, could anyone help?
We run the WebSocket server as this example: https://blog.idrsolutions.com/2013/12/websockets-an-introduction/.
The extension can be downloaded from: https://github.com/chhxia/Edge-Extension.
The code of edge extension background js:
var ws;
function openSocket(){
var socket, path;
// path = 'wss://echo.websocket.org'; // successfully access this path.
path = 'ws://localhost:8080/EchoChamber/echo';
console.log( '===> Tested path :: ', path );
try {
ws = new WebSocket( path );
}
catch ( e ) {
console.error( '===> WebSocket creation error :: ', e );
}
ws.onopen = function(){
alert('open...');
ws.send('text');
}
ws.onmessage = function(e){
alert("receive: " + e.data);
}
ws.onclose = function(e){
ws = undefined;
alert('close...' + e);
}
}
(function(){
openSocket();
browser.browserAction.onClicked.addListener(function(tab) {
if(ws === undefined){
openSocket();
}else if(ws && ws.readyState === WebSocket.OPEN){
alert('send');
ws.send('text');
}else{
alert('websocket is closed.');
}
});
})();
To save you a few clicks: IE, Chrome, and Firefox allow it, Edge doesn't. Microsoft says that accessing localhost in Edge extensions is blocked by design:
"We are working on Native Messaging for the next release and using
native messaging is the right way to solve this scenario. Localhost
access is not enabled from extension background page is by design."
https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8984919/
... and native messaging for Edge requires an UWP host:
"At a high level, Microsoft Edge extensions use the same APIs for
native messaging as Chrome and Firefox extensions. However, the native
messaging host will need to be implemented using the Universal Windows
Platform."
https://learn.microsoft.com/en-us/microsoft-edge/extensions/guides/native-messaging
I ran into this issue while developing my own extension for Edge. I had also checked the "Allow loopback..." setting in about:flags and so I was very confused and frustrated. Having your extension be able reach localhost while developing seems like a reasonable thing to want... right?
It turns out that you can actually access localhost from an Edge extension. You just have to ensure that you add Edge to the loopback exempt list by running CheckNetIsolation LoopbackExempt -a -n="Microsoft.MicrosoftEdge_8wekyb3d8bbwe" in a Powershell prompt (running in Administrator mode).
To undo that, just run CheckNetIsolation LoopbackExempt -d -n="Microsoft.MicrosoftEdge_8wekyb3d8bbwe".
Edge issue regarding Edge extensions and localhost requests: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/13966307/.
Access localhost via Microsoft Edge extension background page
https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8984919/
Related
I am currently trying to run my react-native/rails app on my phone for testing purposes. I can run my sign in and log in screens fine because they do not communicate with my server until the user info is entered. When running my server i use:
$ rails s --binding=0.0.0.0
I do not receive any errors other than knowing my server is not being communicated with. This all works fine on my Android Studio Emulator as well.
// one of my fetch GET requests
export function requestCurrentUser(username, auth_token) {
return function action(dispatch) {
const request = fetch(`'http://10.0.2.2:3000'/users/${username}`, {
method: 'GET',
headers: {
"Authorization": auth_token
}
});
return request.then(
response => response.json(),
err => console.log("user error"),
)
.then(
json => dispatch(receiveCurrentUser({id: json.id, email: json.email, username: json.username})),
err => console.log("user json error"),
);
}
}
I've tried changing my Phone IP settings to a 10.0.2.2 Gateway, and using my phone's IP in my fetch request. I feel like I am missing something conceptually. Thanks in advance.
In fetch request you need to use the IP from the machine that are running the rails server,
probably your notebook and use the same network to connect your app and your rails backend api. In order to test, you can try directly access your api in your phone browser accessing http://IP_FROM_RAILS_MACHINE:3000
I've been struggling for couple of days with eBay token authentication on smartphones. I am able to register customer tokens on desktop systems, tablets and hires smartphones. On the android app there is a intent listener to get the reply and register the token within the app.
But on some devices, the following message occurs within registration flow trough ebay:
This can not be done on a small screen. Please try again with a desktop computer.
eBay customer support told me, that it is not possible to use the registration on apps. But i don't understand this, because the registration window for the token registration flow is matching even on small devices!
Any idea to solve this? Eventually to simulate a higher resolution / meta information for the web-view so the message wouldn't generated from the eBay server?
Thank you very much for any idea.
I had to zoom out the browser window
https://stackoverflow.com/a/4322209/1849478
also needed to set the UserAgent of the Webview like this:
String agent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.5) Gecko/20100101 Firefox/4.1";
mWebView.getSettings().setUserAgentString(agent);
Try to set the browser size with javascript.
<html>
<head>
<script>
window.alert("Window resolution before overwrite is " + window.screen.availWidth + " x " + window.screen.availHeight);
Object.defineProperty(window.screen, "availWidth", { get: function(){return 0; }});
Object.defineProperty(window.screen, "availHeight", { get: function(){return 0; }});
</script>
</head>
<body>
<script>
window.alert("Window resolution after overwrite is " + window.screen.availWidth + " x " + window.screen.availHeight);
</script>
</body>
</html>
Here is another way
I'm trying a react native application using couchDB 2.1.1. PouchDB entry in package json looks like this:
"pouchdb": "^6.3.4",
"pouchdb-react-native": "^6.3.4",
Replication is as shown below:
const localDB = new PouchDB('employee');
const remoteDB = new PouchDB('http://username:password#localhost:5984/employee');
localDB.replicate.from(
remoteDB,
(err, response) => {
if (err) {
return console.log(err);
}
},
);
I get following error:
{"code":"ETIMEDOUT","status":0,"result":{"ok":false,"start_time":"...","docs_read":0,"docs_written":0,"doc_write_failures":0,"errors":[],"status":"aborting","end_time":"...","last_seq":0}}
Almost all the times this works fine when I run the app in debug mode. Tried ajax timeout as shown here PouchDB ETIMEDOUT error. This didn't work. Is there something that I'm supposed to look in my code? Please help.
Had the same issue, the following fixed it for me:
Use your PC ip address instead of localhost
Configure your firewall
to allow connections on port 5984 OR just disable it (Not
recommended)
I am trying to convert a Chrome Extension to Firefox using the new API WebExtension.
Everything works fine except the use of chrome.runtime.sendMessage() in a webpage. The goal is to communicate with the addon and pass some data.
For that, I am using the property "externally_connectable" as written here : can-a-site-invoke-a-browser-extension
background.js
chrome.runtime.onMessageExternal.addListener(
function(request, sender, sendResponse) {
sendResponse({
success: true,
message: 'ok'
});
return true; // Bug chrome, close channel otherwise
});
In webpage
chrome.runtime.sendMessage(EXTENSION_ID, {type: 'show', data: 'test'}, function(response) {
if (response.success && !response.success) {
console.log(response.message);
}
});
In chrome, the communication works fine but in Firefox, the code executed in the webpage doesn't work : "chrome is not defined".
Is there another var to use instead of "chrome" or is it not implemented ?
I've found nothing about this on the web :( Thanks
Web extensions do not support externally_connectable website scripts but you can communicate between website scripts and extension scripts as shown in this example
https://github.com/mdn/webextensions-examples/tree/master/page-to-extension-messaging
Try use WebExtension APIs with "browser" namespace
browser.runtime.sendMessage(...)
All available APIs on mozilla development
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts#WebExtension_APIs
I am doing a server side dart code using notepad++, I have already succeed in server side dart code using dart editor. But I the same think where I done with notepad++ done a error as net::ERR_UNSAFE_PORT in dart in browser, Dart server side initialed by Command prompt is done, When I try to access 172....190 ,Bowser(dartium) said that above error!!!
server side code
main() {
HttpServer.bind("172...", 4045).then((server) {
server.listen((res) {
res.response.headers.add("Access-Control-Allow-Origin", "172.25.10.181");
res.response.headers
.add("Access-Control-Allow-Methods", "POST,GET,DELETE,PUT,OPTIONS");
res.response.headers.add('Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept,application/x-www-form-urlencoded');
print('I am writing server side code');
});
});
}
Client side code
req = new HttpRequest();
req.open('get', 'http://172...:4045');
req.send(data);
req.onReadyStateChange.listen((_) {
if (req.readyState == HttpRequest.DONE &&
(req.status == 200 || req.status == 0)) {
print(req.responseText);
}
});
Here is a best way to deal with this issue.
There some ports are reserved for specific protocols like 80 for HTTP
and 22 for SSH etc. If you use that port for another kind of protocol
you will face this error. In my case, I'm using 6000 port for my
backend API server which was resolved. I just simply move 6000 port to
7789 all stuff working as expected. Here are the list ports for
specific protocols that you may not violate. You need to use port other then this for your specific work.
Shameless copied from https://superuser.com/questions/188006/how-to-fix-err-unsafe-port-error-on-chrome-when-browsing-to-unsafe-ports
Right Click on Chrome shortcut >> Properties >>
Then Append
--explicitly-allowed-ports=xxx to shortcut target
Example:
C:\Documents and Settings\User\Local
Settings\Application
Data\Google\Chrome\Application\chrome.exe
--explicitly-allowed-ports=6666
Resource from here
There is a bug in some versions of Chrome that prevents the given --explicitly-allowed-ports solution from working. In that case, a temporary workaround would be:
Browse to chrome://flags/#network-service.
Set "Enable network service" to Disabled.
Restart Chrome.
Reference