saadtazi / firefox-profile-js

Firefox Profile creation using nodejs and CLI
MIT License
60 stars 30 forks source link

Fail to set the firefox profile #95

Closed thomas-lee closed 7 years ago

thomas-lee commented 7 years ago

Tried to show the default homepage on firefox. But it didn't show the home page and it seems the options is not set. Any idea?

Env: FIREFOX_VERSION=55.0.3 GECKODRIVER_VERSION=0.18.0 selenium 3.5.3-astatine using this docker image https://hub.docker.com/r/selenium/node-firefox/

import wd from 'wd';
import FirefoxProfile from 'firefox-profile';

const serverConfig = {
  host: 'localhost',
  port: 7101,
};

const capabilities = {
  browserName: 'firefox',
  platform: 'ANY',
  version: ''
};

const fp = new FirefoxProfile();
fp.setPreference('browser.startup.homepage', 'http://google.com');
fp.updatePreferences();

fp.encoded((err, zippedProfile) => {
    if (err) {
        console.error('oops, an error occured:', err);
        return;
    }
    capabilities.firefox_profile = zippedProfile;
    const driver = wd.promiseChainRemote(serverConfig);
    driver.init(capabilities);
});
saadtazi commented 7 years ago

I assume that you are using geckodriver and a modern version of firefox?

If that's the case, after fighting with geckodriver and selenium-server (the key thing is to have geckodriver in the PATH), I figured that the prefs are now the following:

fp.setPreference('browser.startup.homepage', 'http://saadtazi.com');
fp.setPreference('browser.startup.page', '1'); // defaults to 0, which means 'Blank Page'

Note that browser.startup.page seems to correspond to the following dropdown: image

and that the profile needs to be placed under moz:firefoxOptons:

{
      browserName:'firefox',
      marionette: true,  // <-- it took me a while to figure out this one too!
        // firefox_profile: zippedProfile // <-- Not here...
        'moz:firefoxOptions': {
          profile: zippedProfile  // <-- ... but here
        }
      }

I hope it helps.

saadtazi commented 7 years ago

Note that I updated examples/example-wd.js in master (+ added some hints in the README)

Feel free ask any questions, or close the issue if this works for you.

thomas-lee commented 7 years ago

Thanks a lot, i can set the profile right now.

FYI, it seems firebug is deprecated and it seems need to sign or sth or firebug is a legacy extension. So it won't enable/open the firebug automatically according to your sample firefox profile preference in the latest firefox version.

Btw, i want to extract the browser console log from firefox just like chrome. I saw firefox is not currently supported with the webdriver API completely, so I can't get log (type browser) from the webdriver API directly. https://github.com/SeleniumHQ/selenium/issues/1161

I am not sure if i can get the browser log in other ways. I saw there are capabilities and example online about preferences. https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities

fp.setPreference("webdriver.log.file", "/tmp/firefox_console"); I can't find any files generated.

Also tried with

fp.setPreference('webdriver.log.driver', 'DEBUG');
fp.setPreference('marionette.logging', 'DEBUG');
fp.setPreference('extensions.logging.enabled', true);
fp.setPreference('webdriver.firefox.logfile', '/tmp/ff_log');

Do you have any ideas how i can get the firefox browser log from standalone selenium running with firefox driver (need to capture and send back to the client) ?

Is it possible to override the console method and get it back using js later ?

Another question is about fp.setPreference('saadt.coucou', 'console'); I don't understand what its usage..to get console ?

Thanks

saadtazi commented 7 years ago

Not sure how to get the log writen to a file, but there is a selenium command that allows to retrieve the log by type: POST /session/:sessionId/log (corresponding wdjs method: .log(type). Check here: https://github.com/admc/wd/blob/master/doc/api.md (i didn't test it myself...)

Note that there is a pending issue re: geckodrivee and error log: https://github.com/mozilla/geckodriver/issues/330

thomas-lee commented 7 years ago

Thanks for your information.

I have tried getLogType api, only 'server' is returned.

So it looks we can't get firefox browser log directly right now.