how to view source code for javascript src - javascript

I apologize in advance if this question is not appropriate for this forum. I could not find answers from searches in Google or Stackexchange. Also, because the question was specific, I thought I might be acceptable.
Background:
The end purpose is to troubleshoot a server connection error where a client machine runs javascript. I'm trying to at least determine the source and destination network ports used for the communication attempt.
I know zero javascript but have some background in C++.
The client runs this html page:
<script type="text/javascript" language="javascript" src="com.vmware.vim.cimmonitor.gwt.CimUi.nocache.js"></script>
Is there a way to view the contents of the specific js file? I cannot tell if the js file is bundled locally in some kind of javascript library or resides somewhere in vmware.com
I've tried to directly enter the full js name into firefox, but got a server not found error.
Thanks.

Press F-12 to open the browser's debugger. Open the NETWORK section. Reload the page. It will show you a complete list of resources as they are loaded. You can click on any of these to look at the source and http header information.
Unless the js code is using websockets, communication is likely just http:// on port 80.

if you use the developer console in chrome/safari, you can view all loaded javascript in the resources tab.
you can also use netstat to see what active port connections you have.

Related

React Browser Error (MIME Type not Executable)

I am following a basic tutorial for a react app and was hit with this error in the browser.
"Refused to execute script from
'http://localhost:8080/bundle.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled."
I cannot find any support online for this error and would like to understand what the problem is. I have spent about 2 hours trying to debug. One forum mentioned it was in-browser cookies but this was not the problem. I believe it may be something to do with my index.html file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ReactJS Sample Project</title>
</head>
<body>
<div id="root"></div>
<script type="text/javascript" src="bundle.js"></script>
</body>
</html>
Let me know if you have any ideas! I am relatively new to coding and it is frustrating hitting a dead end so early in a project.
The browser is asking the server to give it bundle.js.
Then the server is responding with "Here is bundle.js, it is an HTML document".
This means one of two things:
It is an HTML document (with an odd URL)
It is a JS file, but the server thinks that it is HTML
The first thing to do is to look at the data in the file. You could do this by looking at the Network tab in the developer tools in your browser.
If it is JS, then you need to fix your server so it sends the correct Content-Type header for JavaScript (application/javascript).
If it isn't JS, you need to figure out why. Possibly you have the wrong URL. Possibly the server isn't set up so it can serve your JS at all.
Whatever the problem, you will need to examine your HTTP server more than the client side code you shared in the question.
If you are developing a single page HTML5 application then chances are the default server is configured to send index.html back for every resources not found instead of 404 to enable full page refresh for every virtual path in your application. Now if bundle.js is not present for any reason, then you get back a legitimate html response. You have to debug your application, or at least tell us more details about what you are using.
To debug your application, open the developer tools, go to the network panel, and refresh the page to see the resources being loaded.
This problem appears to occur when a package manager like npm is used. The following stack overflow answer solved the problem for me. You need to just use the CDN link to the library using tag.
How to use Tesseract.js in a React app
If you open the Network tab in Developer tools and look at the error (might be in the Headers tab within Network) what URL do you see that it is attempting to obtain the bundle.js file from. The answer may be as simple prefixing bundle.js with a slash (i.e. src="/bundle.js") if you are using client-side routing.

Cloudflare - PHP and Javascript Includes not Working

Since implementing Cloudflare some of my includes aren't working.
One specific example: Inside the includes folder, I have a sub folder "texter". Here I have a php page that references a Javascript library in the same folder. The page receives a GET request with variables, then parses on the parameters to an external 3rd party API.
When Cloudflare is disabled/paused the mini app works.
I'm using Page Rules to disable Cloudflare activity for my includes folder but it's still not working.
e.g. Pattern: *mysite.com/includes/* - With all rules and chache set to disabled.
How can I get my web app running while Cloudflare is also running? Am I on the right track? Thanks in advance.
Edit: I'm using htaccess to limit direct access to these directories... could this cause an issue?
Hmmm...this goes away with us paused? Do you have something like Rocket Loader turned on in your performance settings (can potentially impact jQuery or JavaScript).
Do any error messages appear at all?

Trick a browser into loading <script> or <link rel="stylesheet"> URLs from local setup/server?

I'm debugging a CSS/JS problem on a live website, and in this situation it is unfeasible to clone the entire production system onto a local machine to fiddle with 2 lines of code.
I would LOVE it if there were a simple way to trick a browser (FF, Chrome, anything - I'm not fussy) into loading the live site but redirecting certain internal URLs to a local webserver. Any ideas?
eg. I want to load the entire live website, except one specific Javascript file. The attempt to access http://...production.../js/map.js should be rerouted to http://localhost/debug/js/map.js, which I can edit locally until the problem is fixed.
Edit re-read your issue, if you aren't happy to find/edit the SQL database for the file in question, you could always just add an adblock rule against it, and manually run your own script from console/greasemonkey it in.
Answer to question in the title:
HTML5 has a feature called an "application cache" just for this. It involves adding a manifest attribute to your <html> tag.
<html manifest="what_to_cache.appcache">
Then in what_to_cache.appcache,
CACHE MANIFEST
http://...production.../js/map.js
Future requests of items listed in the manifest will thereafter be loaded from the cache, if available, even if the user is offline. The file is stored in an SQL database for that website, so you can thereafter edit the database.
You can do this with fiddler.
Use the AutoResponder to intercept URLs and return content from local file or different server.
http://fiddler2.com/
I have found a Chrome extension which, despite its bugs, achieves precisely this behaviour. DevTools Redirect: https://chrome.google.com/webstore/detail/devtools-redirect/jmhdebkkippcccflcoddckhjjfgnfhnp
This allows developers to specify JS or CSS files to redirect, and a new URL to grab them from (eg. http://localhost/.../debug.js).
For future readers I would like to answer this question. Have a look at
Requestly - A Chrome Extension to modify Network Requests.
You can setup a Redirect Rule Request following these steps:
Select Redirect Request Rule Type
Create a new Redirect Rule
Disclaimer: I have created this So you can blame me if you do not find this helpful :)

ASP pages not bringing in Images, CSS or JavaScript

My uncle's has got the files for his website that he got made a few years ago and needs something changed on it. So he has sent me the files as I am willing to make small changes as I know HTML and CSS. But when I open his index.asp page in a browser this only shows html even though the images, css and javascript files are linked properly.
I am not familiar with asp, I would really appreciate it if someone could let me know why the files are not being brought up when I open the index.asp file in a browser.
Thanks
Because when you just open the asp file on a browser, there's no web server intervention so that the ASP page is properly processed. You are just opening a file as if you were opening it on Notepad. You need to configure the whole site as an IIS Application and browse to the site by going to http://localhost/YourSite
First things first - as the previous comment says, you need to run ASP through an IIS based web site because the code needs to be processed.
If you're running through IIS and having this issue, check to see that your IIS settings are correct. Google "static content IIS" and you should find articles relating to this problem.

Javascript not working on localhost, but it is working on Live site

I am facing JavaScript problems on XAMPP Localhost. The Collapse Buttons, go to top button and jQuery news feed are not working on every site on my localhost.
But Facebook, Twitter, Plusone buttons load correctly from remote server i.e. from the respective Social Sites.
So, I think it narrows me to the point that the JavaScript files hosted locally are not executed while those from Facebook etc. are getting executed.
I tried reinstalling XAMPP but didn't work.
I know this is old but, I had the same problem and found this question while searching a solution. But I have lampp installed on ubuntu and since Linux asks permission to execute ANYTHING, the local js files which resided in htdocs were without permission. After:
sudo chmod 777 -R /opt/lampp/htdocs
... everything was OK. Hope this helps future wanabee web developers.
It should not matter whether your files are local or not...javascript should still get executed. Try using some debugging tool like to see if you get any errors that only occur on your local machine. Because it could be that you are running some code that is depending on a domain or whatever.
I know this post is old and the answer is already given, I just wanted to give an answer of a possible reason that I encountered in case someone else finds this and it does not help.
Make sure your entire html code gets executed by viewing your page source. With me, half my code was not being executed due to a PHP error that was working on localhost with the local database but not on live with the live database. This caused the HTML to cut of from that point above my javascript.
So check your page source. If it is being cut of somewhere, find out why :)
I had the same problem. I try a lot but finally solved. The main problem was my browser cache that prevents from loading the new JavaScript file. My recommendation is that clear your browser cache data then close the browser and reopen your site again it will work perfectly.
remove any (pre in post ) blank spaces from filenames of your namespace example : localhost:port/dir /index.html
localhost:port/dir/index.html
In similar cases,
If web project site runs JS on Live Server but not on locally opened index.html,
try to check validity of HTML File Paths,
e.g you may have written:
<script src="script.js"></script>
instead of:
<script src="./script.js"></script>
Try to add ./ before file name.
./ means Current directory.

Categories

Resources