[Gambas-user] Many Java Script messages when displaying html in webview

Brian G brian at westwoodsvcs.com
Wed Sep 27 16:48:02 CEST 2023


If anyone is interested I found the following solution. Tried using 
*error**to* and *output to*, but these only redirect the gambas3 io 
instructions. So I included the following code in my program. This uses 
the system calls dup and dup2 to temporarily replace the stdout and 
stderr handle with a handle to  /dev/null. This then just writes the 
messages to the bit bucket.

In my case I am dynamically creating the webview window as a task and 
controlling it from my main application.

Using the c system library calls to duplicate the file descriptors

    extern dup(oldHandle as integer) as integer in "libc:6"
    extern dup2(newHandle as integer, replaceiHandle as integer) as 
integer in "libc:6"
    Public OldStdout as integer
    Public OldStderr as integer
    Public StdOut as integer = 1
    Public StdErr as integer = 2


Then in the function just before opening the webView

     Dim efile as file
     efile = open "/dev/null" for write
     OldStdout = dup(StdOut)                ' We must save the old 
stdout handle
     OldStderr = dup(StdErr)                  ' We must also save the 
old stderr handle
     dup2(efile.handle,StdOut)               ' use our file handle
     dup2(efile.handle,StdErr)                ' use our file handle
     close efile                                        ' Close this 
file as we don't need it any more

Then just after the webview closes, perhaps in the close event to 
restore the original file descriptors

     dup2(OldStderr,StdOut)
     dup2(OldStderr,StdErr)

This seems to work, If anyone has a reason not to do this, please send a 
comment!

~~~~~~~~~~~~~ Brian G

On 9/26/23 12:26, Brian G wrote:
> When I am displaying a webview with a url being displayed I start to 
> get a lot of js messages sent to the std out it is a problem for my app.
>
> Is there some way to suppress the js output from the webview component ?
>
> See attached image as an example.
>
>
>
> ----[http://gambaswiki.org/wiki/doc/netiquette  ]----

-- 
~~~~ Brian

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230927/bcb959b0/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0x78BFB26402F48419.asc
Type: application/pgp-keys
Size: 2428 bytes
Desc: OpenPGP public key
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230927/bcb959b0/attachment.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 665 bytes
Desc: OpenPGP digital signature
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230927/bcb959b0/attachment.sig>


More information about the User mailing list