Accessing HTML source in HTMLViewer

Is there a way to access the HTML source in the HTML Viewer when I load a page with the LoadURL method?

What I want to achieve: Before rendering the HTML I want to parse it through, probably alter it and then reinject it to the HTML Viewer. The result should have a similar functionality like the NoScript-Plugin on Firefox browser – preventing loaded Javascripts from executing without permission.

I am aware that I can solve this problem with a combination of the HTML Viewer and the HTTP/HTTPSSocket but it would have been nice if it would work with the HTML Viewer alone.

From studying the language reference, I would say an easy way is currently not possible but perhaps I am overseeing something ;). Thx in advance.

1 Like

Search is your friend
https://forum.xojo.com/5714-html-source-code-as-a-string/0

Natascha,

a simple entry in this forum with only 3 entries have 8 files when saved to disk in the complementary folder:

3 css files, 2 js files, 3 png files.

Some html complementary folders have far more items. The search can be tricky.

Hi Natascha. I think you are right that this cannot be done with the HTMLViewer alone :frowning:

I believe it might be possible with an MBSPlugin but I’ve not played with that part of MBS yet so I cannot be 100% sure. Christian might be along today, he could confirm this.

1 Like

It is no problem to replace things, but you will get problems when the page uses local paths like

Then the page looks wrong because it cannot find the files

is this for desktop, iOS or web?

MBS Plugins have a lot of HTMLViewer extensions:

[code]dim html as string

#if TargetMacOS then

html = HTMLViewer1.mainFrameMBS.dataSource.data

#elseif TargetWin32 then

if HTMLViewer1.Renderer = 1 then
  html = HTMLViewer1.ChromiumBrowserMBS.MainFrame.Source
else
  html = HTMLViewer1.IEHTMLTextMBS
end if

#elseif TargetLinux then

html = HTMLViewer1.LinuxWebViewMBS.MainFrame.DataSource.Data

#else
?
#endif[/code]
4 ways so we can cover most platforms :slight_smile:

[quote=315637:@]Hi Natascha. I think you are right that this cannot be done with the HTMLViewer alone :frowning:

I believe it might be possible with an MBSPlugin but I’ve not played with that part of MBS yet so I cannot be 100% sure. Christian might be along today, he could confirm this.[/quote]

It is quite possible with JavaScript, but indeed, it is not built in. I posted solutions at the thread I linked to.

And of course, it is part of the MBS plugins.

Ahh it only worked when I changed the Renderer to WebKit

I am not sure StatusChanged fires correctly with native renderer in Windows. You may want to use TitleChanged instead.

I still can’t confirm that by the way. I’m concerned about how it happens because that seriously cripples our workarounds.
Windows is significantly slower with triggering StatusChanged, but I haven’t seen it not fire.

Cheers everybody!

Xojo 2019 R1.1 latest version of plugin:
Doesn’t seem to work well. Code execution freezes in line

> html = HTMLViewer1.ChromiumBrowserMBS.MainFrame.Source

even with a very simple peace of html on the page.

1 Like

Sorry for bumping this old thread up again.

This works for me now:

Dim secureSite As New HTTPSecureSocket
secureSite.Secure = True
secureSite.ConnectionType = SSLSocket.TLSv12
Dim Page As String = secureSite.Get(URL, 30)
1 Like

This was the only “for sure” way I found to do something similar.