I'm currently trying to grab a value from an electron-json-storage database and return it.
function getWithExpiry(key) {
var grabbed = "";
storage.has(key, function (error, hasKey){
if (error) throw error;
if (hasKey){
storage.get(key, function (error, data){
if (error) throw error
const item = JSON.parse(data)
const now = new Date()
if (now.getTime() > item.expiry) {
storage.remove(key, function (error) {
if (error) throw error
grabbed = null
})
}else{
console.log(item.value)
grabbed = item.value
}
})
}
})
console.log(grabbed)
return grabbed;
}
I'm calling it with this:
setTimeout(async () => {
var tokenpass = getWithExpiry('captcha')
console.log(tokenpass)
await page.evaluate((tokenpass) => {document.getElementById("g-recaptcha-response").innerText = `${tokenpass}`}, tokenpass)
await page.click('input.button').then(console.log('Clicked'));
The console.logs return in a different order than called. First it returns "" from console.log(grabbed) in getWithExpiry(key), then "" from console.log(tokenpass), then console.log('Clicked'), then the expected value from console.log(item.value). I think the order of these console.logs might be the reason why getWithExpiry doesn't return item.value.