Faking flash plugin info in phantomjs 1.8-Collection of common programming errors

I’m a newbie to PhantomJs. I’m using 1.8.1 version. I’ve looked at here to solve this as i’ve similar requirement.

I’m doing something like this:

page.onInitialized = function () {
    page.evaluate(function () {
        (function () {
            window.navigator.plugins = {
                'length': 1, 
                'Shockwave Flash': {
                    'description':'fakeflash'
                }
            };
        })();
    });
};

When i do console.log (window.navigator.plugins[‘Shockwave Flash’].description)

I get undefined as the result.

Could anyone tell me what am doing wrong?

  1. Replace the entire navigator object (you can’t just modify some properties).

    var page = require('webpage').create();
    
    page.onConsoleMessage = function (msg) {
        console.log(msg);
    };
    
    page.onInitialized = function () {
        page.evaluate(function () {
            window.navigator = {
                plugins: {
                    length: 1,
                    'Shockwave Flash': {
                        description: 'fakeflash'
                    }
                }
            };
        });
    };
    
    page.content = 'Hello';
    page.evaluate(function () {
        console.log(window.navigator.plugins['Shockwave Flash'].description);
    });
    
    phantom.exit();
    

Originally posted 2013-11-10 03:08:45.