Troubleshooting Mobile Versions of iOS Websites on Linux

troubleshooting-mobile-versions-1As a Linux user, you may struggle to debug your iOS websites. However, as a web developer, debugging is crucial for maintaining optimal performance of your webpages. Debugging remotely on a Mac is easy — all you need is a recent version of Safari. Unfortunately, not a single version of Safari is available for Linux. Luckily, there are a few (albeit a limited number) of ways to get around the problem.

JSConsole

JSConsole is a web app for Linux and Windows. Although it is sufficient to handle problems when you have no access to a Mac, it is no substitute for a complete web inspector.

JSConsole inserts a script tag into your web page to override console behavior. It then streams logs and errors to a session on your Linux browser. To receive a unique session ID and script tag, run “:listen in the prompt” on the JSConsole website.troubleshooting-mobile-versions-2Debugging Over USB

If you are at risk for connection interruptions, a better option than debugging over WiFi is to use USB. Before you can start, you will need to jailbreak your iOS device and install OpenSSH.

Creating your debugserver

Debugserver is more or less the iOS app equivalent of gdbserver and is necessary for debugging over USB.

To start, head to your OS X installation, where you can prepare the debugserver. Find the developer disk image that corresponds to your device. Options appear like this:

$ls /Applications/Xcode.app/Contents/Developer/Platforms/\
iPhoneOS.platform/DeviceSupport/
6.0    6.1    7.0    7.1    8.0    8.1
8.2    8.3    8.4    9.0    9.1 (13B137)

Mount the correct version in /Volumes/DeveloperDiskImage.

Next, copy the debugserver:

$ mkdir debugserver
$ cd debugserver
$ cp /Volumes/DeveloperDiskImage/usr/bin/debugserver

Once you have done this, you can unmount the developer disk image. Now, create an entitlements.plist file:

$ cat << EOF > entitlements.plist
<?xml version=“1.0” encoding=“UTF-8”?><!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/
PropertyList-1.0.dtd”>
<plist version=“1.0”>
<dict>
<key>com.apple.springboard.debugapplications</key>
<true/>
<key>run-unsigned-code</key>
<true/>
<key>get-task-allow</key>
<true/>
<key>task_for_pid-allow</key>
<true/>
</dict>
</plist>
EOF

This will enable you to redesign the debugserver as so:

$ codesign -s - —entitlements entitlements.plist -f
debugserver

Once all this is complete, copy the new debugserver to Linux, such as by using SSH.

Setting up the Linux host

With your debugserver configured, the second stage is to set up your Linux host. Note that debugserver is compatible with 11db rather than gdb like gdbserver.

To start, you need to launch ubsbmuxd service. For systemd, use:

$ sudo systemctl start usbmuxd.service

If your distribution doesn’t use systemd, launch it using init or upstart script. Then, connect your iOS device to the Linux host. Create an SSH tunnel using:

$ iproxy 2222 22

If you haven’t already, change the default alpine root password:

$ ssh root@localhost -p 2222

Finally, copy the debugserver to your iOS device using your Linux machine:

$ scp -P 2222 debugserver root@localhost:/var/private/root/

Debug an iOS website

You are now ready to debug on the application of your choice. Debugserver allows you to connect it with 11db by binding to a port. This means you need to create an SSH tunnel. Keeping your previous tunnel active, create an SSH tunnel from your Linux machine using:

$ ssh -L 12345:localhost:23456 root@localhost -p 2222

This will redirect any connection on port 12345 of your Linux to port 23456 of your iOS device through the tunnel.

Still keeping both tunnels open, run 11db and attach to the debugserver using:

$ 11db
(11db) process connect connect://127.0.0.1:12345
Process 1844 stopped
* thread #1: tid = 0xdcc0, 0x380f9130, stop reason = signal SIGSTOP
frame #0: 0x380f9130
->  0x380f9130: pop    {r4, r5, r6, r8}
0x380f9134: bx     lr
0x380f9138: mov     r12, sp
0x380f913c: push   {r4, r5, r6, r8}
(11db) c
Process 1844 resuming

Charles

Another option for remote debugging is Charles, a web proxy that runs on all three of the main operating systems. By allowing your web browser to access the Internet through Charles, you will see all the data sent to and received by your iOS website. You can access all HTTP and SSL / HTTPS traffic, including requests, responses, and HTTP headers. This enables you to quickly locate issues and debug.

Unlike the first two options, you need a license to benefit from Charles. User licenses are available according to the number of users you want. Alternatively, you can purchase a single site or multi-site license. Whatever you choose, you will have access to features including SSL proxying, bandwidth throttling, AJAX debugging, and AMF. You will also be able to handle requests for tests from different inputs and repeat requests to test back-end changes.

If you like my articles,