Chrome extension Unexpected Identifier in Content Script - google-chrome-extension

I have a problem. I cannot access variable that I created in content script in chrome console.
Here are my my codes.
Content script code:
var data = []
var x = document.querySelector('div.A3dMNc').innerText
var y = document.querySelector('span.ryNqvb').innerText
if data.includes(x){
console.log('alreade included!!!')
} else {
data.push({ "surah": x, "maksud": y })
console.log(x + ' --> ' + y)
console.log(data)
console.clear()
}
I got error:
Uncaught SyntaxError: Unexpected identifier 'data' (at script.js:7:6)
I want to collect data into the array of data.

Related

nodejs cookie-session typeerror

TypeError: this.keys.index is not a function
the console log show that the if condition line is error
app.get('/',(req,res)=>{
if(!req.session.authenticated){
res.redirect('/login');
}else{
res.redirect('/search')
}
})
it was fine until i start another server.js from a completely different folder. I have tried to reinstall the node_module to fix it but it just result the same. but the weird part is i can start the server in a vm without any problem. can any help me with this?
Cookies.prototype.get = function(name, opts) {
var sigName = name + ".sig"
, header, match, value, remote, data, index
, signed = opts && opts.signed !== undefined ? opts.signed : !!this.keys
header = this.request.headers["cookie"]
if (!header) return
match = header.match(getPattern(name))
if (!match) return
value = match[1]
if (!opts || !signed) return value
remote = this.get(sigName)
if (!remote) return
data = name + "=" + value
if (!this.keys) throw new Error('.keys required for signed cookies');
index = this.keys.index(data, remote)
if (index < 0) {
this.set(sigName, null, {path: "/", signed: false })
} else {
index && this.set(sigName, this.keys.sign(data), { signed: false })
return value
}
};
I realise that this answer is late in the day but might help someone with the same error. I was getting the error 'TypeError: this.keys.index is not a function' on line 73 of index.js in cookies when trying to use koa-session.
I eventually realised that I had set app.keys to a single value i.e.
app.keys = 'dieueyf7huienejnfef'
When it should be an array:
app.keys = ['dieueyf7huienejnfef']

Invalid or unexpected token at new Function of Enumerable using linqjs

I want to return an object using Enumerable of linqjs. But this code gives an error "Invalid or unexpected token". When I check the same condition using if condition in forEach then it is working perfectly. But what's problem with Enumerable?
Using Linqjs
var checkAddressForUpdate = Enumerable.From($scope.companyAddresslist).Where("$.Address === '" + $scope.ad_CompanyAddress.Address + "' && $.SlNo !== " + $scope.ad_CompanyAddress.SlNo).FirstOrDefault();
Using If Condition
var checkAddressForUpdate;
angular.forEach($scope.companyAddresslist, function (comAddress) {
if (comAddress.Address == $scope.ad_CompanyAddress.Address && comAddress.SlNo != $scope.ad_CompanyAddress.SlNo) {
checkAddressForUpdate = comAddress;
}
});
Error in console
enter image description here

Problem Utf-8 decoding nodejs - Invalid continuation byte at readContinuationByte

I'm developping a nodejs server and i want to convert a csv file to a json file. I succeed this part, but on of my data ( the libelle_etape is not on a good format (utf8), the values are like: 'EII/MEA 5ème année' or 'Geau/STE 4ème année' etc...). So in my function i would like to decode those values to have the right format on my json file.
I have the result that i want when i do :
const result= utf8.decode(str)
BUT the problem is : when i want to remplace the old String that i have in my csv file (this one : "EII/MEA 5ème année") by the good one (result = "EII/MEA 5ème année") I have the following error :
*Unhandled rejection Error: Invalid continuation byte
at readContinuationByte *
The entire code is :
CSVToJSON()
.fromFile('./infoEtu.csv')
.then((source) => {
const oneData = source[0];
for (let i = 0; i < source.length; i++) {
for (let j = 0; j < Object.keys(source[i]).length; j++) {
const columnName = Object.keys(source[i]);
columnName.forEach((element) => {
if (element == 'Libelle_etape') {
const str = source[i]['Libelle_etape'];
const result = utf8.decode(str);
console.log(result); // this line show me the good result
source[i]['Libelle_etape'] = String(result); // this line is definitely the problem , i've tried with and withou de String() methods but it's the same error
}
});
}
}
const data = JSON.stringify(source);
FileSystem.writeFileSync('./jsonEtu.json', data);
});
Thank you in advance for your help, i'm searching for a long time now and i can find the same problem anywhere.
UPDATE :
The problem was because of the accents !
By doing that it's working :
const result = accents.remove(utf8.decode(str));
source[i]['Libelle_etape'] = result;

Firebase - Cloud Functions: enumerate [Object Object]

I would like to enumerate the members object from the below structure.
I do not have prior experience in node.js, I have tried the following code and it doesn't seem to work.
exports.sendVaultUnlockedPush = functions.database.ref('/Vaults/{id}/action').onUpdate(event => {
let status = event.data.val();
if (status == 'lock') {
var db = admin.database();
var vaultRef = db.ref("/Vaults/" + event.params.id);
vaultRef.once('value').then(function(snapshot) {
var hasMembers = snapshot.child('members');
if (hasMembers) {
var memberRef = db.ref("Vaults/" + event.params.id + "/members");
memberRef.once('value').then(function(memberSnapshot) {
memberSnapshot.forEach(function(element) {
console(element.key + " - " + element.val());
}, this);
});
}
});
}
})
It throws the following error:
Error: Firebase.DataSnapshot.forEach failed: Was called with 2 arguments. Expects no more than 1.
at Error (native)
at z (/user_code/node_modules/firebase-admin/lib/database/database.js:42:1666)
at T.forEach (/user_code/node_modules/firebase-admin/lib/database/database.js:114:179)
at /user_code/index.js:34:36
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
I would just like it to return the value of 'members' node. And I have no clue to do the same.
Any help is much appreciated in getting this sorted. Thanks!
According to the docs forEach takes only one parameter:
This should work:
var values;
memberSnapshot.forEach(function(element) {
console(element.key);
values = element.val();
for (var val in values) {
if (values.hasOwnProperty(val)) {
console(val, values[val]);
}
}
});
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in

Chrome Extension breaks Google Sheets

I'm working on a chrome extension to log analytics for my use of Google Drive. I've used a webNavigation.onCompleted.addListener function to send analytics a page view, and it all works properly, except when it comes to sheets.
I'm gettting an intermittent failure to load sheets properly. However, nothing logs in the extension's console as an error - it shows everything is working properly. In the console for the sheet I'm trying to load, I'm getting two strange errors popping up.
The first (in all its glory) is:
Uncaught TypeError: Cannot read property 'setTimeout' of undefined
Mfb # 2046562200-ritz_waffle_i18n_core.js:2745
pN # 2046562200-ritz_waffle_i18n_core.js:2746
ggb # 2046562200-ritz_waffle_i18n_core.js:2757
fxb # 2046562200-ritz_waffle_i18n_core.js:3558
r.load # 2046562200-ritz_waffle_i18n_core.js:3555
loadWaffle # edit:163
w2b # ritz-0.js:1465
KGb # ritz-0.js:990
g # ritz-0.js:2
jC # ritz-0.js:649
mC # ritz-0.js:652
(anonymous function) # ritz-0.js:651
AGb # ritz-0.js:3
(anonymous function) # ritz-0.js:7622
(anonymous function) # VM3274:1
m # edit:110
(anonymous function) # edit:111
d # edit:107
(anonymous function) # edit:108
And the second is:
Uncaught TypeError: Cannot read property 'Yu' of undefined
r.jLa # 2046562200-ritz_waffle_i18n_core.js:361
I'm having trouble understanding what's creating this problem. My code isn't modifying any headers, and only triggers once web navigation is complete. Here's the function that seems to be causing this issue:
chrome.webNavigation.onCompleted.addListener(
// callback
function(info) {
console.log("webNavigation Complete - Docs");
console.log(info.url);
var fields = { hitType:'pageview'};
chrome.pageAction.show(info.tabId);
// check for editor of docs, sheets, slides, etc.
if (info.url.indexOf('docs') > -1 && info.url.indexOf('/d/') > -1) {
var start = info.url.indexOf('.com/')+5;
var end = info.url.indexOf('/',start+1);
var type = info.url.substring(start,end);
start = end+2;
end = info.url.indexOf('/',start+1);
var docId = info.url.substring(start,end);
fields['page'] = docId;
ga('send','event',type,'Load');
}
// check for editor of docs, sheets, slides, etc.
if (info.url.indexOf('macros') > -1 && info.url.indexOf('/d/') > -1) {
console.log('Apps-Script');
ga('send','event',type,'Apps-Script');
}
if (info.url.indexOf('drive') > -1 ){
fields['page'] = '/drive';
}
if (fields.page) {
var tabId = info.tabId;
chrome.pageAction.show(tabId);
chrome.tabs.get(tabId,function(tab) {
fields['title'] = tab.title;
console.log(fields);
//ga('send',fields);
});
}
},
//filters
{url:[{hostContains:'docs.google.com'},
{hostContains:'drive.google.com'}]
});

Resources