Page 1 of 1
Replace server response
Posted: Wed Sep 12, 2018 6:09 pm
by xpert13
Hello.
Some site has inline JS code in the page response. I want to change those code before browser execute JS. How can I do it?
Re: Replace server response
Posted: Wed Sep 12, 2018 7:30 pm
by salvadordf
Hi,
Right now the official CEF forum is down and I can't search a way to change the response headers but you can use the code in the ResponseFilterBrowser demo to change the javascript code that checks the response to ignore that value.
Re: Replace server response
Posted: Mon Sep 17, 2018 5:21 pm
by xpert13
Thank you. It seems to be that I looking for. But I not completly understand how it works. Your have 2 functions: first one read complete resonse, second one is replacing complete resonse by own. But I don't understand how to read responce and replace just part of it.
I will be grateful for any help.
Re: Replace server response
Posted: Mon Sep 17, 2018 7:27 pm
by salvadordf
You need to use TResponseFilterBrowserFrm.CopyScript and modify the line with :
Code: Select all
Move(data_in^, data_out^, data_out_written);
That code copies the input buffer in "data_in" to the output buffer in "data_out" unchanged.
You need to search and replace the string in the "data_in" buffer and then write that buffer to the "data_out" buffer.
Use the "data_in" pointer like a PChar with a "data_in_size" size and use the search and replace functions in Delphi.
Things to keep in mind :
- The web server sends encoded text. See how the TResponseFilterBrowserFrm.GetResponseEncoding and TResponseFilterBrowserFrm.StreamCopyCompleteMsg functions use the content type to decode the text.
- The TResponseFilterBrowserFrm.Filter_OnFilter function can be called several times with several chunks of data if the resource is too big. Read the code comments in uResponseFilterBrowser.pas.
Re: Replace server response
Posted: Tue Sep 18, 2018 3:56 pm
by xpert13
Thanks a lot, salvadordf
Re: Replace server response
Posted: Fri Feb 15, 2019 7:31 pm
by dilfich
Code: Select all
var
Repl: AnsiString;
......
Repl:= PAnsiChar(data_in);
Repl:= System.AnsiStrings.StringReplace(Repl, 'refer', 'test', [rfReplaceAll, rfIgnoreCase]);
data_in:= PAnsiChar(Repl);
Move(data_in^, data_out^, data_out_written);
How to do? I sometimes get extra characters in the modified code.
Code: Select all
["res","refer"] replace ["res","test"]]U or ["res","test"
Or add an example in the Demo ResponseFilterBrowser, many will certainly help.
Copy script
Replace logo
Replace Text

Re: Replace server response
Posted: Sat Feb 16, 2019 1:09 pm
by salvadordf
dilfich wrote: Fri Feb 15, 2019 7:31 pm
Code: Select all
var
Repl: AnsiString;
......
Repl:= PAnsiChar(data_in);
Repl:= System.AnsiStrings.StringReplace(Repl, 'refer', 'test', [rfReplaceAll, rfIgnoreCase]);
data_in:= PAnsiChar(Repl);
Move(data_in^, data_out^, data_out_written);
How to do? I sometimes get extra characters in the modified code.
Perhaps the server is sending text encoded in UTF8 or something else that "
System.AnsiStrings.StringReplace" can't handle correctly.
dilfich wrote: Fri Feb 15, 2019 7:31 pm
Code: Select all
["res","refer"] replace ["res","test"]]U or ["res","test"
Or add an example in the Demo ResponseFilterBrowser, many will certainly help.
Copy script
Replace logo
Replace Text
I'm sorry but I'm extremely busy these days and this seems to be a text encoding issue.
Re: Replace server response
Posted: Sat Feb 16, 2019 1:38 pm
by dilfich
I think the problem is length.
Like there is no mistakes
Code: Select all
Repl:= System.AnsiStrings.StringReplace(Repl, 'refer', 'reser', [rfReplaceAll, rfIgnoreCase]);
Problem
Code: Select all
Repl:= System.AnsiStrings.StringReplace(Repl, 'refer', 'test', [rfReplaceAll, rfIgnoreCase]);
Need to know a new the size of the and where the point to?
Re: Replace server response
Posted: Mon Feb 18, 2019 10:09 am
by salvadordf
The
TResponseFilterBrowserFrm.ReplaceLogo function in the ResponseFilterBrowser demo handles buffers with different sizes.
The original logo is much smaller than the new logo but the demo keeps sending data.
If the new data buffer is smaller than the old buffer then you need to :
- Write the modified data in the buffer.
- Set the data_in_read and data_out_written parameters accordingly. They will be smaller than data_in_size.
- Return RESPONSE_FILTER_DONE.
Re: Replace server response
Posted: Wed Sep 18, 2019 10:30 am
by dilfich
I can not understand how to upgrade the size. ReplaceLogo not suitable, there is a file changing and not the text, the html code is not changed. I ask specifically about the text. How will you have the time, please add ResponseFilterBrowser is also an example of modification of the text received in the response from the server.
