Is it possible to determine the HTTP protocol version using JavaScript? I need to detect if the user is using HTTP/2 protocol (and congratulate him if this was the case).
console.log(performance.getEntries()[0].nextHopProtocol)
See also: https://caniuse.com/mdn-api_performanceresourcetiming_nexthopprotocol
Works in
Edge since 17
Firefox (Desktop and Mobile) since 45
Chrome (Desktop and Mobile) since 61
Safari Mac 14.1 (tested here, but not yet updated on MDN/caniuse)
if (location.protocol == "http/2"){
alert('congratulations!');
}
Related
I want to detect that my JS code in a webpage is running in Safari on iOS 11, which supports some new features.
I can do something like
if (window.navigator.userAgent.includes('OS 11_0')) {
// iOS 11
}
but I believe this is considered unreliable.
Is there some feature or a hack that works only on iOS 11 and not on other OS and can be used to detect that version without inspecting the userAgent?
Update: I am talking about getUserMedia so I am not sure if ther is a way to test it presence without triggering the microphone permission request.
Check out this solution, and then you could do something like this:
ver = iOSversion();
if (ver[0]==11) {
// do something
}
The shared snippet can also be used to detect any specific iOS version, >iOS 2.
According to MDN documentation, getVideoPlaybackQuality() on HTMLVideoElement is available after version 25.0.
However, I tried to call it on video element in Firefox 38.1.0 and got an getVideoPlaybackQuality is not a function error.
Is this api actually available for Firefox?
According to Firefox MSE bug report,
Firefox has a whitelist limiting MSE (to YouTube, Netflix, and Dailymotion) while we fix some compatibility bugs. The whitelist will likely be removed in Firefox 42, making MSE available to all websites.
Did you catch the footnote in Mozilla's documentation ... that the function is only available if you switch on a config flag?
Load about:config in Firefox and search for the media.mediasource.enabled flag, then set it to true and try your function call again.
EDIT: If I'm reading correctly, the release notes for Firefox 37 and Firefox 38 seem to indicate that the MediaSource API is currently implemented for YouTube only. However, it's enabled for Firefox Nightlies right now.
I develop an extension for mobile version (as Android version) of Firefox borwser. I use sdk/page-worker high-level api for create a background page for connect with WebSocket server. But when I updated my Firefox to 38 version, page-worker dont'work!
In example I have a next source:
var pageWorker = require("sdk/page-worker");
var tmp = pageWorker.Page({
contentScript: 'console.log("Im loaded!!");'
});
It was work on older version of Firefox (etc 37).
But it don't work only in mobile version of Firefox. On desktop Firefox 38 page-worker is work.
It's a bug or a new feature? Thanks!
More details,
I use a simple post Ajax call (used Jquery but also the native XMLhttpRequest with the form encoded as url encoded.
myPost: function(url,form,doneCallback,failedCallback){
var mypost = new XMLHttpRequest();
mypost.onreadystatechange = function() {
if (mypost.readyState === 4){
doneCallback(mypost);
}
};
mypost.onerror = function() {
failedCallback(mypost);
};
mypost.open('POST',url,true);
mypost.setRequestHeader('Content-Length', result.length);
mypost.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
mypost.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
mypost.setRequestHeader('Connection','close');
mypost.send(form);
},
In both situations the code works just fine with Chrome, Safari, Firefox and on IE 11 on win 8.1 or win 7 as a VM on VMWare Fusion, so running on a Mac OsX 10.9.2 with the latest win 8.1 updates installed. However as soon as this code runs on a native windows 8.1 version and IE with the same version for OS and IE, the post forgets to put out the post payload no matter whether I put the above header attributes in or not.
And yes a chrome browser on native win 8.1 properly puts the payload to the server, while the native IE 11 does not put the payload out. The receiving server linux based restlet is missing the payload for the specified resource so further returns a "500" status at the application layer.
There must be some configuration difference with respect to the IE on the native and the VM. As far as I can see this is different from what similar question have described.
BTW on the same native windows 8.1 some posts are working that address a form already created on the web pages, while the above form date is simply filled as.
form = 'options='+encodeURIComponent(options);
Any idea where the different behaviour is created?
Thanks
mypost.setRequestHeader('Content-Length', result.length);
mypost.setRequestHeader('Connection','close');
those lines are only working in FireFox for me, if I remove those 2 lines, my code is working in IE11.
i am trying to write a websocket page, and it works in Chrome and some other browsers on my Ubuntu machine.
however, firefox would not run the websocket part, and both window[WebSocket] and window[MozWebSocket] return "undefined". does firefox not support websockets?
Use (from MDN docs):
var mySocket = new WebSocket("ws://www.example.com/socketserver", "protocol");
It is supported from Firefox 6.0 (known as MozWebSocket prior to Fx 11 - see #Dracs' comment).
Extensions like TorButton can set network.websocket.enabled to false in about:config. Make sure it's true.