Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Try to overwrite window.document.referrer from within phantomjs / onInitialized
var page = require('webpage').create();
page.onConsoleMessage = function (msg) {
console.log('From Page Console: '+msg);
};
page.onInitialized = function() {
page.evaluate(function () {
"use strict";
//The Referrer we want to set
var myReferrer = 'http://referrer.example.com';
function showInfo(){
console.log("window.document.referrer is: '" + window.document.referrer + "' of type: '" + typeof window.document.referrer+"'");
};
//Before
console.log("Status Quo");
showInfo();
// Trying to delete the property
console.log("Deleting document.referrer");
delete window.document.referrer;
showInfo();
// Manually setting the referrer
console.log('Manual overwrite')
window.document.referrer = myReferrer;
showInfo();
// defining a getter method
console.log('testing defineGetter');
window.document.__defineGetter__('referrer', function () {
return myReferrer;
});
showInfo();
});
}
page.onLoadFinished = function (status) {
exit();
};
page.open('http://example.com');
@Mds92

This comment has been minimized.

Copy link

@Mds92 Mds92 commented Jun 18, 2016

I've just tested it, it doesn't change document.referrer !!!

@Eldair

This comment has been minimized.

Copy link

@Eldair Eldair commented Jun 29, 2016

Same here, there isn't any good solution.

@StasToken

This comment has been minimized.

Copy link

@StasToken StasToken commented Jun 30, 2018

I've just tested it, it doesn't change document.referrer !!! ну и че хуй забили и успокоились все блять что ли?

@irahulsaini

This comment has been minimized.

Copy link

@irahulsaini irahulsaini commented Jul 3, 2020

I've just tested it, it doesn't change document.referrer !!!

Open Console, Copy Paste and Hit Hinter:
delete window.document.referrer; window.document.__defineGetter__('referrer', function () { return "yoururl.com"; });

now type in console:
document.referrer
or
window.document.referrer

you can see the changes...

@papoms

This comment has been minimized.

Copy link
Owner Author

@papoms papoms commented Jul 3, 2020

Hey, this was a snippet to show that phantomjs did not pass the referrer as expected. So it not working in the original version of phantomjs is expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.