I am implementing PerformanceObserver to track 'first-paint' & 'first-contentful-paint'.
const observer = new PerformanceObserver((list) => {
for (const entry of list.getEntries()) {
if (typeof(Storage) !== 'undefined') {
if (entry.name === 'first-paint') {
localStorage.setItem(rumMetrics.RUM_METRICS_FIRST_PAINT, entry.startTime);
}
else if (entry.name === 'first-contentful-paint') {
localStorage.setItem(rumMetrics.RUM_METRICS_FIRST_CONTENTFUL_PAINT, entry.startTime);
}
}
else {
console.log('local storage is not supported here. RUM metrics won\'t be recorded.');
}
}
});
observer.observe({ entryTypes: ['paint'] });
This works perfectly in Chrome but throws an error in Firefox.
TypeError: The expression cannot be converted to return the specified type. (line: observer.observe({ entryTypes: ['paint'] });)
Update-1: 20th Apr 2018
Mozilla has confirmed the bug and it is affecting FF61 Nightly as well
Original Answer
Confirmed that this is a bug even in the developer version.
Below is the bug for the same
https://bugzilla.mozilla.org/show_bug.cgi?id=1454581
Related
in Strapi 4.0, i want to validate the input before saving. So i created lifecycles.js file as per the documentation and added the code:
module.exports = {
beforeCreate(event) {
//validation login here;
if (!valid) {
throw strapi.errors.badRequest('Invalid Entry');
}
},
}
How ever throw strapi.errors.badRequest('Invalid Entry'); is giving an error :
Cannot read property 'badRequest' of undefined
My guess is the Strapi v4 changed it from version 3. I looked everywhere but couldn't find a solution.
Any idea on how to handle error in lifecycles.js?
I had a similar situation with a forbidden error. I got to do it importing a class from #strapi/utils/lib/errors.js
const { ForbiddenError } = require("#strapi/utils").errors;
...
if (!authorized) {
throw new ForbiddenError(errorMessage);
}
You can show the list of errors based on your requirement
const { ValidationError } = require("#strapi/utils").errors;
...
if (formValidationError) {
throw new ForbiddenError("Fill the form");
}
Strapi comes with a lot of error response functions here are they
HttpError,
ApplicationError,
ValidationError,
YupValidationError,
PaginationError,
NotFoundError,
ForbiddenError,
PayloadTooLargeError,
UnauthorizedError,
PolicyError,
I am building an app in React-Native and need to have location access as per the requirement.
I have tried using react-native-fused-location for the same, as below.
FusedLocation.setLocationInterval(20000);
FusedLocation.setFastestLocationInterval(15000);
FusedLocation.setSmallestDisplacement(10);
FusedLocation.setLocationPriority(
FusedLocation.Constants.HIGH_ACCURACY
);
FusedLocation.startLocationUpdates();
FusedLocation.getFusedLocation().then(location => {
if (location != null) {
let initialPosition = JSON.stringify(location);
this.state.latitude = location.latitude;
this.state.longitude = location.longitude;
this.state.timestamp = location.timestamp;
this.state.initialPosition = initialPosition;
} else {
alert("Location unavailable, please try later");
}
}).catch(error => { // fused location catch
console.log("location retrieval failed");
});
The only output, I am receiving with the above code, in case of Oreo 8.0.0 is E/request: 100.
also tried the other way as below
navigator.geolocation.watchPosition(
location => {
console.log("inside watchPosition location");
if (location != null) {
console.log("location is not null");
let initialPosition = JSON.stringify(location.coords);
this.state.latitude = location.coords.latitude;
this.state.longitude = location.coords.longitude;
this.state.timestamp = location.coords.timestamp;
this.state.initialPosition = initialPosition;
} else {
alert("Location unavailable, please try later");
}
},
error => {
console.log("calling ShowHideActivityIndicator, getLocationWithNavigate (ios)");
this.ShowHideActivityIndicator(false);
alert("location retrieval failed");
console.log(error);
},
{ timeout: 20000, enableHighAccuracy: true, distanceFilter: 10 }
);
But getting same output in both of the above codes, that is unable to get the location specifically in Android Oreo 8.0.0. Even the location retrieving callback is not even called. Though in other versions, including Oreo 8.1.0, and lower version devices, including Marshmallow and Nougat, it seems working fine.
Though, if I turn on the fake GPS in Oreo 8.0.0, then it seems to be able to get the location. I am unable to figure out, what I am missing.
mention to google document:
In an effort to reduce power consumption, Android 8.0 (API level 26) limits how frequently background apps can retrieve the user's current location. Apps can receive location updates only a few times each hour.Background Location Limits
I get the following error in firefox (no problems in Chrome / Edge / Safari):
MediaStreamError { name: "AbortError", message: "Starting video failed", constraint: "", stack: "" }
Browser console only shows < unavailable > when this error is thrown.
I am using adapter-latest.js from webrtc.github.io and the code works perfectly well on other pages within my application but not in one particular page. Is there a possibility to find out, what interferes with getUserMedia? I allready tried commenting out all other libraries and includes.
My code is:
var video = document.getElementById('recorder');
video.onloadedmetadata = function(e) {
$("#takePicture").show();
if($("#customerImage").attr("src") == ""){
$("#recorder").show();
}
};
navigator.mediaDevices.getUserMedia({ video: true})
.then(stream => {
video.srcObject = stream;
})
.catch(e => console.log(e));
I was facing this issue because I had Chrome also running the same app and using the webcam. So basically the webcam was already in use and I was trying to access it via Firefox too.
Are you really sure that you need adapter? In my experience it makes more problems than it solves.
Can you try to use constraints?
Example (I removed some things, but it works like a charm here):
constraints = {
width: 1280,
height: 720,
frameRate: 10, //mobile
facingMode: {
exact: "environment"
} //mobile
}
navigator.mediaDevices.getUserMedia({
audio: false,
video: constraints
}).
then(handleSuccess).catch(handleError);
function handleSuccess(stream) {
video.src = URL.createObjectURL(stream);
video.play();
}
function handleError(error) {
console.log('navigator.getUserMedia error: ', error);
}
The following code, executing on a chromebook with Chrome version 59.0.3071.134 (Official Build) (64-bit) is generating "Uncaught TypeError: navigator.bluetooth.getAvailability is not a function". Any idea why?
bluetoothle.checkBluetoothAvailable = function() {
console.log("checkBluetoothAvailable");
navigator.bluetooth.getAvailability().then(isAvailable => {
document.getElementById('btn_discover').hidden = !isAvailable;
if (!isAvailable) {
document.getElementById('message').innerHTML = 'Bluetooth is not available';
}
});
navigator.bluetooth.addEventListener('availabilitychanged', e => {
document.getElementById('btn_discover').hidden = !e.value;
if (!e.value) {
document.getElementById('message').innerHTML = 'Bluetooth is not available';
} else {
document.getElementById('message').innerHTML = 'Bluetooth is available';
}
});
}
getAvailability is not implemented. It is specified, so it makes sense to try it and expect it to work.
https://github.com/WebBluetoothCG/web-bluetooth/blob/gh-pages/implementation-status.md lists what has been implemented in more detail.
And, in the specification you will find the background of some sections such as getAvailability include "This section is not stable." and background text "Unstable".
I use the following code from (https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia):
navigator.mediaDevices = navigator.mediaDevices || ((navigator.mozGetUserMedia || navigator.webkitGetUserMedia) ? {
getUserMedia: function(c) {
return new Promise(function(y, n) {
(navigator.mozGetUserMedia || navigator.webkitGetUserMedia).call(navigator, c, y, n);
});
}
} : null);
to setup the microphone for use. This works great in Chrome (v45) and Firefox (v36), but in Firefox (v41) I get the following error in the console:
Error: setting a property that has only a getter
RecorderSvc.initAudio#http://fakewebsite.com/js/services/recorder.js:61:1
I can solve the problem by doing:
if (navigator.mozGetUserMedia || navigator.webkitGetUserMedia) {
navigator.mediaDevices.getUserMedia = function(c) {
return new Promise(function(y, n) {
(navigator.mozGetUserMedia || navigator.webkitGetUserMedia).call(navigator, c, y, n);
});
}
}
but this doesn't work in Chrome or Firefox (v36).
In Chrome, only navigator.webkitGetUserMedia is defined.
In Firefox (v36), only navigator.mozGetUserMedia is defined.
In Firefox (v41), both navigator.mozGetUserMedia AND
navigator.mediaDevices are defined.
I can't figure out how to fix this without breaking one of the browsers. Any ideas?
The code you've copied (which I wrote incidentally) does a lousy job trying to polyfill navigator.mediaDevices.getUserMedia into browsers that don't have it natively yet. It has since been removed from where you found it. Thanks for spotting that it's broken.
Polyfilling is tricky business, so I highly recommend using adapter.js, the official WebRTC polyfill, instead of attempting to shim it manually. You can use a recent version of adapter.js, or link to the always latest one directly, like this:
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
See https://jsfiddle.net/srn9db4h/ for an example of this that works in the browsers you mention.
I wont try to correct the code you mention, because polyfilling navigator.mediaDevices correctly got quite complicated.
It's also insufficient, because the location of getUserMedia isn't the only thing that has changed in the specification. The format of the constraints argument has changed as well, which is why navigator.mediaDevices.getUsermedia is still behind an experimental flag in Chrome 45.
adapter.js takes care of all this until the browsers catch up.
If you surround your statement in a Try Catch block, it'll work.
if (navigator.mediaDevices || (navigator.mozGetUserMedia || navigator.webkitGetUserMedia)) {
try {
navigator.mediaDevices = {
getUserMedia: function(c) {
return new Promise(function(y, n) {
(navigator.mozGetUserMedia || navigator.webkitGetUserMedia).call(navigator, c, y, n);
});
}
};
}
catch(err) {
navigator.mediaDevices.getUserMedia = function(c) {
return new Promise(function(y, n) {
(navigator.mozGetUserMedia || navigator.webkitGetUserMedia).call(navigator, c, y, n);
});
}
}
} else {
navigator.mediaDevices = null;
}