Jump to content

_IESetEmbeddedBrowserEmulation()


argumentum
 Share

Recommended Posts

IE is not new but newer versions are not emulated ( IE8+ ) so a function to expressly set the IE version to load when embedded was needed. Otherwise some technologies will not behave as expected of a modern browser.

#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <WindowsConstants.au3>

Func _IEGetEmbeddedBrowserEmulation()
    Local $iRet = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", _
            StringTrimLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1)))
    Return SetError(@error, @extended, $iRet)
EndFunc   ;==>_IEGetEmbeddedBrowserEmulation

Func _IESetEmbeddedBrowserEmulation($FEATURE_BROWSER_EMULATION = Default) ; ..update as of 6/28/2020
    If Not Int($FEATURE_BROWSER_EMULATION) And Not IsKeyword($FEATURE_BROWSER_EMULATION) Then
        RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", _
                StringTrimLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1)))
        Return SetError(@error, 2, "")
    EndIf

    Local $iRet = _IEGetEmbeddedBrowserEmulation()
    If $FEATURE_BROWSER_EMULATION = Default Then $FEATURE_BROWSER_EMULATION = Int(FileGetVersion("ieframe.dll")) * 1000
    If Int($FEATURE_BROWSER_EMULATION) = 0 Then Return SetError(10, 3, $iRet)

    If $iRet <> $FEATURE_BROWSER_EMULATION Then ; https://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx
        $iRet = RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", _
                StringTrimLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1)), "REG_DWORD", $FEATURE_BROWSER_EMULATION)
        Return SetError(@error, 1, ($iRet = 1 ? $FEATURE_BROWSER_EMULATION : $iRet))
    EndIf
    Return $iRet
EndFunc   ;==>_IESetEmbeddedBrowserEmulation

Example()
Func Example() ; https://www.autoitscript.com/forum/topic/203209-_iesetEmbeddedBrowserEmulation/



    _IESetEmbeddedBrowserEmulation(0) ; remove setting. It'll default to IE 7.
;~  _IESetEmbeddedBrowserEmulation() ;  set default to available IExplorer in the OS.

    ConsoleWrite("_IEGetEmbeddedBrowserEmulation(): " & _IEGetEmbeddedBrowserEmulation() & @CRLF)



    Local $oIE = _IECreateEmbedded()
    _IEErrorHandlerRegister() ; this is here so CheckError() get to kick in
    GUICreate("Embedded Web control Test", 640, 580, _
            (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
            $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
    GUICtrlCreateObj($oIE, 10, 40, 600, 360)
    Local $idButton_Back = GUICtrlCreateButton("Back", 10, 420, 100, 30)
    Local $idButton_Forward = GUICtrlCreateButton("Forward", 120, 420, 100, 30)
    Local $idButton_Home = GUICtrlCreateButton("Home", 230, 420, 100, 30)
    Local $idButton_Stop = GUICtrlCreateButton("Stop", 340, 420, 100, 30)

    Global $g_idError_Message = GUICtrlCreateLabel("", 100, 500, 500, 30, -1, 0)
    GUICtrlSetColor(-1, 0xff0000)

    GUISetState(@SW_SHOW) ;Show GUI

    _IENavigate($oIE, "https://www.w3schools.com/js/tryit.asp?filename=tryjs_ajax_suggest_php")
    _IEAction($oIE, "stop")

    While 1
        Local $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $iMsg = $idButton_Home
                _IENavigate($oIE, "https://www.w3schools.com/js/tryit.asp?filename=tryjs_ajax_suggest_php")
                _IEAction($oIE, "stop")
                CheckError("Home", @error, @extended)
            Case $iMsg = $idButton_Back
                _IEAction($oIE, "back")
                CheckError("Back", @error, @extended)
            Case $iMsg = $idButton_Forward
                _IEAction($oIE, "forward")
                CheckError("Forward", @error, @extended)
            Case $iMsg = $idButton_Stop
                _IEAction($oIE, "stop")
                CheckError("Stop", @error, @extended)
        EndSelect
    WEnd

    GUIDelete()

EndFunc   ;==>Example

Func CheckError($sMsg, $iError, $iExtended)
    If $iError Then
        $sMsg = "Error using " & $sMsg & " button (" & $iExtended & ")"
    Else
        $sMsg = ""
    EndIf
    GUICtrlSetData($g_idError_Message, $sMsg)
EndFunc   ;==>CheckError

if within a week no one came up with better code, I'll add these 2 functions to the trac, to be evaluated for adding it to IE.au3 on a next beta :) 

oh, ..do uncomment the _IESetEmbeddedBrowserEmulation() to see the difference between declared emulation and not. 

Your ideas are very much welcomed.

PS: for now I guess this code is just an example.

6/27/2020 update: To look for the IE version and use that as the Default value. This way if you have, say v10.x.x.x, it will not try to emulate v11.
        The default browser value is the Int(version) & "000", so it does not need a lookup a table. Tested on XP, Win7 and Win10.

6/28/2020 update: Renamed the functions from *BrowserEmulation() to * EmbeddedBrowserEmulation() as it truly only applies to an Embedded Browser.
       Also changed the Version discovery form looking at the EXE to looking at the DLL.
      ( all this thanks to @Chimp's clues )

Edited by argumentum
better code

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Hi @argumentum,

shouldn't you also check whether to enable or disable the redirection of the WOW64 file system for 32-bit programs running on 64-bit systems so to avoid the not finding of those registry keys in that cases? (*)
p.s. take a look here too:

https://www.autoitscript.com/forum/topic/163492-ie-embedded-control-versioning-use-ie9-and-html5-in-a-gui/

https://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version

P.P.S.

(*) edit: The above would only be true if you chose to set these keys at machine level in HKLM. Since you have chosen to act at the current user level HKCU, it is not necessary. sorry for my inaccuracy

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

6 hours ago, Chimp said:

it is not necessary. sorry for my inaccuracy

oh, no. I like input.
The I rather have code than links (...I'm some what lazy and code is my mother tongue anyway) ;) 
This code is gonna go in the standard distribution of UDF so, look at it from every angle.
If you, or anyone, find's a detail that need attention, do post the code that would be best for the function.
This is not "my baby"/"my project"/"my etc.", this is our UDF, our code.
I never cared for intellectual property or to shine ( unless is in front of my parents and I did great in school :P )

Now back to seriousness:

6 hours ago, Chimp said:

Since you have chosen to act at the current user level HKCU

I believe that HKCU is better as in doing so, a limited user/non-admin user, need not anything special to read/write the registry.

As far as 

Int(FileGetVersion(@ProgramFilesDir & "\Internet Explorer\iexplore.exe"))

,the EXE is in both @ProgramFilesDir, x86 and x64 folders.

Looking at @Ascend4nt's code, getting the version from the DLL, is better.

Edited by argumentum
better code

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...