Skip to content

Commit 012bf67

Browse files
authored
feat(webkit): emulate timezone on webkit (#968)
1 parent d26f47b commit 012bf67

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"playwright": {
1111
"chromium_revision": "740847",
1212
"firefox_revision": "1028",
13-
"webkit_revision": "1146"
13+
"webkit_revision": "1147"
1414
},
1515
"scripts": {
1616
"ctest": "cross-env BROWSER=chromium node test/test.js",

src/webkit/wkConnection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export class WKSession extends platform.EventEmitter {
166166
export function createProtocolError(error: Error, method: string, object: { error: { message: string; data: any; }; }): Error {
167167
let message = `Protocol error (${method}): ${object.error.message}`;
168168
if ('data' in object.error)
169-
message += ` ${object.error.data}`;
169+
message += ` ${JSON.stringify(object.error.data)}`;
170170
return rewriteError(error, message);
171171
}
172172

src/webkit/wkPage.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ export class WKPage implements PageDelegate {
146146
promises.push(session.send('Network.setExtraHTTPHeaders', { headers: this._page._state.extraHTTPHeaders }));
147147
if (this._page._state.hasTouch)
148148
promises.push(session.send('Page.setTouchEmulationEnabled', { enabled: true }));
149+
if (contextOptions.timezoneId) {
150+
promises.push(session.send('Page.setTimeZone', { timeZone: contextOptions.timezoneId }).
151+
catch(e => { throw new Error(`Invalid timezone ID: ${contextOptions.timezoneId}`); }));
152+
}
149153
await Promise.all(promises);
150154
}
151155

test/emulation.spec.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,24 +193,36 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FF
193193
});
194194
});
195195

196-
describe.skip(FFOX || WEBKIT)('BrowserContext({timezoneId})', function() {
196+
describe.skip(FFOX)('BrowserContext({timezoneId})', function() {
197197
it('should work', async ({ newPage }) => {
198198
const func = () => new Date(1479579154987).toString();
199199
{
200200
const page = await newPage({ timezoneId: 'America/Jamaica' });
201-
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 13:12:34 GMT-0500 (Eastern Standard Time)');
201+
if (WEBKIT)
202+
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 13:12:34 GMT-0500 (America/Jamaica)');
203+
else
204+
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 13:12:34 GMT-0500 (Eastern Standard Time)');
202205
}
203206
{
204207
const page = await newPage({ timezoneId: 'Pacific/Honolulu' });
205-
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 08:12:34 GMT-1000 (Hawaii-Aleutian Standard Time)');
208+
if (WEBKIT)
209+
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 08:12:34 GMT-1000 (Pacific/Honolulu)');
210+
else
211+
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 08:12:34 GMT-1000 (Hawaii-Aleutian Standard Time)');
206212
}
207213
{
208214
const page = await newPage({ timezoneId: 'America/Buenos_Aires' });
209-
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 15:12:34 GMT-0300 (Argentina Standard Time)');
215+
if (WEBKIT)
216+
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 15:12:34 GMT-0300 (America/Buenos_Aires)');
217+
else
218+
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 15:12:34 GMT-0300 (Argentina Standard Time)');
210219
}
211220
{
212221
const page = await newPage({ timezoneId: 'Europe/Berlin' });
213-
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 19:12:34 GMT+0100 (Central European Standard Time)');
222+
if (WEBKIT)
223+
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 19:12:34 GMT+0100 (Europe/Berlin)');
224+
else
225+
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 19:12:34 GMT+0100 (Central European Standard Time)');
214226
}
215227
});
216228

0 commit comments

Comments
 (0)