GithubHelp home page GithubHelp logo

Add geolocation support about webshell HOT 2 CLOSED

djyde avatar djyde commented on June 28, 2024
Add geolocation support

from webshell.

Comments (2)

0xWDG avatar 0xWDG commented on June 28, 2024

Difficult. we can enable it via private headers, but we don't do that that will cause App Store submits to rejected.

- (BOOL)webView:(WebView *)sender frame:(WebFrame *)frame requestGeolocationPermission:(WebGeolocation *)geolocation securityOrigin:(WebSecurityOrigin *)origin;

See also:

But i did some research.

 ["city": "Haarlem", "country": "The Netherlands", "alt": -1.8790876865387, "cource": -1.0, "subadministrative": "Haarlem", "ocean": "", "lat": 52.3593304249772, "spreed": -1.0, "name": "Baron de Coubertinstraat 25", "countrycode": "NL", "inlandwater": "", "number": "25", "street": "Baron de Coubertinstraat", "neighborhood": "", "postal": "2037 HA", "lon": 4.66551022283385, "administrative": "North Holland", "poi": ""]
 JS: Added location 

Some technical scripting info.

// For later use.
let locationManager = CLLocationManager()
var currentLocation: [String: Any] = ["lat": 0, "lon": 0, "name": "", "street": "", "number": "", "city": "", "neighborhood": "", "administrative": "", "subadministrative": "", "postal": "", "countrycode": "", "country": "", "inlandwater": "", "ocean": "", "poi": ""]

func websiteWantsLocation() -> Void {
    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.startUpdatingLocation()
    print("Getting location?")
    print(locationManager.location)
}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [AnyObject]) {
    let location: CLLocation = locations[0] as! CLLocation

    CLGeocoder().reverseGeocodeLocation(location) {(let myPlacemark, theError) -> Void in
        if (myPlacemark != nil) {
            let place: CLPlacemark = (myPlacemark?.first)!
            self.currentLocation["name"]   = place.name != nil ? place.name! : ""
            self.currentLocation["street"] = place.thoroughfare != nil ? place.thoroughfare! : ""
            self.currentLocation["number"] = place.subThoroughfare != nil ? place.subThoroughfare! : ""
            self.currentLocation["city"] = place.locality != nil ? place.locality! : ""
            self.currentLocation["neighborhood"] = place.subLocality != nil ? place.subLocality! : ""
            self.currentLocation["administrative"] = place.administrativeArea != nil ? place.administrativeArea! : ""
            self.currentLocation["subadministrative"] = place.subAdministrativeArea != nil ? place.subAdministrativeArea : ""
            self.currentLocation["postal"] = place.postalCode != nil ? place.postalCode! : ""
            self.currentLocation["countrycode"] = place.ISOcountryCode != nil ? place.ISOcountryCode! : ""
            self.currentLocation["country"] = place.country != nil ? place.country! : ""
            self.currentLocation["inlandwater"] = place.inlandWater != nil ? place.inlandWater! : ""
            self.currentLocation["ocean"] = place.ocean != nil ? place.ocean! : ""
            self.currentLocation["poi"] = place.areasOfInterest != nil ? place.areasOfInterest! : ""
            print(self.currentLocation)
            // will be called a thousand times or so.

            // Ok inject new java Thing! (Cool!)
            self.mainWebview.mainFrame.javaScriptContext.evaluateScript("function navigator.geolocation.getCurrentPosition(callback, error, whatever) {callback('hi')}") // Does not work
            self.mainWebview.mainFrame.javaScriptContext.evaluateScript("navigator.geolocation = {getCurrentPosition:function(call, err, we){call('hi')}}") // Does even not work
            self.mainWebview.mainFrame.javaScriptContext.evaluateScript("console.log('Added location');")
        }
    }
    currentLocation["lat"] = location.coordinate.latitude
    currentLocation["lon"] = location.coordinate.longitude
    currentLocation["alt"] = location.altitude
    currentLocation["cource"] = location.course
    currentLocation["spreed"] = location.speed
    }

func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
    print("Error while updating location " + error.localizedDescription)
}

The problem i got there is i can't rewrite the navigator.geolocation class.

For the rest, if you run:

> navigator.geolocation.getCurrentPosition(function(position) {
  console.log(position);
},function(position) {
  console.log(position);
});
< undefined

Then WebShell will error (in console)

JS: [object PositionError] 

I don't have a solution ready, sorry.
I'll keep on looking

from webshell.

0xWDG avatar 0xWDG commented on June 28, 2024

Ok, i'll think i know how to fix it.
Since

navigator.geolocation.getCurrentPosition(function(position) {
  console.log(position);
},function(position) {
  console.log(position);
});

is not a listener i can directly return the values. (if i save them)
but, i will make a config flag for it, because by default location needs to be disabled.

-> Note to myself: Inject hook, and return dictionary data.

from webshell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.