From 918956822a751816ebb2dd23f1a9be0f24499181 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 14 Oct 2026 08:37:29 -0700 Subject: [PATCH 1/3] fix(fill): accept datetime-local values the browser re-serializes Fixes: https://github.com/microsoft/playwright/issues/43370 --- packages/injected/src/injectedScript.ts | 5 +++-- tests/page/page-fill.spec.ts | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/injected/src/injectedScript.ts b/packages/injected/src/injectedScript.ts index f9cd653334778..d23a55ec9fd01 100644 --- a/packages/injected/src/injectedScript.ts +++ b/packages/injected/src/injectedScript.ts @@ -925,8 +925,9 @@ export class InjectedScript { value = value.trim(); input.focus(); input.value = value; - // The browser serializes range values in canonical form, e.g. "0.850" becomes "0.85". - const accepted = type === 'range' ? Number(input.value) === Number(value) : input.value === value; + // The browser serializes some values in canonical form, e.g. range "0.850" becomes "0.85" and + // datetime-local "2020-03-02T05:15:00" becomes "2020-03-02T05:15". Invalid dates and times become "". + const accepted = input.value === value || (type === 'range' ? Number(input.value) === Number(value) : type !== 'color' && !!input.value); if (!accepted) throw this.createStacklessError('Malformed value'); element.dispatchEvent(new Event('input', { bubbles: true, composed: true })); diff --git a/tests/page/page-fill.spec.ts b/tests/page/page-fill.spec.ts index b667825e0e84a..fe21f475ba4ca 100644 --- a/tests/page/page-fill.spec.ts +++ b/tests/page/page-fill.spec.ts @@ -197,10 +197,15 @@ it('should throw on incorrect time', async ({ page, browserName }) => { expect(error.message).toContain('Malformed value'); }); -it('should fill datetime-local input', async ({ page, server }) => { +it('should fill datetime-local input', { + annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43370' }, +}, async ({ page, server }) => { await page.setContent(''); await page.fill('input', '2020-03-02T05:15'); expect(await page.$eval('input', input => input.value)).toBe('2020-03-02T05:15'); + // The browser omits zero seconds. + await page.fill('input', '2020-03-02T06:20:00'); + expect(await page.$eval('input', input => input.value)).toBe('2020-03-02T06:20'); }); it('should throw on incorrect datetime-local', async ({ page, server, browserName }) => { From f22e9b8b49ead5f21912783272a28e8e441c6932 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 14 Oct 2026 11:55:39 -0700 Subject: [PATCH 2/3] chore(fill): split the accepted value check into statements --- packages/injected/src/injectedScript.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/injected/src/injectedScript.ts b/packages/injected/src/injectedScript.ts index d23a55ec9fd01..b7a65eeace127 100644 --- a/packages/injected/src/injectedScript.ts +++ b/packages/injected/src/injectedScript.ts @@ -925,9 +925,14 @@ export class InjectedScript { value = value.trim(); input.focus(); input.value = value; - // The browser serializes some values in canonical form, e.g. range "0.850" becomes "0.85" and - // datetime-local "2020-03-02T05:15:00" becomes "2020-03-02T05:15". Invalid dates and times become "". - const accepted = input.value === value || (type === 'range' ? Number(input.value) === Number(value) : type !== 'color' && !!input.value); + // The browser may serialize the value in canonical form, e.g. range "0.850" becomes "0.85" and + // datetime-local "2020-03-02T05:15:00" becomes "2020-03-02T05:15". It replaces an invalid value: + // range with its default, color with "#000000", dates and times with "". + let accepted = input.value === value; + if (!accepted && type === 'range') + accepted = Number(input.value) === Number(value); + else if (!accepted && type !== 'color') + accepted = !!input.value; if (!accepted) throw this.createStacklessError('Malformed value'); element.dispatchEvent(new Event('input', { bubbles: true, composed: true })); From cd452f8af74061e593b7b10613f5feca07d12dab Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 14 Oct 2026 13:45:00 -0700 Subject: [PATCH 3/3] chore(fill): only accept re-serialized values for datetime-local --- packages/injected/src/injectedScript.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/injected/src/injectedScript.ts b/packages/injected/src/injectedScript.ts index b7a65eeace127..2572c6296099b 100644 --- a/packages/injected/src/injectedScript.ts +++ b/packages/injected/src/injectedScript.ts @@ -925,13 +925,12 @@ export class InjectedScript { value = value.trim(); input.focus(); input.value = value; - // The browser may serialize the value in canonical form, e.g. range "0.850" becomes "0.85" and - // datetime-local "2020-03-02T05:15:00" becomes "2020-03-02T05:15". It replaces an invalid value: - // range with its default, color with "#000000", dates and times with "". + // The browser serializes some values in canonical form, e.g. range "0.850" becomes "0.85" and + // datetime-local "2020-03-02T05:15:00" becomes "2020-03-02T05:15". Invalid datetime-local values become "". let accepted = input.value === value; if (!accepted && type === 'range') accepted = Number(input.value) === Number(value); - else if (!accepted && type !== 'color') + else if (!accepted && type === 'datetime-local') accepted = !!input.value; if (!accepted) throw this.createStacklessError('Malformed value');