How to trigger consistent events in single browser console in one time? - javascript

For example I would like to control multiple”online”webpages ,such as google.com ,with only a sequence of consistent codes on browser console(ctrl+shift+j in windows system)for consistent action "such as clicking button A in A web and jumping to web B automatically , then clicking button B in B web."
(as usual,I must type other codes in refreshed console once I jump to anther webpage to change html)
For example:
//on the console1
`document.getElementbyid(“id1”).click()
`
//id1 is inside the web1
`window.open(“link_of_new_webpage”,”_self”)`
//I understand that it will be just a new page with new console.
//but I mean I was looking forward to some kind of these things.
//and below is id2 inside web2 in console2
`document.getElementbyid(“id2”).click()`
in conclusion i want a console likely showed below
document.getElementbyid(“id1”).click()
window.open(“link_of_new_webpage”,”_self”)`
document.getElementbyid(“id2”).click()
//the code above is actually consistent!
//not like code below
document.getElementbyid(“id1”).click()//in console 1 in web1
////////////////////////////////////////////////////////////////////////////////////////////////////
document.getElementbyid(“id2”).click()//in console 2 in web2
Plz someone helps me or tell me that it cannot be fulfilled
(in fact ,I was freshman in JavaScript and Html)
I promise I will use these tools in correct way.thx beyond description !!

If you're trying to do this on a client facing site I'm afraid what I believe you're asking to do is impossible for a myriad of security reasons. If you're just looking to run these executions locally though you're in luck. Headless browsers are commonly used in testing as well as web scraping and allow you to program commands as if a user was interacting directly with the browser. If you're looking to stay within the confines of JS a popular option is Puppeteer.
Best of luck

Related

Where is Chrome's debugger console command history stored?

I often use Chrome's debugger console for experimenting with javascript code fragments. When I got it right I usually want to copy the needed commands into my script, but here is where it gets messy. The is no filter options for commands and no way to call certain commands back (like with Ctrl-R in Bash) so you need to step through all the commands in the history and copy the commands you want one by one.
Instead, I think it should be possible to retrieve the command history from some file or Sqlite database. But I can't find it.
So my question is: Where is Chrome's debugger console command history stored?
I found an answer here: How to access firefox web console command history?
I had some trouble getting it working, but here is how I did.
Open the developer console (shift-ctrl-I). Then open that console in a new window if it isn't that already by using the menu in the upper right (the three dots).
When it is a separate window, press shift-ctrl-I again. Then paste something like this:
var hist = JSON.parse(localStorage.consoleHistory);
hist.forEach(function(command){
console.log(command);
})
Now, with all the commands in the console you can either copy them all to the clipboard or use the filter field above the console to do some filtering on them (you can use regex).
https://code.google.com/p/chromium/issues/detail?id=171386
Seems there was talk of such a feature which never came to fruition
You can collect some people and pressure the devs to put it in, or get it done.
Sounds really useful to me (:
For retrieving history :
https://developer.chrome.com/extensions/experimental_devtools_console#method-getMessages
How about developing an extension around that ?
Adding To marlars answer :
Actually i think its a little useful to not convert it into json. you can just keep it as a string so that you can use .indexof('yoursearchvalue')
And you don't have to always type that piece of code. you can just go to the Application tab -> Local Storage -> Devtools Entry and click on the consoleHistory

Execute Javascript method from browser address bar - GWT

I'm trying to execute Javascript on my web application by executing this on the browser URL/address bar:
javascript:window.alert('test');void(0);
However, nothing happens and the alert box is not showing up? Could the reason be that the app is running in DevMode?
You can write your javascript code inside the block like this
javascript:{alert("ok");}
I believe most browsers refuse to execute javascript: URLs from the URL bar as a safety measure (there's been messages on the web –esp. Facebook– telling people to copy-paste a javascript: URL to their URL bar that triggered an XSS). They didn't want to break bookmarklets though, so you can put that code in a bookmark; but it's much easier to just open the browser's JS console and type that command there.
Anyway, it's not due to GWT's DevMode.

Python Selenium get javascript document

I have a webpage that contains some information that I am interested in. However, those information are generated by Javascript.
If you do something similar like below:
browser = webdriver.Chrome()
browser.set_window_size(1000, 1000)
browser.get('https://www.xxx.com') # cannot make the web public, sorry
print browser.page_source
It only print out a few javascript functions and some headers which doesn't contain that information that I want - Description of Suppliers, etc... So, when I try to collect those information using Selenium, the browser.find_element_by_class_name would not find the element I want successfully either.
I tried the code below assuming it would has the same effect as typing document in the javascript console, but obviously not.
result = browser.execute_script("document")
print result
and it returns NULL...
However, if I open up the page in Chrome, right click the element and inspect element. I could see the populated source code. See the attached picture.
Also, I was inspired by this commend that helps a lot.
I could open up the javascript console in Chrome, and if I type in
document
I could see the complete html sitting there, which is exactly what I want. I am wondering is there a way to store the js populated source code using selenium?
I've read some posts saying that it requires some security work to store the populated document to client's side.
Hope I have made myself clear and appreciates any suggestion or correction.
(Note, I have zero experience with JS so detailed explaination would be gratefully appreciated!)

disable (Ctrl+U) keyboard script to prevent view source [duplicate]

This question already has answers here:
How to disable (View Source) and (Ctrl + C ) from my site
(10 answers)
Closed 9 years ago.
I'm looking for disable keyboard script to protect hidden content.
It is not possible. A user will always be able to view your source since he needs to download it in order to render the page.
There are more ways to view source than what you are trying to prevent:
Using firebug
Using wget
Right clicking on content choosing 'view source'
Using the menu option
Via man in the middle
probably more...
This is not very complicated but totally unreliable. Its same with all other Javascript protections.
First the trick (IE incompatible):
function denyKey(event) {
var code = event.keyCode;
if(event.ctrlKey) {
if(code==85)
return false;
}
}
window.addEventListener("keydown", denyKey);
My code is just scratch, it is not cross-browser. This is where to get keyCodes. I did not put much effort in the code since I want to discourage you from using it.
Once you send data to user, he can read the data unless you encrypt them without giving him the key. This means any:
Javascript authentication
Secret loading pages
Javascript "Wait before download..."
Blocked mouse buttons
..can and will be bypassed by the user.
I have a bookmarklet to unblock mouse buttons for example.
That is not possible, even if it was, it would have been a horrible protection. Even I could write a simple script that fetches the source of an arbitrary page. Everything that the client sees, is 'view source'-able (somebody edit that). Only server-side code is safe. Even if it was only possible to view your page through a real browser (but you can't make it so) you'll probably overlook a accelerator key, or other shortcut. If you don't want the client to see some code, don't give it to him! Keep it server-side (and not in a .txt file, that's accessible too) or don't keep it.

appMobi / phonegap setting/deleting cookie click action required 2 times before working?

I can't figure out for the life of me whats up with this. I dunno if this is appMobi/phonegap centric, cause they have there own special ways of setting cookies, and handling them. But I have what seems to be a unique problem overall, and it only occurs in the process of actually writing a cookie for the first time. Or removing it if it exists which is kind of like writing it.
Anyway I have 2 functions that worked perfectly up til the point of introducing the cookies to them. But I need the cookies also as its part of a login check, and a handful of other things. So this is my issue.
I type my user/pass, hit login. get nothing. hit login again, works.
I hit logout after being logged in, nothing works. hit it again.. works..
These are ajax driven functions as well. Dunno if that has anything to do with it or not, but in both cases cookies are being written in one shape form or another and thats when the functions seem to break in respect to the fact that I need to click the buttons that trigger them twice to get the desired effect despite them being a single click action.
If I remove the cookie lines from my functions everything works normally again without problem, with exception that the cookies are required to actually use half the stuff I am building. Also its a lone cookie being written with a numeric value.
Ideas?
AppMobi.cache.setCookie('AutoRemember', uid, 90);
This one line if its there, i have to double click for my functions to work, if its not there my functions work as expected..
a sample of one of my function would be (quickly typing one out here for example sake)
$('#buttonX').click(function(){
url = 'http://www.domain.com';
$.post(url, function(data)
{
if(data.status == "good")
{
AppMobi.cache.setCookie('AutoRemember', uid, 90);
window.location = 'dashboard.html';
}
}, 'json')
});
Ah yes, I ran into the same thing. You'll need to download and init the local_bootstrap.js lib and something from "Develop In Eclipse For Android " (I downloaded the .zip "appMobi Cloud Services library for PhoneGap Android development"). I'm doing the Android app with Eclipse, and I assume you are too, your post didn't mention what IDE you were using.
The .zip file has a great readme.txt on where & what to copy (.java files, jar file, etc.)
found here: http://www.appmobi.com/?q=node/85
Well, come to find out or as far as I can figure at least. This appears to be a glitch between browser and emulator more so than it is my coding. When I run the app in the sandboxed appMobi application from "Test Anywhere" things work as expected all around.
I will be opening up a bug ticked on appMobi where every they take bug reports and I will come back here with a link later so others may follow it as well when and if they come across a similar issue.

Categories

Resources