Here's another short and interesting story about problems we have to deal at Browserling. This story is about getting rid of annoying pop-up dialogs in browsers, such as alerts, error dialogs and add-on update dialogs.

So this one time when we were building Testling we started getting a nasty modal dialog in Chrome that paralyzed the browser and the tests wouldn't run. It said:

Your profile can not be used because it is from a newer version of
Google Chrome.

Some features may be unavailable. Please specify a different profile
directory or use a newer version of Chrome.

Here's how that dialog looked in Chrome:

Your profile can not be used because it is from a newer version of Google Chrome.

We were isolating each browser already through Sandboxie so changing the profile directory wasn't really a solution. I decided to write a quick hack that would simply click the OK button on this dialog.

I used Spy++ to find the window class of the dialog:

Spy++ in action.

And then I wrote a Win32 C++ program that detects if this dialog is present, and if it is, it clicks the OK button to get rid of it:

#include <windows.h>
#include <cstdio>

int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    while (1) {
        HWND dialog = FindWindow("#32770", "Google Chrome");
        if (dialog) {
            printf("Found dialog: %x\n", dialog);
            HWND dialogItem = NULL;
            while (1) {
                dialogItem = FindWindowEx(dialog, dialogItem, NULL, NULL);
                if (dialogItem == NULL) {
                    break;
                }
                char windowText[255];
                GetWindowText(dialogItem, windowText, 255);
                if (strcmp(windowText, "OK") == 0) {
                    SetActiveWindow(dialog);
                    SendMessage(dialogItem, BM_CLICK, NULL, NULL);
                    break;
                }
            }
        }
        Sleep(1000);
    }
}

I pushed this program to github and called it chrome-dialog-killer.

Here's another similar problem that we faced in Browserling. We run many different FireFox versions on the same box and often FireFox wouldn't start cleanly. Instead it would complain about incompatible add-ons:

The following add-ons are not compatible with this version of
Firefox and have been disabled.
...
Firefox can check if there are compatible versions of these
add-ons available.

The incompatible add-ons dialog looked like this:

Incompatible add-ons FireFox dialog.

I tried disabling this add-on in all the FireFox version (Firefox 3 to Firefox 25) but we'd still get this alert sometimes. The browser wouldn't start and users had to click the "Don't Check" button. So, again, I used Spy++, found the dialog's windows class and wrote an even simpler program that simply sends the WM_CLOSE message to the dialog that closes it:

#include <windows.h>
#include <cstdio>

int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    while (1) {
        HWND dialog = FindWindow("MozillaDialogClass", "FireFox Update");
        if (dialog) {
            printf("Found dialog: %x\n", dialog);
            HWND dialogItem = NULL;
            SendMessage(dialog, WM_CLOSE, 0, 0);
        }
        Sleep(2000);
    }
}

I also pushed this program to github and called it firefox-update-dialog-killer.

Similarly we can get rid of alert() dialogs in Testling as they're unnecessary and halt the JavaScript execution.

Modern GUIs and interfaces should never use modal dialogs as they provide really unpleasant user experience and make automating things difficult. Until next time.