google chrome console , has a problem in show javascript code - javascript

google chrome console , has a problem in show javascript code
Does not display my codes
Even in debugger , after refresh page or whatever
js script in my page start with : <script type="text/javascript">
my file is php and server is xampp

Syeed Masoud Tayefi indeed you need to add the src to the tag, otherwise the browser not only won't show you the file, neither read it and hence not perform any fuction that has been wrote down. Here is how I do it myself in order to check and debug if need it
<body>
<div> ...whatever goes in here...</div>
<script src="./functions.js"></script>
</body>
Hope my answer help a bit to clarify your question. As You didn't leave any of your code, I can't speak about the unclosed issues, if any.

Related

Alert does not trigger, JS is not detected

I think I might be going crazy at this point. I had an ASP page working yesterday, and came in today to Firebug telling me it cannot detect the JavaScript on the page. Love it when things change after not touching them.
So I start trying to figure out what is happening. I tried slimming down the code, this answer, restarting Firefox, saving the page under a new name and loading the new one, and adding a ridiculous amount of code I generally consider unnecessary. I even tried removing everything from the page and changing it to this:
<script>
alert("yay");
</script>
Does not trigger alert, and Firebug says "No JavaScript on this page". I've been looking for explanations for almost 2 hours and cannot figure out what is happening. I know I did not deactivate anything because other pages will show JavaScript and function properly. I also know that no add-ons are causing it.
I am using Firefox 28.0 (also tried on 27.0.1). Opening the page in Chrome triggers the alert.
(Damn I meant to post this as a comment).
As you responded I'll re-popualate...
I create jsfiddle,
<body>
<script>
alert("yay");
</script>
</body>
Also ensure your browser has javascript enabled.
You should follow the instructions on the Firebug's first aid page.
I assume it's either some Firebug setting or a conflict with another extension. (I see at least YSlow and FlashFirebug installed.)
To check that you can create a new profile and just install Firebug.
Closing the tab and opening the same link in a new tab seemed to resolve the issue.
I'm not sure if any of the prior attempts factored in, so I will list them as well. To be clear, none of these worked, but may have paved the way in some fashion.
Restarting Firefox
"Clear Activation List" on Firebug
Save page under new filename and load the new page
Uninstalling add-ons (all of them)
Create new profile and load page on that profile
Add a <!DOCTYPE html> to the top
Add type="text/javascript" to script tags
Add charset="utf-8" to script tags
Add <meta charset="utf-8"> in <head>

Javascript not working in Google Chrome Browser

I've put up a code for commenting box on my html file for the visitors to comment on something in my website, and the code is provided from a website that offers it for free.
The problem is, the commenting box is visible and functions perfectly on Internet Explorer, but in Google Chrome Browser, or FireFox Browser, the commenting box doesn't even appear on the screen. When i view source by right-clicking, the code is still there, but does not show on the screen, and I think something is wrong with the code.
I have tried to fix this myself, and I could not figure this out alone.
Here is the code that was provided from the free commenting box website.
<div class="js-kit-comments" backwards="yes" paginate="10"></div>
<script src="http://js-kit.com/comments.js"></script>
I wish i could provide more code, but honestly, this is basically it.
I really hope you guys can help me out on this one. Thank you in advance.
The big js code isn't made to be compatible.
First line :
try { if(!window.JSK$EPB && navigator.appVersion.match(/[345]\.[.0-9 ]+Safari/)) {
This is not the task of SO to adapt and/or debug a big proprietary script in the blind.

I have found that just before the </head> tag I have <script id="__isTpiViewExists"></script>. Is this a virus?

In the HTML code just before the </head> tag I have this:
<script id="__isTpiViewExists"></script>
I never put it there. Is it possible to be a virus or something else?
Edit //
By using google chrome debugging tool in the Scripts section i have everypage_early.js // This content script get injected into every page, enabling us to inject the conduit commmunity toolbar into the DOM of the page.
Another note : In Firefox using firebug i dont have this script only when I use google chrome debugging tool,also if I right click and View Page Source.I dont have the script only in google chrome debugging tool.. so i think is not a virus just google add in there tool .. i dont know
This is the nasty nasty conduit toolbar which injects javascript into every page it visits in order to hjiack the behvaiour. If you see this, run MalwareBytes and another AV and uninstall all toolbars and update your system.

Delphi, EmbeddedWB/TWebbrowser - jQuery not executing

I am using EmbeddedWB (A TWebbrowser extension) to do like a "live preview" of some dynamically generated content.
I am trying to add jQuery into the mix, so I can get some fancy effects going on, however since IE9 always asks "Allow blocked content" for each and every damn page, a dynamically generated one (Webbrowser.LoadFromString) certainly wont be allowed to have fun. To put it simple: It wont allow Javascript execution.
I tried adding a SecurityManager to my TEmbeddedWB, however that did not do it either. I tested my dynamic code in Firefox, and in IE9, and it works (of course, in IE9 I have to allow first, which was how I found it was a security issue).
Is there a painless way to get around this, without having to manually go into IE and tweak something? Or am I completely wrong about the cause of the issue?
EDIT: After trying this article's method, IE does not ask if it should allow stuff anymore, however my script is still not being executed within my TEmbeddedWB/TWebbrowser..
EDIT 2: Okay, by removing the jQuery code, and displaying a plain Alert, I am forced to conclude that JS is now being executed, however jQuery is not.
EDIT 3: Here is the (stripped down) HTML code that my app generates, where jQuery is not working in my EmbeddedWB/TWebbrowser control - however, it works in Internet Explorer 9 itself:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<script type="text/javascript" src="file://C:\jQuery.js"></script>
</head>
<body>
<center>
<p>
Some stuff here!
</p>
</center>
<script type="text/javascript" language="javascript">
$(document).ready(function(){
alert('I Am jQuery!!!!');
});
</script>
</body>
</html>
EDIT4: I have also tried switching the src to a Google Hosted jQuery, and that did not work either. Removing the Metatag did not fix it either. Just letting you know of stuff I tried before you waste time on suggesting it :)
EDIT5: By navigating to a site that uses jQuery (Webbrowser.Navigate) the site was working as expected. However when doing it from my local test.html, or by doing .LoadFromString();, it will not work.
Will not work = jQuery code not executing.
It seems to work if you use correct URL for the jquery.js file:
<script type="text/javascript" src="file://C:/jQuery.js"></script>
<script type="text/javascript" src="file:///jQuery.js"></script>
or a relative path, you can also omit the file:// protocol:
<script type="text/javascript" src="../../jQuery.js"></script>
The above works when you load the HTML from a file. The question is however, if content from memory and javascript from file system is not considered crossing a security context boundary and rejected for that reason by the embedded browser. In that case, embedding jquery directly in the HTML content (using the <script> tag) should work.

How to set breakpoints in inline Javascript in Google Chrome?

When I open Developer Tools in Google Chrome, I see all kinds of features like Profiles, Timelines, and Audits, but basic functionality like being able to set breakpoints both in js files and within html and javascript code is missing! I tried to use the javascript console, which itself is buggy - for example, once it encounters a JS error, I cannot get out of it unless I refresh the whole page. Can someone help?
Are you talking about code within <script> tags, or in the HTML tag attributes, like this?
Click
Either way, the debugger keyword like this will work:
Click
N.B. Chrome won't pause at debuggers if the dev tools are not open.
You can also set property breakpoints in JS files and <script> tags:
Click the Sources tab
Click the Show Navigator icon and select the a file
Double-click the a line number in the left-hand margin. A corresponding row is added to the Breakpoints panel (4).
Use the sources tab, you can set breakpoints in JavaScript there. In the directory tree underneath it (with the up and down arrow in it), you can select the file you want to debug. You can get out of an error by pressing resume on the right-hand side of the same tab.
You also can give a name to your script:
<script>
... (your code here)
//# sourceURL=somename.js
</script>
ofcourse replace "somename" by some name ;) and then you will see it in the chrome debugger at "Sources > top > (no domain) > somename.js" as a normal script and you will be able to debug it like other scripts
Refresh the page containing the script whilst the developer tools are open on the scripts tab. This will add a (program) entry in the file list which shows the html of the page including the script. From here you can add breakpoints.
Another intuitive simple trick to debug especially script inside html returned by ajax, is to temporary put console.log("test") inside the script.
Once you have fired the event, open up the console tab inside the developer tools.
you will see the source file link shown up at the right side of the "test" debug print statement. just click on the source (something like VM4xxx) and you can now set the break point.
P.S.: besides, you can consider to put "debugger" statement if you are using chrome, like what is being suggested by #Matt Ball
My situation and what I did to fix it:
I have a javascript file included on an HTML page as follows:
Page Name: test.html
<!DOCTYPE html>
<html>
<head>
<script src="scripts/common.js"></script>
<title>Test debugging JS in Chrome</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>
<script type="text/javascript">
document.write("something");
</script>
</div>
</body>
</html>
Now entering the Javascript Debugger in Chrome, I click the Scripts Tab, and drop down the list as shown above. I can clearly see scripts/common.js however I could NOT see the current html page test.html in the drop down, therefore I could not debug the embedded javascript:
<script type="text/javascript">
document.write("something");
</script>
That was perplexing. However, when I removed the obsolete type="text/javascript" from the embedded script:
<script>
document.write("something");
</script>
..and refreshed / reloaded the page, voila, it appeared in the drop down list, and all was well again.
I hope this is helpful to anyone who is having issues debugging embedded javascript on an html page.
I was having the same problem too, how to debug JavaScript that is inside <script> tags. But then I found it under the Sources tab, called "(index)", with parenthesis. Click the line number to set breakpoints.
This is Chrome 71.
Adding debugger; on top at my script worked for me.
I know the Q is not about Firefox but I did not want to add a copy of this question to just answer it myself.
For Firefox you need to add debugger; to be able to do what #matt-ball suggested for the script tag.
So on your code, you add debugger above the line you want to debug and then you can add breakpoints. If you just set the breakpoints on the browser it won't stop.
If this is not the place to add a Firefox answer given that the question is about Chrome. Don't :( minus the answer just let me know where I should post it and I'll happily move the post. :)
If you cannot see the "Scripts" tab, make sure you are launching Chrome with the right arguments. I had this problem when I launched Chrome for debugging server-side JavaScript with the argument --remote-shell-port=9222. I have no problem if I launch Chrome with no argument.
I came across this issue, however my inline function was withing an angularJS view. Therefore on the load i could not access the inline script to add the debug, as only the index.html was available in the sources tab of the debugger.
This meant that when i was opening the particular view with my inline (had no choice on this) it was not accessible.
The onlly way i was able to hit it was to put an erroneous function or call inside the inline JS function.
My solution included :
function doMyInline(data) {
//Throw my undefined error here.
$("select.Sel").debug();
//This is the real onclick i was passing to
angular.element(document.getElementById(data.id)).scope().doblablabla(data.id);
}
This mean when i clicked on my button, i was then prompted in the chrome consolse.
Uncaught TypeError: undefined is not a function
The important thing here was the source of this : VM5658:6 clicking on this allowed me to step through the inline and hold the break point there for later..
Extremely convoluted way of reaching it.. But it worked and might prove useful for when dealing with Single page apps which dynamically load your views.
The VM[n] has no significant value, and the n on equates to the script ID. This info can be found here : Chrome "[VM]"
Using Visual Studio (2012) I had the same issue and switching to IIS Express solved the problem!
The script tag's type attribute did not factor into it.
For some reason the Visual Studio Development Server does not provide everything Chrome needs to enable the breakpoints.
This is an extension of Rian Schmits' answer above. In my case, I had HTML code embedded in my JavaScript code and I couldn't see anything other than the HTML code. Maybe Chrome Debugging has changed over the years but right-clicking the Sources/Sources tab presented me with Add folder to workspace. I was able to add my entire project, which gave me access to all of my JavaScripts. You can find more detail in this link. I hope this helps somebody.
You have to add type="text/javascript" to the script blocks for them to be picked up as script. For example:
<script type="text/javascript"> ...your code here... </script>
for someone like me: just want to
(add breakpoint to) debug normal js code
<script> ... </script> inside/embedded html
Steps:
Sources -> Page -> Top -> find your html -> click -> right side show html and js script -> add breakpoint -> debug

Categories