How do I run my custom code in Chrome DevTools? - javascript

I open Chrome DevTools for a remote web site (not my localhost) and select "Add folder for workspace" under "Sources". In the added folder I have a few .js files.
When I try to execute a function from one of the files in the console, eg. the function "myMethod", I get "Uncaught ReferenceError: myMethod is not defined".
How do I run my own code-files side by side with the ones already loaded into the browser?

Adding a folder to Chrome Devtools allows you to edit files from chrome, but it doesn't include them to the current web page at all. To do that, you have to actually paste the code in the console, or append a new script node referencing the file. But this has nothing to do with Chrome Devtools.
document.body.appendChild((s=document.createElement('script'),s.src='myfile.js',s));
(replace myfile.js with the complete path to the file on your pc)

Related

Unable to launch browser: "spawn C:\Program Files\Google\Application\chrome.exe ENOENT"

Just making a simple HTML, CSS and JavaScript web app in Visual Studio code.
Trying to run and debug so I can test it in the browser (Chrome).
It automatically made a launch.json file for me - the default config didn't work so I changed the route to this: "webRoot": "${workspaceRoot}/index.html" - thinking all would be fixed!
Now I'm getting a completely different error:
Unable to launch browser: "spawn C:\Program Files\Google\Application\chrome.exe ENOENT"
Tried changing JSON file configuration.
Checked where chrome was installed - file location matches.
Was expecting the file to be debugged and index.html to open in my Chrome browser.
enter image description here

Can't download a pdf file in npx cypress run --headed mode?

Hope to get some help with what is my first question to the community...
I'm using the Tricentis Sample App to practice some testautomation with Cypress (javascript) and I'm having issues with the final step. (Downloading the mock invoice and checking the presence of it in the downloads folder)
//This function displays the "download pdf" button
function selectPriceOption(cy){
cy.get('#selectplatinum').check({force:true})
}
//this function is supposed to download the pdf
function downloadQuote(cy){
cy.wait(2000)
cy.get('#downloadquote').click()
cy.wait(20000)
}
//This function checks if file exists in the download folder
function checkFileExists(cy){
cy.readFile('C:/xxx/Documents/cypress/downloads/Tricentis_Insurance_Quote.pdf')
}
module.exports = {
enterAutoPage,
enterVehicleData,
enterInsuranceData,
enterProductData,
selectPriceOption,
checkFileExists,
downloadQuote
//sendQuote
}
When I'm running the script on npx cypress open mode, it downloads the pdf generated without a hitch. But as soon as I use npx cypress run --headed it doesn't manage to download the pdf file and as a consequence the test case throws a fail... Btw, I know the cy.wait command is not needed, it was just my last attempt to see if it needed additional waiting time. Still didn't work!
Now, here's what bugs me... If I run the script in open mode first, the download is successful and if I then go for the "run --headed" mode afterwards, it finds the file! I'm running trashAssetsBeforeRuns: false in the config file. So the check file function is working as intended. But when the folder is empty and I only use --headed mode then the download is NOT successful and the test case fails due the file is missing when the script reaches the last test step. I hope this explanation makes sense... #newbietechnicaltester
PS: Leaving the possibility open to something funky going on with the Tricentis site that is causing the code to not work as intended

Flutter Web App Source Map not loading in Chrome (http error 404)

I have built a flutter web app using the command:
flutter build web --release --source-maps
I am running this app on localhost and also on cloud (GCP Cloud Run). In both cases, the web app throws exceptions which are logged in the Chrome Developer Tools console within the file main.dart.js. The main.dart.js file is a minified/compiled file (low-level & unreadable) and I can't debug the errors logged within in. To debug the errors, I need Chrome to point the location of errors in my source code.
This should be accessible using Source Maps. My web app has source maps enabled and I can see all my source code directories and files in Chrome Devtools > Sources. However, when I click on any .dart file within the listed Sources, all I see is:
Could not load content for http://localhost:3000/lib/main.dart (HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE)
I have the same error (404) in both cloud & localhost builds, for all source code .dart files
My minified/compiled Javascript file main.dart.js has this source map link attached at the bottom:
//# sourceMappingURL=main.dart.js.map
I also have Enable Javascript source maps setting enabled within Chrome Devtools.
Here's an image of the problem:
404 error when viewing source maps
How do I fix this?
Thanks!

Problem running same script in different platforms(Termux and Windows)

I'm trying to run my server script on nodejs through Termux on my phone and normally on windows. On windows it all runs perfectly without erros, but on termux there's an error "Cannot find module gameserver.js", even though that is the main file(I'm running "sudo node gameserver.js" inside the folder its locatedd), and no other file tries to do a require on it.
The error points to js files from node itself(loader.js, run_main.js and run_main_module.js). I've given termux root access, and I run node.js using sudo, so I've no clue what could be happening. I've no .json file since I'm just trying to run a js file through node on my phone. Both windows and my phone are using the same node.js version
Did you try to give an absolute path to your file as a parameter? It could happen if working directory has changed (because of sudo?).

Parcel server localhost:1234 does not work

I have Parcel installed to compile my javascript files. According the documentation I run parcel index.php commnad and tried to open localhost:1234 in the browser. No error in console only success message server is running on localhost:1234. But as I open the address I have 404 This localhost page can’t be found. What am I doing wrong?
Also if I try to use it like file watcher for index.js it works only for the first code update. Any other chages are not reflected in the result html..

Categories