Skip to content

Commit

Permalink
General fixes after merging into live environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Johanndutoit committed Aug 7, 2017
1 parent 91a01e1 commit 1f8b97f
Show file tree
Hide file tree
Showing 3 changed files with 314 additions and 259 deletions.
145 changes: 47 additions & 98 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Chrome = require('chrome-remote-interface');
const CDP = require('chrome-remote-interface');
const ChromePage = require('./page');
const fs = require('fs');
const _ = require('underscore')
Expand Down Expand Up @@ -78,7 +78,7 @@ module.exports = exports = function(options) {
ChromeClient.flush = function(fn) {

// connect to client
var scopedClient = Chrome({
CDP({

host: options.host,
port: options.port
Expand All @@ -98,12 +98,22 @@ module.exports = exports = function(options) {
// the entries
var entries = (result || {}).targetInfos || [];

// how many specials ?
var specialCount = 0;

// close targets
for(var i = 0; i < entries.length; i++) {

if(entries[i].url.indexOf('chrome://') === 0 ||
entries[i].url.indexOf('about://') === 0)
continue;
entries[i].url.indexOf('about://') === 0) {

// check if open
specialCount++;

// if special count is 1 or less
if(specialCount == 1) continue;

}

promises.push(Target.closeTarget({

Expand Down Expand Up @@ -157,7 +167,7 @@ module.exports = exports = function(options) {
var callback = params.callback;

// connect to client
var scopedClient = Chrome({
CDP({

host: options.host,
port: options.port,
Expand Down Expand Up @@ -212,35 +222,50 @@ module.exports = exports = function(options) {
}));
page.exit = function(cb) {

// close the target
Chrome.Close({
try {

host: options.host,
port: options.port,
id: targetid
// close the target
client.close();
fn(null);
cb(null);
return
Chrome.Close({

})
.then(function() {
host: options.host,
port: options.port,
id: targetid

fn(null);
if(cb) cb(null);
})
.then(function() {

})
.catch(function() {
fn(null);
cb(null);

})
.catch(function() {

fn(null);
cb(null);

})

} catch(err){

fn(null);
if(cb) cb(null);
cb(null);

})
}

};
page.close = function(cb) {

// close the page
page.disable();
page.disable(function() {

// totally close the page and client
page.exit(cb);
// close it
page.exit(cb || function(){});

});

};

Expand All @@ -253,16 +278,6 @@ module.exports = exports = function(options) {

});

scopedClient.on('error', function(err) {

// output the error
callback(err);

// totally close the page and client
page.exit();

});

};

/**
Expand All @@ -280,78 +295,12 @@ module.exports = exports = function(options) {

};

/**
// connect to client
var scopedClient = Chrome({
host: options.host,
port: options.port
}, (client) => {
// remove the notification
process.removeListener('unhandledRejection', rejectionHandler)
// check if we got a client ... ?
if(!client) {
// return error
fn(new Error('Problem connecting to ' + options.host + ':' + options.port))
// nope..
return
}
// extract what we want
const {Target} = client;
// create a target
Target.createTarget({
url: 'about:blank'
})
.then((result)=>{
// then close it
client.close()
// great pass this along
ChromeClient.handlePageRequest(result.targetId, params, fn);
})
.catch((err)=>{
// then close it
client.close()
// return it
callback(err);
// finish up
return fn();
})
});
// handle any errors
scopedClient.on('error', function (err){
// return the error
fn(err);
});
**/

// there seems to be a issue in the chrome-remote-interface library
// where a rejection error is not caught
process.once('unhandledRejection', rejectionHandler);

// create a new target
Chrome.New({
CDP.New({

host: options.host,
port: options.port,
Expand Down
Loading

0 comments on commit 1f8b97f

Please sign in to comment.