chrome.hid.getDevices() typeError - javascript

I use this"https://github.com/GoogleChrome/chrome-app-samples/tree/master/samples/hid " The following error occurred
Uncaught TypeError: Cannot read property 'getDevices' of undefined
at enumerateDevices (control-panel.js:55)
at initializeWindow (control-panel.js:42)
Is the chrome version a new issue? How do I modify it to use the new chrome?
var enumerateDevices = function() {
chrome.hid.getDevices({}, onDevicesEnumerated);
chrome.hid.onDeviceAdded.addListener(onDeviceAdded);
chrome.hid.onDeviceRemoved.addListener(onDeviceRemoved);
};

Related

OpenLayers parsing GeoJSON error 'Uncaught TypeError: feature.getId is not a function'

With the following code i am trying to get coordinates from polygon drawing on map but i get this console error instead "Uncaught TypeError: feature.getId is not a function"
const drawInteraction = new Draw({
type:'Polygon',
freehand:true
})
map.addInteraction(drawInteraction);
drawInteraction.on('drawend',function(e){
let parser= new GeoJSON();
let drawnFeatures = parser.writeFeatureObject([e.feature]);
console.log(drawnFeatures);
})
Actually i found the error it is
let drawnFeatures = parser.writeFeatures([e.feature]);
and not
let drawnFeatures = parser.writeFeatureObject([e.feature]);

Getting Uncaught TypeError: Cannot read properties of undefined (reading 'then') while working with Javascript Promise

I declare a window promise where I get a response and stor it in a JS ojbect. The script does not get executed. I am getting an error while working with the Javascript promise:
Cannot read properties of undefined (reading 'then')
window.promise.then(function(response) {
var jsObject = JSON.parse(response);
if (jsObject.enableEmailVerificationOnRegistration) {
alert('hii enable verification tggle is on')
var signUpClick = document.getElementById("registrationSignUp");
signUpClick.addEventListener('click', function(e) {
event.preventDefault();
var getPdpUrl = window.parent.location.pathname;
document.getElementById("pdpUrlValue").value = getPdpUrl;
localStorage.setItem("currentPdpPath", getPdpUrl);
window.location.href = getPdpUrl;
});
}
});

js: TypeError: Cannot read property 'replace' of undefined using

I wanted to replace /\r?\n|\r/g with empty string but got a type error "Cannot read property 'replace' of undefined".
export function getCupsCredentials() {
var vcap_services = process.env.VCAP_SERVICES;
var vcap_servces_as_single_line = vcap_services.replace(/\r?\n|\r/g, " ");
var vcap_servces_as_json = JSON.parse(vcap_servces_as_single_line)
var vcap_servces_user_provided = vcap_servces_as_json['user-provided']
var cups_credentials = vcap_servces_user_provided[0].credentials;
return cups_credentials;
}
i got the following error message on using .replace
TypeError: Cannot read property 'replace' of undefined
at getCupsCredentials (/app/ui/dist/webpack:/src/utils/VcapUtils.js:4:50)
at Object.defineProperty.value (/app/ui/dist/webpack:/src/utils/IAMUtils.js:5:17)
at __webpack_require__ (/app/ui/dist/webpack:/webpack/bootstrap 713b700ecf31:19:1)
at Object.defineProperty.value (/app/ui/dist/webpack:/src/api/middleware/filters/authFilter.js:1:1)
at __webpack_require__ (/app/ui/dist/webpack:/webpack/bootstrap 713b700ece831:19:1)
at Object.<anonymous> (/app/ui/dist/webpack:/src/api/middleware/pre.js:1:1)
at __webpack_require__ (/app/ui/dist/webpack:/webpack/bootstrap 713b70031:19:1)
at Object.defineProperty.value (/app/ui/dist/webpack:/src/api/middleware/index.js:1:1)
at __webpack_require__ (/app/ui/dist/webpack:/webpack/bootstrap 713b700ececf31:19:1)
at Object.canUseDOM (/app/ui/dist/webpack:/src/server.js:4:1)
Starting Conductor UI
using Conductor API server from 'http://chand-wf-nfce-server.cloud.pcftest.com/api'
/app/ui/dist/webpack:/src/utils/VcapUtils.js:4
var vcap_servces_as_single_line = vcap_services.replace(/\r?\n|\r/g, " ");
If these values are getting fetched from a remote server then the case might be that you are trying to replace the characters before the data is assigned to the variable. Try using await functions or the .then() And also replace as such var vcap_servces_as_single_line = vcap_services?.replace(/\r?\n|\r/g, " ");
So that the code will not scream at you if you have an undefined value.
The most probable cause is that your process.env.VCAP_SERVICES is not initialized properly and it is initializing your vcap_services with undefined. As the replace method does not work with undefined thus that error.
Try checking if vcap_services is empty or not by the ternary operator
export function getCupsCredentials() {
var vcap_services = process.env.VCAP_SERVICES;
var vcap_servces_as_single_line = vcap_services
? vcap_services.replace(/\r?\n|\r/g, " ")
: "vcap_servisec is empty";
console.log(vcap_services);
/*
var vcap_servces_as_json = JSON.parse(vcap_servces_as_single_line)
var vcap_servces_user_provided = vcap_servces_as_json['user-provided']
var cups_credentials = vcap_servces_user_provided[0].credentials;
return cups_credentials;
*/
}

Failed: Cannot read property 'results' of undefined

Snippet for taking screenshot on Test Failure
afterEach(function() {
var spec = jasmine.getEnv().currentSpec;
var passed = spec.results().passed();
if (!passed) {
browser.takeScreenshot().then(function(png) {
writeScreenShot(png, "screenshot.png");
});
}
function writeScreenShot(data, filename) {
var stream = fs.createWriteStream(filename);
stream.write(new Buffer(data, 'base64'));
stream.end();
}
});
Console error
Message:
Failed: Cannot read property 'results' of undefined
Stack:
TypeError: Cannot read property 'results' of undefined
at Object.<anonymous>
it returns undefined here,
var spec = jasmine.getEnv().currentSpec;
console.log(spec);
Looks like issues due to Jasmine 2; any alternate solutions also welcome! I use Jasmine 2
As of Jasmine 2.0, env.currentSpec is no longer supported.
https://github.com/jasmine/jasmine/issues/1212
"var spec" is not being set to anything. That means "jasmine.getEnv().currentSpec" is not working for whatever reason.

TypeError: undefined is not an object error

I have this code, which is throwing a TypeError. I can't find what the problem is.
Code
/ Topic Banners - swap out mobile ads
if ($('#advertisment-main').length){
if (matchMedia('(min-width: 768px)').matches) {
var topicBannerName = $('.topic-banner[src*="mobile"]').attr('src').replace('mobile.jpg','');
$('.topic-banner').attr('src', topicBannerName + 'tablet.jpg');
} else{
var topicBannerName = $('.topic-banner[src*="tablet"]').attr('src').replace('tablet.jpg','');
$('.topic-banner').attr('src', topicBannerName + 'mobile.jpg');
}
}
Error
TypeError: undefined is not an object (evaluating '$('.topic-banner[src*="tablet"]').attr("src").replace')
That's because your selector $('.topic-banner[src*="tablet"]') doesn't match any elements. Make sure that the selector and HTML code is correct.

Categories

Resources