Developing for Safari on Windows 10 / Linux
Tags: testing, safari, webdev, programming
Published: 2021-01-23 15:05:36

<strong>Are you a Web Developer?</strong>
If yes, my bet is that you are probably developing on one of the following browsers: Chrome, Opera, Firefox, Edge, Brave or Safari.

In the end, it boils down to the big three browsers: 
- Chromium based
- Safari
- Firefox

Even though I am <strong>currently</strong> a kind of happy Firefox user, the market share of the browser is converging to zero and ultimately it seems like the browser is dying. They even decided to close the ticket regarding the <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1407202">install option for PWA</a> without plans of continuing.

Beside the nagging, a lot of consumers are effectively using Safari on desktop and especially mobile. <em>(cf. <a href="https://gs.statcounter.com/browser-market-share">statcounter</a> or <a href="https://caniuse.com/flexbox">Can I Use</a>)</em>

So, how do we as Web Developer test on Safari, without feeling uncomfortable? In the past I had jobs where I could make use of a local MacBook or paid services like browserstack. It felt burdensome for me to work on a macOS, mostly because I was not used to it and my peripherals were somewhere else. And even if you would have a macOS at your workplace, given the fact that most of us are working from home right now, this is no longer an option.

<h1>🤝 The solution </h1>

Have you heard of <a href="https://github.com/microsoft/playwright">Playwright?</a> 
<u>If your answer is no, </u> then let me tell you that Playwright is a Node.js library to automate Chromium, Firefox and WebKit with a single API. In fact, the API is very simular to Puppeteer, because two of the Developers moved from Puppeteer to Playwright. <em>(cf. <a href="https://github.com/puppeteer/puppeteer/graphs/contributors">Puppeteer Contributions</a> vs. <a href="https://github.com/microsoft/playwright/graphs/contributors">Playwright Contributions</a>)</em>
<u>If your answer is yes, </u> and if you are not using Safari yet for testing purposes as Windows or Linux user, then congratulations, you are just like me 🤡.

The solution was right in front of us and I am happy to share a little snippet to kickstart the browser, so that we all can create better applications 🚀

```js
// unflagged top-level await from Node 14.8.0+
import { webkit } from "playwright";
const browser = await webkit.launch({ headless: false });
const context = await browser.newContext();
const page = await context.newPage();
await page.goto("https://www.whatismybrowser.com/");
```

For anything else, please refer to the official playwright documentation.

<h2>🖼 Further improvements on Windows </h2>
If you do not want to execute the .js file everytime you want to make use of Safari, follow these steps: 
- Execute the script
- Open the Task Manager, go to tab 'Details', right-click on Playwright.exe and select 'Open file location'.
- Right-click on Playwright.exe in the folder and click on 'Create shortcut'
- (optional) download Safari Icon from <a href="https://en.wikipedia.org/wiki/Safari_(web_browser)#/media/File:Safari_14_icon.png">wikipedia</a>, convert it to an icon, save it in the folder, right-click on the shortcut, properties 'Change Icon' and select the .ico.
- Right-click the shortcut and select 'Pin to Start'

![Start Safari](https://dev-to-uploads.s3.amazonaws.com/i/xyn0dn4traas4mnaifk5.png)