Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CasperJS and 'Unsafe JavaScript attempt to access frame with URL' error

I have simple page with javascript which validates email written in input:

email.html:

<!DOCTYPE html>
<html>
    <head>
        <title>Email validation</title>
        <script src="email.js"></script>
    </head>
    <body>
        <span style="padding: 5px;">
            <input type="text" id="email-input" placeholder="Email..."></input>
        </span>
    </body>
</html>

email.js:

var checkEmail = function() {
    var regexp = /BIG_REGEX/;
    var email = document.getElementById('email-input').value;
    if (email === '') 
        removeFrame();
    else if (regexp.test(email))
        drawFrame('green');
    else
        drawFrame('red');
};

var removeFrame = function() {
    var input = document.getElementById('email-input');
    input.parentNode.style.backgroundColor = input.parentNode.parentNode.style.backgroundColor;
};

var drawFrame = function(color) {
    var input = document.getElementById('email-input');
    input.parentNode.style.backgroundColor = color;
};


window.onload = function() {
    document.getElementById('email-input').onkeyup = checkEmail;
};

I want to test validation functionality using CasperJS. Here is my test case:

test/validator.test.js:

var fillEmail = function(browser, email) {
    browser.sendKeys('#email-input', email, {reset: true});
};

var getValidation = function(browser) {
    var color = browser.evaluate(function () {
        return document.getElementById('email-input').parentNode.style.backgroundColor;
    });
    return color;
};

var validate = function(browser, email) {
    fillEmail(browser, email);
    return getValidation(browser);
};

casper.test.begin('Validation testing', function suite(test) {
    casper.start('http://localhost:8000/email.html', function() {
        test.assertEquals(validate(this, '[email protected]'), 'green', '[email protected]');
        test.assertEquals(validate(this, 'vnbgfjbndkjnv'), 'red', 'vnbgfjbndkjnv');
    }).run(function() {
        test.done();
    });

});

But when I run tests using casperjs test test/validator.test.js, there is always error after information about tests:

Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///C:/Users/home/AppData/Roaming/npm/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.

What's wrong?

PhantomJS version: 1.9.8

like image 446
michaeluskov Avatar asked Oct 31 '14 08:10

michaeluskov


3 Answers

Recent PhantomJS (1.9.8) introduced this error message. It doesn't cause any real issue, other than confusing log lines when quiting PhantomJS.

It is fixed in unreleased 1.9 branch: https://github.com/ariya/phantomjs/pull/12720

like image 108
Jakozaur Avatar answered Oct 15 '22 03:10

Jakozaur


This issue is fixed in phantomjs version 1.9

"phantomjs": "^1.9.9"

for casperJs

casperjs --ssl-protocol=tlsv1 test  run.js
like image 1
PPB Avatar answered Oct 15 '22 02:10

PPB


I was getting this same error, so I tried updating to phantomjs 1.9.9 (from 1.9.8). However, I was getting an install error when trying to install 1.9.9, so I down rev-ed to phantomjs 1.9.7, and that fixed this error for me. So, it seems like this is an issue introduced in phantomjs 1.9.8.

like image 1
noobie Avatar answered Oct 15 '22 02:10

noobie