Chromium WebGadget v4

Developed or developing a new product in PureBasic? Tell the world about it.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Chromium WebGadget

Post by JHPJHP »

Updated:
- restructured directory / files
- numerous filename changes
- squashed a navigation bug
- various minor improvements

Since moving to the Chrome DevTools Protocol the directory structure and naming convention were becoming more convoluted with each update.

Unfortunately, the new update is not backward compatible, my apologies to those who have previously used the framework and want to benefit from the latest improvements and bug fixes.

Navigation Bug: I'm not sure how long it has been around, but to fix the problem remnants from the previous version needed excising.
Last edited by JHPJHP on Thu Nov 10, 2022 4:25 pm, edited 1 time in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Chromium WebGadget

Post by JHPJHP »

Updated:
- added a DevTools Control
- added auto-search opened port

DevTools Control
Using netstat the IP Address and Port Number are compared against established connections, if found...
- the Chromium WebGadget will issue a warning message ending the application unless the override constant was previously set
- the standalone Control Panel will issue a warning message at each step of the connection process with an option to ignore and continue

The warning message includes the process attached to the DevTools connection.

Auto-Search Opened Port (Control Panel)
Clear the Port field and tab-out. If an opened WebSocket port is found the port number is set, otherwise the default 9222 is set.
For this to work the version of Control Panel must match the OS version: 64 to 64, 32 to 32.

There is a constant built-in to the Chromium WebGadget framework for randomizing the port. Auto-search for an opened port can be useful for attaching to the Chromium WebGadget remotely when not knowing the port number.
Last edited by JHPJHP on Fri Nov 11, 2022 4:45 pm, edited 1 time in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Chromium WebGadget

Post by JHPJHP »

Updated:
- fixed a bug in the previous release

Fixed Bug
The DevTools Control would sometimes return a false positive reporting an opened connection.

-----------------------------------------

I recently received a PM inquiring about the Chromium WebGadget. I'm hoping the following provides information to anyone else with similar questions.

Returning the clicked ID from the HTML example below is a simple exercise when using the CrWG framework.
In addition, running the free examples (available from my website) will demonstrate more of what the framework offers.

Code: Select all

<body>
    <main>
        <button id="first_button" onclick="getClickID(this.id)">First Button</button>
        <button id="second_button" onclick="getClickID(this.id)">Second Button</button>
        <button id="third_button" onclick="getClickID(this.id)">Third Button</button>
    </main>

    <script type="text/javascript">
        function getClickID(clickID) {
            alert(clickID);
        }
    </script>
</body>
1. Create an HTML file with the above code. (e.g. test.html)
2. Run Control Panel from my free downloads.
3. Press the [ > ] button to select and open a browser window.
4. Change the address in the opened browser to the HTML file. (e.g. file://C:/Users/JHPJHP/Desktop/test.html)
5. Press the [ + ] button to listen for a connection.
6. Press the Connect DevTools button.
7. Press the F1 key to show the Display Area.
8. Right-mouse-click the Command Area > Load Command List... (context menu).
9. Select the file compile.json.
10. Right-mouse-click Runtime.enable from the Command Area > Send Selected (context menu).
11. Double-click Runtime.compileScript from the Command Area.
12. Press the sprocket (script) button to open the Script window.
13. Paste the following in the Script window, replacing the existing code.

Code: Select all

var buttons = document.getElementsByTagName("button");
for (var i = 0; i < buttons.length; i++) {
    buttons[i].addEventListener("click", function(e) {
        console.log(this.id);
    });
}
14. Press the Return Script button.
15. Press the Send Command button.
16. Press the buttons in your webpage; returned information (button id) viewed in the Display Area.

Numerous CrWG examples demonstrate how simple it is to parse the JSON script returning only the required data.
Last edited by JHPJHP on Sun Dec 11, 2022 5:11 pm, edited 3 times in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Chromium WebGadget

Post by JHPJHP »

Updated:
- added additional checks and balances
- improved previous checks and balances

Checks and Balances
It can be confusing if you already have a browser open to a specific port and you execute a second application using the same port.
It can happen that when you're executing script in the second browser it's being redirected to the first browser, making you think your code is faulty.
- the Chromium framework now tries to determine if a port is already in use...
-- the WebGadget will stop execution if found to be true, unless the override constant is included
-- the CDP Control Panel will issue a warning if found to be true, prompting the user to continue or cancel

In a 32-bit OS, examples can only be executed if they were previously compiled in the x86 version of PureBasic, and the same for a 64-bit OS.
This strictly applies to Control Panel but is ignored with the Cr WebGadget if the DevTools constant is excluded or the override constant is included.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Chromium WebGadget

Post by JHPJHP »

Updated:
- various improvements to Control Panel

Various Improvements
1. Added Close Chromium Browser button.
2. Added Page Title field with dynamic updates.
3. Added Stop Port Listening button.
Last edited by JHPJHP on Fri Mar 24, 2023 8:51 pm, edited 1 time in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Chromium WebGadget

Post by JHPJHP »

Updated:
- various improvements to Control Panel

Various Improvements
1. Added ScrollAreaGadget: Double-click to capture full page screenshot.
2. Added three options when sending the command Page.captureScreenshot (capture view port only).
-- Event ID: 20101 (dialog opens for user to save screenshot)
-- Event ID: 20102 (screenshot is saved directly to local folder)
-- Event ID: 20103 (screenshot is displayed in the ScrollAreaGadget)
Last edited by JHPJHP on Fri Mar 24, 2023 8:48 pm, edited 1 time in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Chromium WebGadget

Post by JHPJHP »

Updated:
- improved the use of Page.captureScreenshot
- submitted Control Panel for malware analysis
- squashed a bug from the previous update

Not only was full-page capturing added, but with a default change from PNG to JPEG, there is a considerable speed improvement for large images.

Malware Analysis
Compiling the FREE executables was becoming impossible without disabling Windows Defender or setting up various exclusions.
Obviously, their analysis was negative for malware; see recommendation below.
Analyst comments:

At this time, the submitted files do not meet our criteria for malware or potentially unwanted applications. The detection has been removed. Please follow the steps below to clear cached detections and obtain the latest malware definitions.

1. Open command prompt as administrator and change directory to c:\Program Files\Windows Defender
2. Run “MpCmdRun.exe -removedefinitions -dynamicsignatures”
3. Run "MpCmdRun.exe -SignatureUpdate"
Last edited by JHPJHP on Thu Dec 08, 2022 3:39 am, edited 1 time in total.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Chromium WebGadget

Post by infratec »

Hi,

I just downloaded the free binary and tried

General Display.exe
and
General ChartJS.exe

On my PC it works a s expected, but I have the WebView2 Runtime installed.
On other PCs with only the latest Edge browser installed, I can not see content of the cr_webgadget.

All PCs are Win10 x64 22H2 with the latest patch level.
On all PCs is also Chrome installed.

Any ideas?
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Chromium WebGadget

Post by JHPJHP »

Hi infratec,

Thank you for your post and support information.

This was not something I was aware of, a product of programming in a bubble without much feedback.

My current working environment is Windows 11; WebView2 Runtime is installed by default.
My previous laptop was Windows 10 with Office 365, which also included the WebView2 Runtime environment.

Sorry, I'm not able to look into this until later today when I'm home and have access to more resources.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Chromium WebGadget

Post by infratec »

It does something with edge, because when I start the exe files from a network drive, I get warnings from edge that it can be instable to store
the profiles on a network drive.

Then I copied the files to a local drive. The message is gone, but still no content of the cr_webgadget is displayed.

On windows 10 the webview2 runtime is not installed by default.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Chromium WebGadget

Post by JHPJHP »

Hi infratec,

Thank you for the additional information.
infratec wrote:It does something with edge, because when I start the exe files from a network drive, I get warnings from edge that it can be instable to store the profiles on a network drive.
All the examples include the Constant #Cr_WebGadget_User_Directory_Override. This modifies the creating and loading of the browser profile from the local directory \Users\[user name]\Appdata\Roaming\ to the same folder where the example was executed. Removing this Constant should stop any warning messages.
infratec wrote:... no content of the cr_webgadget is displayed
That is still something I need to test when I'm home, sometime within the next few hours.

There's another Constant (#Cr_WebGadget_Browser_Override) to switch the browser from Edge to Chrome. Once I'm home the first thing I intend to do is uninstall Webview2 from my Windows 10 laptop and test both the Edge and Chrome options.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Chromium WebGadget

Post by JHPJHP »

Hi infratec,

From my Windows 10 laptop I uninstalled WebView2, Office 365 and Google Chrome. Rebooted, ran CCleaner, rebooted again.

All the examples worked without an issue, executed from both the source code and 32/64 bit executables.

The only time I've seen something similar to what you reported was working from a virtual environment.

NOTE: WebView2 returned after a couple reboots.

------------------------------------

Updated:
- small update to the framework

Update Framework
The IAccessible Interface is used to control browser navigation in some examples, but the way its currently written is not reliable.
I've patched the problem, but eventually I'll need to rewrite the code for stability; I already have a solution in mind.
Last edited by JHPJHP on Fri Dec 09, 2022 5:07 pm, edited 2 times in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Chromium WebGadget

Post by JHPJHP »

Hi All,
infratec wrote:On my PC it works a s expected, but I have the WebView2 Runtime installed.
On other PCs with only the latest Edge browser installed, I can not see content of the cr_webgadget.
If anyone else experiences similar Chromium WebGadget behavior, please contact me via this forum or a PM.

The problem with fixing the issue is that I cannot reproduce it.
Currently, I'm running the Chromium WebGadget on laptops with Windows 10 / 11 Pro installed.

NOTE: The reported issue does not effect automating web tasks or remote controlling the numerous supported browsers.
Last edited by JHPJHP on Sun Dec 11, 2022 4:15 pm, edited 3 times in total.
normeus
Enthusiast
Enthusiast
Posts: 414
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Chromium WebGadget

Post by normeus »

JHPJHP,
First of all, thank you for all the work you do with PureBasic. One day I hope to have time and be able to play with all your cool contributions.
I downloaded the free version, (I do have access to your website, but like I said, I don't have time to try and use any of your cool libraries).
I ran "64x General Display.exe" and also "86x General Display.exe" on my 64 windows 10 machine:
Image
(Img of two grey boxes with "Chromium WebGadget" in the center)
This machine does have WebView2:
Image
(Img of WebView2 installed on my system)
General ChartJS.exe works but if I run it from a network drive I see the warning about MS edge that infratec mentioned.
I do have office 365 plus Chrome installed on this computer. I will try to do some further research.

Thank you.
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Chromium WebGadget

Post by JHPJHP »

Hi normeus,

Thank you for testing the executables, your feedback and positive comments are appreciated.
normeus wrote:I ran "64x General Display.exe" and also "86x General Display.exe" on my 64 windows 10 machine
Please note, the example General Display.exe requires the html folder from the original download to be located in the same directory as the executable; this is by design as it demonstrates the Chromium WebGadget's ability to load external html files.
normeus wrote:General ChartJS.exe works but if I run it from a network drive I see the warning about MS edge that infratec mentioned.
All the compiled examples include the Constant #Cr_WebGadget_User_Directory_Override. This modifies the creating and loading of the browser profile from the local directory (\Users\[user name]\Appdata\Roaming\) to the same folder where the example was executed. Removing this Constant should fix the problem and prevent the warning message.
normeus wrote:I do have office 365 plus Chrome installed on this computer. I will try to do some further research.
Please note, I don't always compile new executables with every revision. If possible, please download the latest version of the framework and run the examples from the PureBasic IDE.
Last edited by JHPJHP on Sun Dec 11, 2022 1:32 am, edited 1 time in total.
Locked