Browse Source

feat: use up2date Chromium user-agents for device descriptors (#6594)

pull/6635/head
Max Schmitt 4 weeks ago
committed by GitHub
parent
commit
9592486225
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/common/.npmignore
  2. 1145
      src/server/deviceDescriptors.js
  3. 1144
      src/server/deviceDescriptorsSource.json
  4. 6
      tests/inspector/cli-codegen-java.spec.ts
  5. 3
      tsconfig.json
  6. 16
      utils/doclint/cli.js

2
packages/common/.npmignore

@ -39,3 +39,5 @@ lib/**/injected/
!browsers.json
# Include commit info
!commitinfo
# Include generated devices descriptors
!deviceDescriptorsSource.json

1145
src/server/deviceDescriptors.js
File diff suppressed because it is too large
View File

1144
src/server/deviceDescriptorsSource.json
File diff suppressed because it is too large
View File

6
tests/inspector/cli-codegen-java.spec.ts

@ -50,14 +50,14 @@ test('should print the correct context options when using a device', async ({ br
test.skip(browserName !== 'chromium');
const cli = runCLI(['--device=Pixel 2', '--target=java', emptyHTML]);
await cli.waitFor(`setHasTouch(true));`);
const expectedResult = `BrowserContext context = browser.newContext(new Browser.NewContextOptions()
.setUserAgent("Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36")
.setUserAgent("Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/XXXX Mobile Safari/537.36")
.setViewportSize(411, 731)
.setDeviceScaleFactor(2.625)
.setIsMobile(true)
.setHasTouch(true));`;
await cli.waitFor(expectedResult);
expect(cli.text()).toContain(expectedResult);
expect(cli.text().replace(/(.*Chrome\/)(.*?)( .*)/m, '$1XXXX$3')).toContain(expectedResult);
});
test('should print the correct context options when using a device and additional options', async ({ browserName, runCLI }) => {

3
tsconfig.json

@ -12,8 +12,9 @@
"declaration": false,
"jsx": "react",
"downlevelIteration": true,
"resolveJsonModule": true,
},
"compileOnSave": true,
"include": ["src/**/*.ts", "src/**/*.js"],
"include": ["src/**/*.ts", "src/**/*.js", "src/server/deviceDescriptorsSource.json"],
"exclude": ["node_modules", "src/.eslintrc.js", "src/web/**", "src/**/*webpack.config.js"]
}

16
utils/doclint/cli.js

@ -43,8 +43,8 @@ async function run() {
documentation.filterForLanguage('js');
// Patch README.md
const versions = await getBrowserVersions();
{
const versions = await getBrowserVersions();
const params = new Map();
const { chromium, firefox, webkit } = versions;
params.set('chromium-version', chromium);
@ -65,6 +65,20 @@ async function run() {
writeAssumeNoop(path.join(PROJECT_DIR, 'README.md'), content, dirtyFiles);
}
// Update device descriptors
{
const devicesDescriptorsSourceFile = path.join(PROJECT_DIR, 'src', 'server', 'deviceDescriptorsSource.json')
const devicesDescriptors = require(devicesDescriptorsSourceFile)
for (const deviceName of Object.keys(devicesDescriptors))
if (devicesDescriptors[deviceName].defaultBrowserType === 'chromium') {
devicesDescriptors[deviceName].userAgent = devicesDescriptors[deviceName].userAgent.replace(
/(.*Chrome\/)(.*?)( .*)/,
`$1${versions.chromium}$3`
)
}
writeAssumeNoop(devicesDescriptorsSourceFile, JSON.stringify(devicesDescriptors, null, 2), dirtyFiles);
}
// Validate links
{
for (const file of fs.readdirSync(path.join(PROJECT_DIR, 'docs', 'src'))) {

Loading…
Cancel
Save