Faking flash plugin info in phantomjs 1.8

I am new to PhantomJs. I am using version 1.8.1. I have looked here to resolve this as I have a similar requirement.

I am 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 am getting undefined as result.

Can anyone tell me what I am doing wrong?

+3


source to share


1 answer


Replace the whole object navigator

(you can't just change 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 = '<html><body>Hello</body></html>';
page.evaluate(function () {
    console.log(window.navigator.plugins['Shockwave Flash'].description);
});

phantom.exit();

      

+8


source







All Articles