Skip to content

Commit

Permalink
chore(connect-popup): allow on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
martykan authored and mroz22 committed Aug 6, 2024
1 parent 172ffac commit 9a6ba2e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
52 changes: 30 additions & 22 deletions packages/connect-popup/e2e/tests/browser-support.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test('unsupported browser', async ({ browser }) => {
await context.close();
});

test('outdated-browser', async ({ browser }) => {
test('outdated browser', async ({ browser }) => {
const context = await browser.newContext({
userAgent:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:100.0) Gecko/20100101 Firefox/50.0',
Expand Down Expand Up @@ -76,27 +76,35 @@ test('outdated-browser', async ({ browser }) => {
});

// test mobile browsers
test.describe(() => {
const fixtures = [
{ desc: 'iPhone', device: iPhone },
{ desc: 'android', device: android },
];
for (const f of fixtures) {
test(`env: web, device: mobile/${f.desc} => not allowed `, async ({ browser }) => {
const context = await browser.newContext({
...f.device,
});
const page = await context.newPage();
await page.goto(formatUrl(url, `methods/bitcoin/getPublicKey/`));
test(`env: web, device: mobile/iPhone => not allowed `, async ({ browser }) => {
const context = await browser.newContext({
...iPhone,
});
const page = await context.newPage();
await page.goto(formatUrl(url, `methods/bitcoin/getPublicKey/`));

popup = await openPopup(page);
// unfortunately webusb now does not work for connect-popup, so mobile chrome won't run even if it technically could
await popup.waitForSelector('text=Smartphones not supported yet');
await popup.screenshot({ path: `${dir}/mobile-iphone-not-supported.png` });

popup = await openPopup(page);
// unfortunately webusb now does not work for connect-popup, so mobile chrome won't run even if it technically could
await popup.waitForSelector('text=Smartphones not supported yet');
await popup.screenshot({ path: `${dir}/mobile-${f.desc}-not-supported.png` });
await popup.click('text=Close');
await page.close();
await context.close();
});

await popup.click('text=Close');
await page.close();
await context.close();
});
}
test(`env: web, device: mobile/Android => allowed `, async ({ browser }) => {
const context = await browser.newContext({
...android,
});
const page = await context.newPage();
await page.goto(formatUrl(url, `methods/bitcoin/getPublicKey/`));

popup = await openPopup(page);

await popup.waitForSelector('text=Connect Trezor to continue');
await popup.screenshot({ path: `${dir}/mobile-android-supported.png` });

await page.close();
await context.close();
});
6 changes: 3 additions & 3 deletions packages/connect-popup/src/view/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { storage } from '@trezor/connect-common';
import { container, showView } from './common';

export const initBrowserView = (systemInfo: SystemInfo): Promise<boolean> => {
if (systemInfo?.os.mobile) {
// popup is not supported on mobile devices
// webusb is now available only on trezor.io domains and bridge can't be installed on mobile
if (systemInfo?.os.mobile && !systemInfo?.browser.supported) {
// popup can now support smartphones that have WebUSB support (e.g. Android with Chrome)
// browsers that are not supported will get rejected
showView('smartphones-not-supported');

return Promise.resolve(false);
Expand Down

0 comments on commit 9a6ba2e

Please sign in to comment.