It is currently Mon Nov 20, 2017 1:06 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: WebGadget; FEATURE_BROWSER_EMULATION; Windows 10;
PostPosted: Sun Jul 09, 2017 4:46 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 19, 2010 3:42 am
Posts: 417
Hello!

I need help getting FEATURE_BROWSER_EMULATION running.

I have an HTA file with borwser detection.

When putting mshta.exe into registry ../Main/FeatureControl/FEATURE_BROWSER_EMULATION/mshta.exe, put
Code:
<meta http-equiv="x-ua-compatible" content="ie=11">

into HTML header and start my HTA, it gives
Code:
Browser name = Netscape
Full version = 5
Major version = 5
navigator.appName = Netscape
navigator.userAgent = Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; rv:11.0) like Gecko

It changed the default entry to somewhat newer.

I tried this for PureBasic WebGadget like given example at http://www.purebasic.fr/english/viewtopic.php?f=13&t=68219&p=505947&hilit=FEATURE_BROWSER_EMULATION#p505947, but no success.

Any comibnation of settings explained on https://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx#browser_emulation did not work.

Browser detection is always:
Code:
Browser name = Microsoft Internet Explorer
Full version = 7.0
Major version = 7
navigator.appName = Microsoft Internet Explorer
navigator.userAgent = Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)

which is old version IE7.0

Of course, IE11 is installed on system...

Is webgadget not able to use FEATURE_BROWSER_EMULATION?


Thanks for any hint!



Here the PureBasic code:
Code:
EnableExplicit


declare RegisterFeatureBrowserEmulation()
declare UnRegisterFeatureBrowserEmulation()


RegisterFeatureBrowserEmulation()

If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    WebGadget(0, 10, 10, 580, 280, "file:///D:\REVIEW/HTA/Test.html")
   
    Repeat
    Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf




Procedure RegisterFeatureBrowserEmulation()
;===== Registry: temp setting to optimise web gadget: Use when Install Program ====
protected sglpValueName.s = GetFilePart(ProgramFilename());"C:\D\REVIEW\PureBasic\PureBasic_Compilation0.exe")
protected lglpData.l = 11001
protected lglpdwDisposition.l
protected igphkResult.i

If RegCreateKeyEx_(#HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", 0, #Null, #REG_OPTION_VOLATILE, #KEY_ALL_ACCESS, #Null, @igphkResult, @lglpdwDisposition) = #ERROR_SUCCESS
  RegSetValueEx_(igphkResult, sglpValueName, 0, #REG_DWORD, @lglpData, SizeOf(LONG))
  RegCloseKey_(igphkResult)
EndIf
EndProcedure

Procedure OpenHtml()
protected File2Read.s = GetCurrentDirectory() + "index.html"

OpenWindow(1, 0, 0, 0, 0, "",#PB_Window_BorderLess|#PB_Window_Maximize)
SetWindowColor(1,$660000)
WebGadget(0, 0, 0, WindowWidth(1), WindowHeight(1), File2Read)
EndProcedure

Procedure UnRegisterFeatureBrowserEmulation()
 ;==== Registry: temp setting to optimise web gadget: Use when uninstall program ====
protected sglpValueName.s = GetFilePart(ProgramFilename())
protected lglpData.l = 11001
protected lglpdwDisposition.l
protected igphkResult.i

If RegOpenKeyEx_(#HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", 0, #KEY_SET_VALUE, @igphkResult) = #ERROR_SUCCESS
  RegDeleteValue_(igphkResult, sglpValueName)
  RegCloseKey_(igphkResult)
EndIf
EndProcedure



here the html code:
Code:
<!DOCTYPE html>
<html>
   <head>
      <meta http-equiv="x-ua-compatible" content="ie=11">
      
      <script>
         function testFileCreation(){
            var fso = new ActiveXObject("Scripting.FileSystemObject");

            var a = fso.CreateTextFile("d:\\temp\\testfile.txt", true);

            a.WriteLine("This is a test.");

            a.Close();   
         }
         
         window.resizeTo(480 * 2, 320 * 2);
         
         window.onload = function (){
            TA.innerText = navigator.userAgent;
         };
         
         
         var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName  = navigator.appName;
var fullVersion  = ''+parseFloat(navigator.appVersion);
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;

// In Opera 15+, the true version is after "OPR/"
if ((verOffset=nAgt.indexOf("OPR/"))!=-1) {
 browserName = "Opera";
 fullVersion = nAgt.substring(verOffset+4);
}
// In older Opera, the true version is after "Opera" or after "Version"
else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
 browserName = "Opera";
 fullVersion = nAgt.substring(verOffset+6);
 if ((verOffset=nAgt.indexOf("Version"))!=-1)
   fullVersion = nAgt.substring(verOffset+8);
}
// In MSIE, the true version is after "MSIE" in userAgent
else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
 browserName = "Microsoft Internet Explorer";
 fullVersion = nAgt.substring(verOffset+5);
}
// In Chrome, the true version is after "Chrome"
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
 browserName = "Chrome";
 fullVersion = nAgt.substring(verOffset+7);
}
// In Safari, the true version is after "Safari" or after "Version"
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
 browserName = "Safari";
 fullVersion = nAgt.substring(verOffset+7);
 if ((verOffset=nAgt.indexOf("Version"))!=-1)
   fullVersion = nAgt.substring(verOffset+8);
}
// In Firefox, the true version is after "Firefox"
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
 browserName = "Firefox";
 fullVersion = nAgt.substring(verOffset+8);
}
// In most other browsers, "name/version" is at the end of userAgent
else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) <
          (verOffset=nAgt.lastIndexOf('/')) )
{
 browserName = nAgt.substring(nameOffset,verOffset);
 fullVersion = nAgt.substring(verOffset+1);
 if (browserName.toLowerCase()==browserName.toUpperCase()) {
  browserName = navigator.appName;
 }
}
// trim the fullVersion string at semicolon/space if present
if ((ix=fullVersion.indexOf(";"))!=-1)
   fullVersion=fullVersion.substring(0,ix);
if ((ix=fullVersion.indexOf(" "))!=-1)
   fullVersion=fullVersion.substring(0,ix);

majorVersion = parseInt(''+fullVersion,10);
if (isNaN(majorVersion)) {
 fullVersion  = ''+parseFloat(navigator.appVersion);
 majorVersion = parseInt(navigator.appVersion,10);
}

document.write(''
 +'Browser name  = '+browserName+'<br>'
 +'Full version  = '+fullVersion+'<br>'
 +'Major version = '+majorVersion+'<br>'
 +'navigator.appName = '+navigator.appName+'<br>'
 +'navigator.userAgent = '+navigator.userAgent+'<br>'
)

      </script>
   </head>
   <body>
      <input type="textbox" value="?"/>
      <input type="button" value="o.k."/>
      <br/>
      
      <textarea id="TA" style="width:10cm; height:5cm"></textarea>
   </body>
</html>


Top
 Profile  
Reply with quote  
 Post subject: Re: WebGadget; FEATURE_BROWSER_EMULATION; Windows 10;
PostPosted: Sun Jul 09, 2017 7:19 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 19, 2010 3:42 am
Posts: 417
o.k. found this:

Quote:
Note: The user agent string sent to the server in the request is IE 7. Be aware of this mismatch if you will also be browsing to the same content in the IE browser. The full IE browser would send an IE 11 user agent string unless the site was included in the compatibility view list. If your web page is doing browser sniffing via the user agent string, you could encounter rendering differences or errors.


I know useragent detection is not good as browser feature detection is...


Top
 Profile  
Reply with quote  
 Post subject: Re: WebGadget; FEATURE_BROWSER_EMULATION; Windows 10;
PostPosted: Sat Jul 15, 2017 1:36 am 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1366
Hi HanPBF,

Enhanced examples using FEATURE_BROWSER_EMULATION (previously mentioned here):
- Barcode Generator, Embed JS into PureBasic, Geolocation: Google Maps

Modifying FEATURE_BROWSER_EMULATION with one of the following values will change the output:
Quote:
11001 Internet Explorer 11. Webpages are displayed in IE11 edge mode, regardless of the !DOCTYPE directive.
11000 IE11. Webpages containing standards-based !DOCTYPE directives are displayed in IE11 edge mode. Default value for IE11.
10001 Internet Explorer 10. Webpages are displayed in IE10 Standards mode, regardless of the !DOCTYPE directive.
10000 Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode. Default value for Internet Explorer 10.
9999 Windows Internet Explorer 9. Webpages are displayed in IE9 Standards mode, regardless of the !DOCTYPE directive.
9000 Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.
8888 Webpages are displayed in IE8 Standards mode, regardless of the !DOCTYPE directive.
8000 Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. Default value for Internet Explorer 8
7000 Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. Default value for applications hosting the WebBrowser Control.

Try the following:
Code:
Enumeration
  #MainWindow
  #WebGadget
EndEnumeration

Procedure BrowserDetection(HTML.s)
  lpValueName.s = GetFilePart(ProgramFilename()) : lpData = 11001

  If RegCreateKeyEx_(#HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", 0, #Null, #REG_OPTION_VOLATILE, #KEY_ALL_ACCESS, #Null, @phkResult, @lpdwDisposition) = #ERROR_SUCCESS
    RegSetValueEx_(phkResult, lpValueName, 0, #REG_DWORD, @lpData, SizeOf(LONG))
    RegCloseKey_(phkResult)

    If OpenWindow(#MainWindow, 0, 0, 640, 480, "Browser Detection", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_Invisible)
      WebGadget(#WebGadget, 0, 0, 640, 480, #Null$)
      SetWindowLongPtr_(GadgetID(#WebGadget), #GWL_STYLE, GetWindowLongPtr_(GadgetID(#WebGadget), #GWL_STYLE) | #WS_CLIPSIBLINGS)
      SetWindowPos_(GadgetID(#WebGadget), #HWND_BOTTOM, #Null, #Null, #Null, #Null, #SWP_NOSIZE | #SWP_NOMOVE)
      SetGadgetAttribute(#WebGadget, #PB_Web_BlockPopupMenu, #True)
      SetGadgetAttribute(#WebGadget, #PB_Web_BlockPopups, #True)
      WebBrowser2.IWebBrowser2 = GetWindowLongPtr_(GadgetID(#WebGadget), #GWL_USERDATA)
      WebBrowser2\put_Silent(#True)
      SetGadgetItemText(#WebGadget, #PB_Web_HtmlCode, HTML)
      StickyWindow(#MainWindow, #True) : HideWindow(#MainWindow, #False)
      Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
    EndIf

    If RegOpenKeyEx_(#HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", 0, #KEY_SET_VALUE, @phkResult) = #ERROR_SUCCESS
      RegDeleteValue_(phkResult, lpValueName)
      RegCloseKey_(phkResult)
    EndIf
  Else
    MessageRequester("Browser Detection", "Registry update failed." + #LF$ + #LF$ + "Operation cancelled.", #MB_ICONERROR)
  EndIf
EndProcedure

HTML.s = "<!DOCTYPE html>" + #LF$ +
         "<html>" + #LF$ +
         #TAB$ + "<head>" + #LF$ +
         #TAB$ + #TAB$ + "<meta http-equiv='X-UA-Compatible' content='IE=11'>" + #LF$ +
         #TAB$ + #TAB$ + "<script>" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "window.onload=function (){" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "TA.innerText=navigator.userAgent;" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "};" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "var nVer=navigator.appVersion;" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "var nAgt=navigator.userAgent;" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "var browserName=navigator.appName;" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "var fullVersion=''+parseFloat(navigator.appVersion);" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "var majorVersion=parseInt(navigator.appVersion,10);" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "var nameOffset,verOffset,ix;" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "if ((verOffset=nAgt.indexOf('OPR/'))!=-1) {" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "browserName='Opera';" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "fullVersion=nAgt.substring(verOffset+4);" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "}" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "else if ((verOffset=nAgt.indexOf('Opera'))!=-1) {" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "browserName='Opera';" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "fullVersion=nAgt.substring(verOffset+6);" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "if ((verOffset=nAgt.indexOf('Version'))!=-1)" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + #TAB$ + "fullVersion=nAgt.substring(verOffset+8);" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "}" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "else if ((verOffset=nAgt.indexOf('MSIE'))!=-1) {" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "browserName='Microsoft Internet Explorer';" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "fullVersion=nAgt.substring(verOffset+5);" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "}" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "else if ((verOffset=nAgt.indexOf('Chrome'))!=-1) {" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "browserName='Chrome';" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "fullVersion=nAgt.substring(verOffset+7);" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "}" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "else if ((verOffset=nAgt.indexOf('Safari'))!=-1) {" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "browserName='Safari';" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "fullVersion=nAgt.substring(verOffset+7);" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "if ((verOffset=nAgt.indexOf('Version'))!=-1)" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + #TAB$ + "fullVersion=nAgt.substring(verOffset+8);" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "}" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "else if ((verOffset=nAgt.indexOf('Firefox'))!=-1) {" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "browserName='Firefox';" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "fullVersion=nAgt.substring(verOffset+8);" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "}" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "else if ((nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/'))) {" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "browserName=nAgt.substring(nameOffset,verOffset);" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "fullVersion=nAgt.substring(verOffset+1);" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "if (browserName.toLowerCase()==browserName.toUpperCase()) {" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + #TAB$ + "browserName=navigator.appName;" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "}" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "}" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "if ((ix=fullVersion.indexOf(';'))!=-1)" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "fullVersion=fullVersion.substring(0,ix);" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "if ((ix=fullVersion.indexOf(' '))!=-1)" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "fullVersion=fullVersion.substring(0,ix);" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "majorVersion=parseInt(''+fullVersion,10);" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "if (isNaN(majorVersion)) {" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "fullVersion =''+parseFloat(navigator.appVersion);" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "majorVersion=parseInt(navigator.appVersion,10);" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "}" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + "document.write(''" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "+'Browser name = '+browserName+'<br>'" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "+'Full version = '+fullVersion+'<br>'" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "+'Major version = '+majorVersion+'<br>'" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "+'App Name = '+navigator.appName+'<br>'" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + #TAB$ + "+'User Agent = '+navigator.userAgent+'<br><br>'" + #LF$ +
         #TAB$ + #TAB$ + #TAB$ + ")" + #LF$ +
         #TAB$ + #TAB$ + "</script>" + #LF$ +
         #TAB$ + "</head>" + #LF$ +
         #TAB$ + "<body>" + #LF$ +
         #TAB$ + #TAB$ + "<textarea id='TA' style='width:10cm; height:5cm'></textarea>" + #LF$ +
         #TAB$ + "</body>" + #LF$ +
         "</html>"
BrowserDetection(HTML)

_________________
ImageMy PureBasic Stuff


Top
 Profile  
Reply with quote  
 Post subject: Re: WebGadget; FEATURE_BROWSER_EMULATION; Windows 10;
PostPosted: Sun Jul 16, 2017 2:25 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 19, 2010 3:42 am
Posts: 417
Thanks a lot for the great example!

Have seen a 32MB limit (at my site) for document.title.
Should be enough for some data exchange;-)

Browser emulation does work indeed.

At the moment the best way to combine PureBasic with ubiquitous web technology (for intranet).

Node.js (Electron framework) lacks debugging somewhat.

With the runtime library in PureBasic, message passing is easily done!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye