I read an answer to a question on SO and someone suggested writing directly into the console. I thought, that sounds cool let's give it a go. I proceeded to make an attempt, but I couldn't figure it out. How do I write/run code directly in the console? I tried in Firebug & Firefox's inspector and I did a little Google search as well. Did I misunderstand something?
Firebug has two ways to execute some code (and write to the console). These are the Command Line at the bottom of the Console panel:
and the Command Editor if you want to write some larger scripts:
which is available by clicking the little arrow at the right side of the Console panel:
The Firefox DevTools have a similar feature to the Command Editor of Firebug called Scratchpad:
This tool is available via the Firefox menu > Developer > Scratchpad or by pressing Shift+F4.
MDN has some example about Outputting text to the console.
The most simple example is:
console.log("Hello World!"); Which should show up in the Firefox Console. (There might be some issue if you use Firebug at the same time)
Related
I am very much glad if anyone help me. am fairly new to Unix scripting side. I am trying to get into one url, but before that am getting one popup window(asking for customer details). So, i need to block/disable/ auto close the popup window. Please help me with the command
In Unix environment shell command plays differently. It can launch your browser but it can not set utility inside a browser application. You need to fix it inside your browser window by using tool option. Just search in google like how to block popup in yourbrowserName.
I got curious if it is possible to have multiple tabs open in a browser where all the tabs have identical content and be able to press a key or a mouseclick so that all tabs experience the same input. I believe my formulation of what I want to do may be confusing as searching this with my words has been fruitless. I will therefore illustrate with something specific:
In my case I want to have a few tabs on same window with the Google search present in all tabs. With one of the tabs selected as the current view in the browser.
I would then type in a query and click the first available link. My desired output would have all the tabs experience the query search and link click at the same time.
I would like to achieve this through bash scripting [not sure if this IS possible] and would be very grateful if I am provided with some examples and readings I can look at to get started on my example detailed above. If there are other approaches I would be happy to look at them as well. Preferably it would be something I could code and play around with.
I found a similar question here, but the question was not answered as it appears a little too general.
If it helps determine the answer: I am running Firefox 43 on Ubuntu 15.04.
Apologies in advance if the question appears a little vague. I will be more than happy to provide requested clarifications.
You can send keyboard and mouse inputs to windows via the X server (which is the service which controls all graphical windows).
For example you can send an F5 keypress to a Chrome window using the following
CHROME_WINDOW_ID="$(xdotool search --class Chrome | head -n 1)"
xdotool key --window "$CHROME_WINDOW_ID" F5
You can use mouse_move and click similarly; see xdotool for more details.
I'm not sure you could do this to individual browser tabs (unless you get your script to click on the correct tab beforehand), but definitely for individual browser windows.
You might do something like this:
# Write all Chrome window IDs to array
xdotool search --class Chrome | tr '\n' ' ' | read -a WINDOW_IDS
for WINDOW in ${WINDOW_IDS[#]} ; do
# Do actions on $WINDOW
done
Edit:
If your problem is specifically related to manipulating web pages, you might also want to check out browser automation tools such as Selenium, mechanize, or splinter.
I am developing a Chrome extension. It sets/reads local storage, reads the DOM, and sends an Ajax message. But sometimes it never reaches the server and I don't know where it gets stuck. Reloading the page doesn't work, although the extension works if I load another page in the same tab, and the original page will work if I load it in another tab. I use activeTab permission.
How can I debug this? The Chrome tutorial http://developer.chrome.com/extensions/tut_debugging.html only mentions a popup, which I do not have. (I right-click the icon and "Inspect popup" is not visible.)
I have tried plain old F12/sources, but I don't see my extension there, even when it works.
I am on localhost and the extension is not packaged. I am still working in developer mode.
The extension does not show up in developer tools>Sources>Content scripts, maybe because it isn't packaged. I can see the content script from another regular extension.
To see mine I:
Wrote the following as the first line in my script:
debugger;
Before pressing the extension icon, I bring up the developer tools: F12
Now, when I click the extension icon, my script opens under sources/program. It does not do this if the developer tools is not open.
In IE I can set breakpoints and debug just fine.
In Chrome I'm able to view the script but I have no options to set a breakpoint in the code, nor is there a "scripts" tab to navigate to for debugging. I'm confused. (Restarted chrome multiple times). I tried also setting a "debugger;" flag in the code, but that didn't work in Chrome.
What I've found that works is the following (in Chrome 21.0.1180.79):
Open the dev tools (ctrl+shift+i), then click the "Sources" tab. Notice the small right pointing arrow in the grey bar, if you click this, it'll show all the .js files loaded.
Here's the trick. Refresh the page (F5) and now all the inline script is available in this section, so you can set breakpoints at your pleasure :)
Add a #sourceUrl comment to your script. Chrome will then list the script in the Scripts / Sources tab in the Chrome DevTools.
There is a pretty good writeup about #sourceUrl on HTML5Rocks: http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl
Even though the comment is called #source*Url*, you can put anything you want as a Url. It just needs to be a human-readable string which you'll use to find your script in the list of scripts.
I use firebug a lot. However I do not like typing console.log all the time. I would rather type just log. So at the top of my console window I add this line all the time.
function log(){try{console.log.apply(console,arguments);}catch(e){}}
log(2 + 2);
I don't like to type that log statement every single time.
Is there a way I can tell either firefox or firebug to include that log function all the time.I guess I want to tinker with firebug and ask it to add that one function anytime it comes up live.
Any thoughts.
OK, this is probably a more complicated answer than you were after, but this is what I would do. I would build for myself a tiny Firefox extension which used an overlay to add a script into the windows which you are interested in, in this case the console window. The script would define anything you wanted in the context of this window, including your log() function. When Firefox opens the console window, it will run your script in this context, making the function available to you.
However, if you're not comfortable or experienced with creating Firefox extensions, this is unlikely to help in your particular case.
Have you tried to create a Greasemonkey script?