mirror of https://github.com/vitalif/phantomjs
Fix the last problem with setTimeout and setInterval
parent
1fb67c49e7
commit
3d0c56af40
|
@ -75,6 +75,39 @@ window.WebPage = function() {
|
|||
return page;
|
||||
}
|
||||
|
||||
|
||||
// override settimeout/setinterval with a try..catch
|
||||
window._setTimeout = window.setTimeout;
|
||||
window._setInterval = window.setInterval;
|
||||
window.setTimeout = function(func, delay) {
|
||||
var f = function() {
|
||||
try {
|
||||
typeof func === 'function' ? func() : eval(func);
|
||||
} catch (err) {
|
||||
if (err !== 'phantom.exit') {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return window._setTimeout(f, delay);
|
||||
}
|
||||
|
||||
window.setInterval = function(func, delay, lang) {
|
||||
var f = function() {
|
||||
try {
|
||||
typeof func === 'function' ? func() : eval(func);
|
||||
} catch (err) {
|
||||
if (err !== 'phantom.exit') {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return window._setInterval(f, delay, lang);
|
||||
}
|
||||
|
||||
|
||||
phantom.exit = function(code) {
|
||||
if (code == null) {
|
||||
code = 0;
|
||||
|
|
|
@ -75,6 +75,39 @@ window.WebPage = function() {
|
|||
return page;
|
||||
}
|
||||
|
||||
|
||||
// override settimeout/setinterval with a try..catch
|
||||
window._setTimeout = window.setTimeout;
|
||||
window._setInterval = window.setInterval;
|
||||
window.setTimeout = function(func, delay) {
|
||||
var f = function() {
|
||||
try {
|
||||
typeof func === 'function' ? func() : eval(func);
|
||||
} catch (err) {
|
||||
if (err !== 'phantom.exit') {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return window._setTimeout(f, delay);
|
||||
}
|
||||
|
||||
window.setInterval = function(func, delay, lang) {
|
||||
var f = function() {
|
||||
try {
|
||||
typeof func === 'function' ? func() : eval(func);
|
||||
} catch (err) {
|
||||
if (err !== 'phantom.exit') {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return window._setInterval(f, delay, lang);
|
||||
}
|
||||
|
||||
|
||||
phantom.exit = function(code) {
|
||||
if (code == null) {
|
||||
code = 0;
|
||||
|
|
Loading…
Reference in New Issue