MIDI.js Error code:1, can't requestMIDIAccess - javascript

I am trying to use MIDI.js to play sounds in the browser.
https://github.com/mudcube/MIDI.js
It works in the chrome browser on one of my computers, but not on my other one (which is a chromebook), or on the chrome browser on two of my friends computers.
it prints to the console
"uh-oh! Something went wrong! Error code: 1" MIDI.js:349
which refers to this part of MIDI.js
navigator.requestMIDIAccess(function (access) {
plugin = access;
output = plugin.getOutput(0);
if (callback) callback();
}, function (err) {
console.log("uh-oh! Something went wrong! Error code: " + err.code );
});
i found this post which seems to be referring to the problem i'm experiencing but i'm not quite sure
https://plus.google.com/+ChrisWilson/posts/cs4J6sS9qmJ
where it says to swap some parts of the code for some reason I couldn't understand
navigator.requestMIDIAccess( successCallback, failureCallback );
becomes:
navigator.requestMIDIAccess().then( successCallback, failureCallback );
but after replacing that part on MIDI.js 344, i get the error message
Uncaught TypeError: Cannot call method 'then' of undefined
Any help on how to fix this problem so it works in all browsers, or at least all chrome browsers, would be greatly appreciated. Thankyou

Chromebooks don't have Web MIDI API support yet (nor on Mac or Windows if you don't enable it, or Windows if you're not running Canary).

Related

Getting "Type Error" when using WebAuthn on IOS

I'm trying to work with WebAuthn for the first time. Everything works well on Android and Windows, however on IOS, I'm getting TypeError: Type Error when calling navigator.credentials.create or navigator.credentials.get.
Here is an example screen shot of the publicKey I'm using on create:
JavaScript:
try {
newCredential = await navigator.credentials.create({
publicKey: makeCredentialOptions
});
}
catch (e) {
alert(e.toString());
return;
}
I'm using the following demo code from https://github.com/passwordless-lib/fido2-net-lib#examples as an example, and my JavaScript looks pretty much the same as in the demo.
Tried with Safari and Chrome, on IOS versions 15.5 and 16.3, on all I get the same error.
Any help would be appreciated.

How to trigger `undefined is not a function` in modern broswers?

I remember getting this error a lot a while before. Today I wanted to show it to a friend unfamiliar with Javascript. Chrome and Safari instead gave me something like:
> const o = {};
< undefined
> o.doge()
< TypeError: o.doge is not a function (In 'o.doge()',' 'o.doge' is undefined)
Chrome and Firefox seem to be user-friendly as well.
How can I get an original error, without this helpful message?
You will never get that error in a modern browser; the error comes from js engine itself not the browser; and if there are no others other than that Type Error, modern engines will return a more developer friendly error by applying a (similar) /(w+)/ regex on what ever typed before () and placing it in the error message check out:
v8 (chrome) message templates that will make the error string (line 51, 52):
T(CalledNonCallable, "% is not a function")
and SpiderMoneky (mozilla) message templates (at line 51, 54):
MSG_DEF(JSMSG_NOT_FUNCTION, 1, JSEXN_TYPEERR, "{0} is not a function")
non-callable test case in v8 and a SpiderMokney test case .
So the only way to a undefined is not a function error message in a modern browser is doing undefined() :)
undefined()
you can just try to find and download an older version of the browser which logged the original error. (if that version is still publicly available).

Playing audio file returns "Uncaught (in promise)" but works in console

I'm trying to play audio files (I've tried many). All of them are mp3s.
I've tested the following on both MAMP localhost and also by just running it in the browser.
I use the following javascript:
var testSound = new Audio();
testSound.src = "a.mp3"
setTimeout(testSound.play.bind(testSound),100)
This returns the error:
Uncaught (in promise)
Trying to catch it:
var testSound = new Audio();
testSound.src = "a.mp3"
setTimeout(playSound,100)
function playSound () {
testSound.play().then(response => {
}).catch(e => {
console.log(e);
})
}
returns nothing ("")
But if I now turn to the console and simply type:
testSound.play()
The sound plays as it's supposed to.
Even if I comment the third line of the first code snippet like:
//setTimeout(testSound.play.bind(testSound),100)
Edit:
Even if people don't know what the solution is I'd still be interested to know if they can reproduce the error.
Edit 2:
By the way, the problem doesn't persist in Firefox or Safari.
If you read the full error message associated with the exception, you'll get a better explanation:
❌ Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first. https://goo.gl/xX8pDD
Google's article "Autoplay Policy Changes" (linked in the message above) explains the situation in detail.
The short version is: if you want to play audio or video, you need to wait to do it until the user has clicked something on the page.

Problems reading JSON file in D3 javascript in some (not all) browsers

I get this error in Chrome immediately after reading a JSON file. It works correctly in Safari and Firefox.
console.log ("event -> "+ postcards.nodes[0].node.event); // "tally" in Safari "TypeError: Cannot read property 'node' of undefined" in Chrome.<
Is there a limit to the levels in a nested JSON file? I generate the JSON from a Drupal view. Here here is the start:
{"nodes":[{"node":{"w1":"","w2":"1","w3":"","w4":"", ...<
Here is the Javascript:
d3.json(
"/sites/default/d3_files/json/toronto-wards.json",
function(error,wards) {
d3.json("/postcards-json", function(error, postcards) {
console.log ("event -> "+ postcards.nodes[0].node.event); // tally in Safari
I'm using macOS and my friends using Windows get the same error in Firefox.
As per request here is what I think is the XHR message:
d3.min.js:1 XHR finished loading: GET "http://www.stopplastics.ca/postcards-json".
Does the following work for you?
Promise.all(
d3.json("/sites/default/d3_files/json/toronto-wards.json"),
d3.json("/postcards-json")
)
.then(
function([wards,postcards]) {
console.log ("event -> "+ postcards.nodes[0].node.event); // tally in Safari
Some browsers may not support deconstructing arrays so probably better to try the following for older browsers (non Chrome and Firefox):
Promise.all(
d3.json("/sites/default/d3_files/json/toronto-wards.json"),
d3.json("/postcards-json")
)
.then(
function(results) {
var wards=results[0],postcards=results[1];
console.log ("event -> "+ postcards.nodes[0].node.event);
}
);
According to the comments your drupal end point providing the JSON needs authentication so gives you empty data when you're not loged in.
Error has maybe nothing to do with the browser used but depends if you're loged in or not.
The problem was caused by the Drupal view not being created correctly. Nothing to do with the Chrome browser.

SteemJS not working in Firefox/IE

I have a problem with connecting Steem using SteemJs https://github.com/adcpm/steem
Problem appears only on firefox browser, but Chrome Works correctly.
Our app is coded in Yii2 and JavaScript,
which works fully in front-end
<script src="//cdn.steemjs.com/lib/latest/steem.min.js"></script>
<script>
steem.broadcast.comment('5K8eZVEAMkfejyHxeQJ9R4wvrXowwz7kcxcTVwFGpeGq1x2iKRb',
'',
‘test',
'sci',
'this-is-a-test-article-2',
'this is a test article2',
'test',
'',
function(err, result) {
console.log(err, result);
});
Problem in the following process:
When running request to blockchain , it return null in Chrome.
Null is mean ok! so everything is fine
But when running on Firefox error occures:
Error: 3030000 tx_missing_posting_auth: missing required posting authority
Missing Posting Authority sci
…..
{"ops":[["comment", {"parent_author":"","parent_permlink":"test","author":"sci","permlink":"this-is-a-test-article-2","title":"this is a test article2","body":"test","json_metadata":"\"\""}]],"sigs": ["STM7x7kJhdKzu7gie8gPg5uUDNmLjbcXx7ek2H8UtKxH8qub3V2ut"]}
th_a transaction.cpp:172 verify_authority
Sigs here - is always different,but should be same and must be equal to public key from private: GLS8MfcHZyYioPBsmoYp8AZf4mbwZdsarunFRvuWUySqb3nwPeRwb.
In chrome it is working right key.
This is browser-compatibility problem, or browser feature problem
Please help identify a problem, and possible we can patch it or overcome in another way.
npm install adcpm/steem#dev
Just build it from develop branch and problem will solved. In lib folder you can find steem.min.js.

Categories