Skip to content

Instantly share code, notes, and snippets.

Created August 26, 2012 17:03
Show Gist options
  • Save papoms/3481673 to your computer and use it in GitHub Desktop.
Save papoms/3481673 to your computer and use it in GitHub Desktop.
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 = '';
function showInfo(){
console.log("window.document.referrer is: '" + window.document.referrer + "' of type: '" + typeof window.document.referrer+"'");
console.log("Status Quo");
// Trying to delete the property
console.log("Deleting document.referrer");
delete window.document.referrer;
// Manually setting the referrer
console.log('Manual overwrite')
window.document.referrer = myReferrer;
// defining a getter method
console.log('testing defineGetter');
window.document.__defineGetter__('referrer', function () {
return myReferrer;
page.onLoadFinished = function (status) {
Copy link

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 ""; });

now type in console:

you can see the changes...

Copy link

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