Chrome Extension - Content Script unable to find elements by class name - dom

I am attempting to access elements with a specific class name from a page using a content script of a Chrome extension. So far the content script can successfully find an element with a specific id using document.getElementById(), but using document.getElementsByClassName() or jQuery's $(".className") yields no results. For the sake of testing, I used 'header' as my class name and every website I ran the extension on resulted in an array length of 0. Any ideas what I might be missing? Here's what I have been testing with:
manifest.json
=================
{
"name": "Sample Extension",
"version": "0.0.1",
"description": "Sample extension",
"icons": {"128": "icon.png"},
"permissions": [
"tabs", "<all_urls>"
],
"browser_action": {
"default_icon": "browseraction.png",
"default_title": "Sample",
"popup": "popup.html"
},
"content_scripts": [
{
"matches": [ "<all_urls>" ],
"js": ["scripts/contentscript.js"],
"run_at": "document_end"
}
]
}
contentscript.js
===================
var elems = document.getElementsByClassName("header");
alert( elems.length );

Your code is very basic and straightforward, it can't be a cause of problem. In fact, I just used your exact code (with "says" class and website you provided) and alert() says every and each time 1 (which is correct).
My best guess is that you haven't reloaded your extension after making changes in contentscript.js OR some other extension is interfering and causing this strange behavior. Try disabling other extensions before testing your extension.

Related

How do I add extra syntax highlighting to an existing language?

I want to add some extra language features, such as liquid language support inside JavaScript:
var firstName = "<% User.firstName %>";
var lastName = "<% User.firstName %>";
I browsed around a bit and I found this folder in the vscode repository: https://github.com/microsoft/vscode/tree/main/extensions/javascript
It's basically the JavaScript tmLanguage grammar rules, so I had this idea to create a new javascript file format (.pjs) and apply the same tmLanguage file as well as add these new rules:
"pk-liquid-expression": {
"begin": "<%",
"beginCaptures": {
"0": {
"name": "storage.type.primitive.java"
}
},
"end": "%>",
"endCaptures": {
"0": {
"name": "storage.type.primitive.java"
}
},
"name": "storage.type.primitive.java"
},
And this worked, however now my pjs files don't have any of the language features such as errors and warnings.
I think my solution is not very forward-thinking however, so is it possible to just edit the current JavaScript tmLanguage rules and add these new tokens?
Thank you.
One solution is to inject the "liquid language" into the Javascript language definition. Main steps for that is to define a grammar to inject and creating a selector which defines when to inject your grammar:
{
"contributes": {
"grammars": [
{
"path": "./syntaxes/injection.json",
"scopeName": "todo-comment.injection",
"injectTo": ["source.js"]
}
]
}
}
See also: How to properly inject grammar extension in vscode (so it works)?

ADF CDM Source Transformation not reading data

I am having an issue with the inline data set for Common Data Model in Azure Data Factory.
Simply, everything in ADF appears to connect and read from my manifest file and entity definition - but when I click the "Data preview" button, I always get "No output data" - which I find bizarre, as the data can be read perfectly when using the CDM connector to the same files in PowerBI. What am I doing wrong to mean that the data is not read into the data preview and subsequent transformations in the mapping data flow?
My Manifest file looks as below (referring to an example entity):
{
"$schema": "CdmManifest.cdm.json",
"jsonSchemaSemanticVersion": "1.0.0",
"imports": [
{
"corpusPath": "cdm:/foundations.cdm.json"
}
],
"manifestName": "manifestExample",
"explanation": "example",
"entities": [
{
"type": "LocalEntity",
"entityName": "Entityname",
"entityPath": "folder/EntityName.cdm.json/Entityname",
"dataPartitions": [
{
"location": "folder/data/Entityname/Entityname.csv",
"exhibitsTraits": [
{
"traitReference": "is.partition.format.CSV",
"arguments": [
{
"name": "columnHeaders",
"value": "true"
},
{
"name": "delimiter",
"value": ","
}
]
}
]
}
]
},
...
I am having exactly same output message "No output data". I am using json not manifest. If i sink the source it moves no data but without error. My CDM originates from PowerBI dataflow. The PowerApps works fine but historization and privileges make it useless.
Edit:
On Microsofts info on preview feature we can find this
screen. I will make a guess that CDM the ADS sources is not the same which orignates from Power BI.

VS Code Spell Checker

I enabled the VS Code extension, "Code Spell Checker," and it works great. However, I wanted to include words from my custom dictionary file so the words in it aren't flagged as incorrect. I tried the following in my settings.json:
"cSpell.customUserDictionaries": [
"name": "Custom",
"description": "These are words from my custom dictionary.",
"path": "C:\\Users\\Joe\\Documents\\Custom.txt",
"addWords": false
],
But the words in Custom.txt are still marked as incorrect.
How can I configure Code Spell Checker so that it's able to load all the words in Custom.txt and ignore them?
According to their package.json that configuration is expecting a typeof array of objects, so the following should work:
"cSpell.customUserDictionaries": [
{
"name": "Custom",
"description": "My desc",
"path": "C:\\Users\\Joe\\Documents\\Custom.txt",
"addWords": false
}
],
And per their description:
File Format: Each line in the file is considered a dictionary entry

Create Entities and training phrases for values in functions for google action

I have created a trivia game using the SDK, it takes user input and then compares it to a value in my DB to see if its correct.
At the moment, I am just passing a raw input variable through my conversation, this means that it regularly fails when it mishears the user since the exact string which was picked up is rarely == to the value in the DB.
Specifically I would like it to only pick up numbers, and for example realise that it must extract '10' , from a speech input of 'my answer is 10'.
{
"actions": [
{
"description": "Default Welcome Intent",
"name": "MAIN",
"fulfillment": {
"conversationName": "welcome"
},
"intent": {
"name": "actions.intent.MAIN"
}
},
{
"description": "response",
"name": "Raw input",
"fulfillment": {
"conversationName": "rawInput"
},
"intent": {
"name": "raw.input",
"parameters": [{
"name": "number",
"type": "org.schema.type.Number"
}],
"trigger": {
"queryPatterns":[
"$org.schema.type.Number:number is the answer",
"$org.schema.type.Number:number",
"My answer is $org.schema.type.Number:number"
]
}
}
}
],
"conversations": {
"welcome": {
"name": "welcome",
"url": "https://us-central1-triviagame",
"fulfillmentApiVersion": 2
},
"rawInput": {
"name": "rawInput",
"url": "https://us-central1-triviagame",
"fulfillmentApiVersion": 2
}
}
}
app.intent('actions.intent.MAIN', (conv) => {
conv.data.answers = answersArr;
conv.data.questions = questionsArr;
conv.data.counter = answersArr.length;
var thisQuestion = conv.data.questions;
conv.ask((conv.data.answers)[0]));
});
app.intent('raw.input', (conv, input) => {
if(input == ((conv.data.answers)[0])){
conv.ask(nextQuestion());
}
app.intent('actions.intent.TEXT', (conv,input) => {
//verifying if input and db value are equal
// at the moment input is equal to 'my number is 10' (for example) instead of '10'
//therefore the string verification never works
conv.ask(nextQuestion());
});
In a previous project i used the dialogflow UI and I used this #system.entities number parameter along with creating some training phrases so it understands different speech patterns.
This input parameter I am passing through my conv , is only a raw string where I'd like it to be filtered using some sort of entity schema.
How do I create the same effect of training phrases/entities using the JSON file?
You can't do this using just the Action SDK. You need a Natural Language Processing system (such as Dialogflow) to handle this as well. The Action SDK, by itself, will do speech-to-text, and will use the actions.json configuration to help shape how to interpret the text. But it will only return the entire text from the user - it will not try to determine how it might match an Intent, nor what parameters may exist in it.
To do that, you need an NLP/NLU system. You don't need to use Dialogflow, but you will need something that does the parsing. Trying to do it with simple pattern matching or regular expressions will lead to nightmares - find a good system to do it.
If you want to stick to things you can edit yourself, Dialogflow does allow you to download its configuration files (they're just JSON), edit them, and update or replace the configuration through the UI or an API.

VS Code cpptools Debugging environment

I've been using vscode with cpptools from Microsoft. I've successfully attached the debugger (gdb) from the launch.json configuration to my project.
But I require to use the "environment": [] array to setup my project so I can start a new debugging session from within vscode. But I don't know the usage syntax for that array and the documentation doesn't cover that part.
I've figured out of parsing errors reported by vscode the first element it "Name". But what is the value tag? This at least doesn't work...
"environment": [
{
"Name": "LD_LIBRARY_PATH",
"Value": "/opt/mylibs",
}
]
How Do I've to fill this variable? Thank you
I've finally figured it out. My initial example was almost correct but needed to be lowercase... like this:
"environment": [
{
"name": "LD_LIBRARY_PATH",
"value": "/opt/mylibs"
}
]
https://code.visualstudio.com/Docs/editor/debugging suggests a format of
"env": {
"LD_LIBRARY_PATH": "/opt/mylibs"
},
In launch.vs.json, under the configurations, "env": { "LD_LIBRARY_PATH": "/your/path/to/lib" }