o2platform / chrome-js

Node-Webkit REPL
Apache License 2.0
17 stars 3 forks source link

Find way to use browser.get inside the target frame #2

Closed DinisCruz closed 9 years ago

DinisCruz commented 9 years ago

at the moment we have to use browser.eval("window.location.href='http://www.google.com'", function() ... (see https://github.com/o2platform/webkit-repl/blob/master/editor.html#L61) which is not a good solution

the problem is that calling browser.get('http://xyz.com', function() ..., will open that url in the main webkit window (not it the iframe1 frame)

DinisCruz commented 9 years ago

fixed using

                wd = require('wd');
                wd.addAsyncMethod('get',
                                  function(url) {
                                    var cb = wd.findCallback(arguments);
                                    this.eval('window.location.href="'+url+'"', cb);                                    
                                  });

as see in

_browser = function() 
            {                
                var chai = require("chai");
                var chaiAsPromised = require("chai-as-promised");
                chai.use(chaiAsPromised);
                chai.should();
                wd = require('wd');
                wd.addAsyncMethod('get',
                                  function(url) {
                                    var cb = wd.findCallback(arguments);
                                    this.eval('window.location.href="'+url+'"', cb);                                    
                                  });

                chaiAsPromised.transferPromiseness = wd.transferPromiseness;
                var browser = wd.promiseChainRemote();
                return browser.attach(sessionId)        
            }()