badeball / karma-jsdom-launcher

A Karma plugin. Launcher for jsdom.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

set userAgent invalid

leeziiAtCn opened this issue · comments

browsers: ['jsdom'], jsdomLauncher: { jsdom: { userAgent: 'asdasdasd' } },
i set userAgent as this, but i get jsdom default ua in test case , can u help me ?

Hi, @leeziiAtCn

The way to change user agent with jsdom changed with the new API / deprecation of the old, in version 12. See below for how you would now control the user agent (Disclaimer: I typed this straight into Github without testing it). See jsdom's own documentation for more information about configurating this.

const jsdom = require("jsdom");

module.exports = function(config) {
  config.set({
    browsers: ['jsdom'],

    jsdomLauncher: {
      jsdom: {
        resources: new jsdom.ResourceLoader({
          userAgent: "foobar",
        })
      }
    }
  });
};

I'll update the readme to reflect this.

@badeball
hi bro , thanks for your help !