General :  K-Meleon Web Browser Forum
General discussion about K-Meleon 
Editing the html code of a displayed webpage and...
Posted by: Zvonko
Date: January 09, 2019 04:34PM

An unusual question. Does anyone here see the possibility of such an approach within K-Meleon:

Initial situation: One opens a website, in which places are provided somewhere, at which afterwards entries made by the visitor would appear, and below then a Submit button. Anyway, after pressing the Submit button the browser sends the contents of these "places" to the server, right?

Now, however, the following (and the question): It is of course easily possible to read out the html code of the page. It is also easily possible to change this code by making the desired entries in the relevant places (ie by a program instead of manually). But would it also be possible (say: at least theoretically) to "infiltrate" this changed code into the browser (in place of the original one)??? To then click on Submit and send the automatically inserted inputs?

I do not understand the internal working of a browser, but you are all experts here, right? Would this "smuggling in" (a more appropriate term I can not think of) possible?

Thank you in advance for your ideas. Is an exciting question, isn't it?

Options: ReplyQuote
Re: Editing the html code of a displayed webpage and...
Posted by: JohnHell
Date: January 09, 2019 06:39PM

Quote
Zvonko
But would it also be possible (say: at least theoretically) to "infiltrate" this changed code into the browser (in place of the original one)??? To then click on Submit and send the automatically inserted inputs?


Is what major sites do everyday with AJAX, so, yes, if you know the page, and you know enough JavasScript, yes, you can modify the live HTML of a page and submit it through JavaScript DOM.

Is not rocket science, but that doesn't mean it is easy either.


What are you trying to do? }:-D

Options: ReplyQuote
Re: Editing the html code of a displayed webpage and...
Posted by: Zvonko
Date: January 09, 2019 08:13PM

Thank you, JohnHell!

What I am trying to do? As I said in my question: to automatize the input of user data. It refers to a secure website of an authority. There is a main page where the user start by invoking another page on which an input is to be done by a very uncomfortable process resulting in returning to the main page then showing the input done. And this must be done several times to make all the input. After this, the main page contains all input data done by the user, and the user would click on the Submit button. As I said, the idea is a program which reads the initial html code of the main page, inserts programmatically the complete set of desired entries and replaces the displayed html code by this changed html code; the click on the Submit button then should be done by the user or by the program itself. I hope this describes the intended concept clearly enough.

OK, I am not a javascript expert... Would the javascript method you are speaking of result in a displayed page showing the changed html code with all the input, as if the input has been done manually by the user? This (how to replace the original html code by the changed code and show this new code in the browser) is the main point of my question. If this is so, I will try to learn how to apply this javascript solution. Or does the use of javascript in your proposal refer to another point, e.g. submitting the changed html code directly to the server? This probably wouldn't work on a secure website of an authority (using certificates etc.)?

I am grateful for all your tips!



Edited 2 time(s). Last edit at 01/09/2019 08:55PM by Zvonko.

Options: ReplyQuote
Re: Editing the html code of a displayed webpage and...
Posted by: JohnHell
Date: January 09, 2019 09:04PM

A page has HTML, the HTML is accessed through DOM (Document Object Model) and you can change whatever you want. If you are going to learn it, have a look to that W3Schools.com link.

For example, if you have a form with an input, you could remove that input and replace it with another, then, when you click on submit you would be submitting the new input.

Consider the HTML of any page, not as a static code, but as a live one.

That is what Greasemonkey and the scripts it loads do when you use it. There is a working Greasemonkey extension adapted for K-meleon, if I'm not wrong. Have a look to it to load your scripts.

It shouldn't matter the page you are sending it as long as the backstage of the web server validates and receives data correctly as expected.

Options: ReplyQuote
Re: Editing the html code of a displayed webpage and...
Posted by: Zvonko
Date: January 09, 2019 10:14PM

OK, I see I have to study this javascript and DOM stuff...

But I am still not sure we are speaking exactly of the same point. A webpage is displayed in my browser. Now three different processes should take place: I want to read (extract, save) the html code of the page, I want to edit it (in my case by inserting input data on specific places of the code), and I want to replace the displayed code by the edited code in my browser window. Are you saying that javascript can be used for all of these three processes? My suspicion is that javascript is only the way how to edit/change/manipulate the html code, and that the other two processes have to be done by completely different methods (e.g. by specific interface programs). Am I right with this suspicion? My main question here refers only to the third process: When I have an edited html code, how to bring it into the browser to be displayed instead of the original one?

Could you please explain this question more exactly?

PS: In fact I would like to know, for my project to be written in AHK, if there are browser independent methods which can be used for the first and the third process described above, i.e. for extracting (saving) the html code currently displayed in the browser, and for replacing the currently displayed code by another one. The script I want to write in AHK (which should do this extracting and replacing) should work for all users (whatever browser they use) to make it easier for them to work with the involved website. But for the beginning I would be happy to know if and how this could be done in KM.

Options: ReplyQuote
Re: Editing the html code of a displayed webpage and...
Posted by: JohnHell
Date: January 09, 2019 11:06PM

Quote
Zvonko
Could you please explain this question more exactly?

I don't think it can be explained further. Have you read the link above, its main content?. That is what JavaScript can do.

Quote
Zvonko
I want to read (extract, save) the html code of the page

If you mean that you need to save it to disk for whatever reason, no, JavaScript can't do that directly. But K-meleon can save it if you call the appropriate ID command (ID_SAVE_AS).

Quote
Zvonko
I want to edit it (in my case by inserting input data on specific places of the code)

Without the need of download it, edit, and kind of upload again, that is what you seem to be understanding, JavaScript can edit and change the page on the fly.

But if you want to see those changes applied to the source code of the page, you won't be able to do it, as when you invoke that command you view the source code of the original page. As I said, this happens all live, on the fly. You don't permanently change the webpage, but if you (File > save) save the page, you'll see the changes are saved to disk, because what it saves is the live HTML in your window.

Quote
Zvonko
I want to replace the displayed code by the edited code in my browser window

Read the above. Code is changed on the fly. No need to save to disk, edit an replace. It is replaced based on your script code instructions on the fly.

Read the link in my previous post.



You have good examples with Google Drive download pages. They are built entirely through JavaScript. If you look at their source code, you'll see only a script that, then, after page load, it builds the whole page and modifies it (in this Google case after requesting to the server what content has the drive ID). That is the reason these pages are sooooo CPU resources demanding, because they are all built on the fly and the RAM goes to heaven peaks.



NOTE: when I talked about GreaseMonkey above is because is what is used in other browser to load user scripts, here, with K-meleon, would be enough with its macro command injectJS. I was just routing, maybe, a simpler method if you don't want to play with macros.



Edited 3 time(s). Last edit at 01/09/2019 11:14PM by JohnHell.

Options: ReplyQuote
Re: Editing the html code of a displayed webpage and...
Posted by: Zvonko
Date: January 09, 2019 11:35PM

Thank you very much, JohnHell! Now this seems to be clear. Sorry for my misunderstandings...

However, it is clear now that the javascript on-the-fly method is not the answer to my specific question.

May I conclude that the shortest answer to my initial question (in the sense it was meant) would be: There are no methods which could be applied with KM to replace the currently displayed html code by another one? And even for the saving of the currently displayed html code only the ID_SAVE_AS command can be used (which is a visible, not a background method)?

Or are there other aproaches which could lead to a solution?

Options: ReplyQuote
Re: Editing the html code of a displayed webpage and...
Posted by: JohnHell
Date: January 09, 2019 11:50PM

Quote
Zvonko
Thank you very much, JohnHell! Now this seems to be clear. Sorry for my misunderstandings...

However, it is clear now that the javascript on-the-fly method is not the answer to my specific question.

May I conclude that the shortest answer to my initial question (in the sense it was meant) would be: There are no methods which could be applied with KM to replace the currently displayed html code by another one? And even for the saving of the currently displayed html code only the ID_SAVE_AS command can be used (which is a visible, not a background method)?

Or are there other aproaches which could lead to a solution?

Now is me who is confused . I understood that you wanted to change the page and interact with it. JavaScript could do that.

I told above about the save command because looks like you wanted to keep a copy of the page, but as I said, there is no need of saving it before change it.

But now you tell that you need to save the code of the changed pages, but silently... Maybe could be done with a mix of JS to modify, and return the modified code to a K-meleon macro variable and then copy that variable contents to the clipboard to send to AutoHotKey

Options: ReplyQuote
Re: Editing the html code of a displayed webpage and...
Posted by: siria
Date: January 10, 2019 12:21AM

Hm, am I getting this right...? The core prob is that you have no clue of javascript, which is the usual method to modify pages, but you are experienced with AutoHotkey. So you wish to avoid coding complicated (unknown) replacements in javascript and instead export/import the html to AHK and back into the browser...
In my opinion a major struggle, probably not worth a giant waste of time. Either starting to learn some JS from zero (nightmare), or struggling with export/import experiments (innerHTML replacements), with high chance of failing anyway.

And there's another danger: If that website is an important one, and they make their form intentionally so complicated in several steps, perhaps they do this exactly to avoid any non-human hacking input, for security reasons? It can also happen, if a site detects any manipulation attempts, that the account gets blocked because a stranger is probably trying identity-theft? And if they realize it's really you, intentionally manipulating, that's probably not much better either.
At any rate - guess not worth it...

Options: ReplyQuote
Re: Editing the html code of a displayed webpage and...
Posted by: Zvonko
Date: January 10, 2019 07:40AM

Thank you, siria, for your helpful comments!

(I think again and again, now I have formulated the question really absolutely clearly, but then I trigger misunderstandings again and again. But, of course, it's difficult in an area where you don't know your way around at all... And, I know, I would probably have to think about how I am asking questions...there must be something wrong in the way I am doing it...)

Yes, my approach is to use AHK wherever this is possible. And you're probably right about some of your concerns...

But anyway, I would like to know now how these two tasks (exporting and re-importing the html code) could at least be solved in principle.

So far (due to misunderstandings) I haven't received any tips on this point from you. Don't you have a clue to help me?

Options: ReplyQuote
Re: Editing the html code of a displayed webpage and...
Posted by: siria
Date: January 10, 2019 09:52AM

Well, roughly in theory (there sure are better ways, am struggling myself with JS):
To get the original code, hit the source code button or CTRL+U, you can set KM to open it in whatever editor you want. From there you can do your AHK replacements. Then CtrlA+CtrlC to put the finished new complete-source into the clipboard (or perhaps AHK can do that too). Next you'll have to fire manually again a little macro to get the clipboard content into a macro variable, and from there injected via javascript back into the page.
With the macro trying perhaps something like
$_x= getclipboard();
# now great prob: escaping all sorts of forbidden characters (to do), or you only get JS-errors and the whole thing breaks. Afterwards:
$_code="var newHTML=\"".$_x."\"; ";
$_code=$_code."document.documentElement.innerHTML=newHTML; ";
injectJS("(function() {".$_code."})() ");
Or replacing only the <body> parts? Or only a form content? No idea, it's always lots of trial+error+ a bit pure luck when I'm struggling with JS myself.

But this also involves several manual steps, not fully automatic, so probably no advantage anyway over doing it the normal way?
Also, it depends heavily on the original html code if the whole concept has any chance to work, even partly. If the page depends strongly on javascript, especially on external js-files, which you can't modify by just changing the html-code, chances are getting lower. And of course, the same replacements would probably be easier and more robust directly in the js-code - which also means "1-click" macro.



Edited 2 time(s). Last edit at 01/10/2019 09:59AM by siria.

Options: ReplyQuote
Re: Editing the html code of a displayed webpage and...
Posted by: Zvonko
Date: January 10, 2019 10:28AM

Wow...thank you very much, siria, this is really a helpful answer!!!

My last attempt here to find a non-JS way out:

You say the macro injects the new code using JS. Can anything be said about how the macro does it? Sure, it uses the JS, but how does the macro interact with the browser, via which "interface", to change the content of the browser window?

My thought is, of course, whether I could use this same "interface" without using JS, but with means of AHK. (AHK is an incredibly powerful tool, so...)

And excuse me if this question is based on further misunderstandings on my part!

Options: ReplyQuote


K-Meleon forum is powered by Phorum.