diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index b960409efdf2d..1824f88cf6770 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -1456,8 +1456,7 @@ void App::BuildPrototype(v8::Isolate* isolate, #if defined(OS_MACOSX) .SetProperty("dock", &App::GetDockAPI) #endif - .SetMethod("setUserAgentFallback", &App::SetUserAgentFallback) - .SetMethod("getUserAgentFallback", &App::GetUserAgentFallback) + .SetProperty("userAgentFallback", &App::GetUserAgentFallback, &App::SetUserAgentFallback) .SetMethod("enableSandbox", &App::EnableSandbox); } diff --git a/docs/api/app.md b/docs/api/app.md index 0ecb666580919..b79adc83a43a4 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -1373,6 +1373,15 @@ On macOS, setting this with any nonzero integer shows on the dock icon. On Linux **Note:** Unity launcher requires the existence of a `.desktop` file to work, for more information please read [Desktop Environment Integration][unity-requirement]. +### `app.userAgentFallback` + +A `String` which is the user agent string Electron will use as a global fallback. + +This is the user agent that will be used when no user agent is set at the +`webContents` or `session` level. Useful for ensuring your entire +app has the same user agent. Set to a custom value as early as possible +in your apps initialization to ensure that your overridden value is used. + ### `app.isPackaged` A `Boolean` property that returns `true` if the app is packaged, `false` otherwise. For many apps, this property can be used to distinguish development and production environments. diff --git a/spec-main/api-app-spec.ts b/spec-main/api-app-spec.ts index 4bcf7f4bdd318..40958954809ff 100644 --- a/spec-main/api-app-spec.ts +++ b/spec-main/api-app-spec.ts @@ -1310,6 +1310,30 @@ describe('default behavior', () => { expect(result).to.equal(true) }) }) + + describe('user agent fallback', () => { + let initialValue: string + + before(() => { + initialValue = app.userAgentFallback! + }) + + it('should have a reasonable default', () => { + expect(initialValue).to.include(`Electron/${process.versions.electron}`) + expect(initialValue).to.include(`Chrome/${process.versions.chrome}`) + }) + + it('should be overridable', () => { + app.userAgentFallback = 'test-agent/123' + expect(app.userAgentFallback).to.equal('test-agent/123') + }) + + it('should be restorable', () => { + app.userAgentFallback = 'test-agent/123' + app.userAgentFallback = '' + expect(app.userAgentFallback).to.equal(initialValue) + }) + }) }) async function runTestApp (name: string, ...args: any[]) { diff --git a/spec-main/index.js b/spec-main/index.js index 7e744b959b231..dd193a9c767b7 100644 --- a/spec-main/index.js +++ b/spec-main/index.js @@ -80,6 +80,6 @@ app.whenReady().then(() => { process.exit(runner.failures) }) } - const runner = (isCI) ? mocha.run(cb) : mocha.forbidOnly().run(cb) + const runner = (isCI) ? mocha.forbidOnly().run(cb) : mocha.run(cb) }) })