Skip to content

Instantly share code, notes, and snippets.

@strazzere
Created July 7, 2017 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save strazzere/eaabad67caf7760944da3822e9bb9955 to your computer and use it in GitHub Desktop.
Save strazzere/eaabad67caf7760944da3822e9bb9955 to your computer and use it in GitHub Desktop.
Quick test for Otto VM detection techniques
package main
import (
"fmt"
"github.com/robertkrimen/otto"
)
func main() {
vm := otto.New()
value, err := vm.Run(`
try {
// Mostly from http://browserhacks.com/
var ieVersion = /*@cc_on (function() {switch(@_jscript_version) {case 1.0: return 3; case 3.0: return 4; case 5.0: return 5; case 5.1: return 5; case 5.5: return 5.5; case 5.6: return 6; case 5.7: return 7; case 5.8: return 8; case 9: return 9; case 10: return 10;}})() || @*/ 0;
var isIE = /*@cc_on!@*/false;
console.log("ieVersion : " + ieVersion + " " + isIE);
var isFF1 = /a/[-1]=='a';
var isFF2 = (function x(){})[-6]=='x';
var isFF3 = typeof InstallTrigger !== 'undefined';
var isFF4 = (function x(){})[-5]=='x';
console.log("isFF : " + isFF1 + isFF2 + isFF3 + isFF4);
var isOpera = /^function \(/.test([].sort);
console.log("isOpera : " + isOpera);
var isSafari = /a/.__proto__=='//';
console.log("isSafari : " + isSafari);
var isVM1 = navigator;
var isVM2 = document;
var isVM3 = window;
} catch(err) {
console.log("Wat? " + err)
}
chrome = window.chrome;
if(chrome == undefined) {
console.log("I don't look like chrome...")
} else {
console.log("I do look like chrome!")
}
console.log("Wat?" + !!window.chrome && !!window.chrome.webstore); // 4
`)
fmt.Println(err)
fmt.Println(value)
}
rigby:otto-detect diff$ go build detect.go
rigby:otto-detect diff$ ./detect
ieVersion : 0 false
isFF : falsefalsefalsefalse
isOpera : false
isSafari : false
Wat? ReferenceError: 'navigator' is not defined
ReferenceError: 'window' is not defined
undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment