WebBrowserComponent URL[SOLVED]

Hi Julian,
I have been trying couple of things with juce::webbrowsercomponent. If I try to open a url containing braces on mac, the webbrowsercomponent doesn’t display the page


But Safari and other browsers display the page.

Well, it’s just passing the string straight through to the browser component. And I don’t think braces are actually legal in a URL, are they?

Safari is probably being clever and trying to fix any illegal characters before it sends the string, but if I did that, it’d break existing code by double-encoding already encoded URLs.

The URL class has encoding methods that you can use to tidy it up before you send it.

Braces are actually unsafe URL characters but not illegal.


I haven’t debugged the webBrowserComponent code yet, But will give it a try soon.

I encrypted the braces and it worked.
Just in case someone faces similar problem


Am guess here, may be safari is checking for unsafe characters and encrypting those before trying to load the page.

Hi Julian,
I have solved the issue, you would have to add a extra line of code to webBrowserComponent’s “sendWebViewToURL” method.

This is the change i have done

 void sendWebViewToURL (const char* utf8URL,
                           const char** headerNames, 
                           const char** headerValues, 
                           int numHeaders,
                           const char* postData, 
                           int postDataSize)
		NSString* formattedURL = [NSString stringWithString:[[NSString stringWithUTF8String: utf8URL] stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding]];  // added this line, it encodes all non- URL characters
		NSMutableURLRequest* r = [NSMutableURLRequest 
								  requestWithURL: [NSURL URLWithString: formattedURL]
								  cachePolicy: NSURLRequestUseProtocolCachePolicy
								  timeoutInterval: 30.0];// pass the formated URL.

        if (postDataSize > 0)
            [ r setHTTPMethod: @"POST"];
            [ r setHTTPBody: [NSData dataWithBytes: postData length: postDataSize]];

        int i;
        for (i = 0; i < numHeaders; ++i)
            [ r setValue: [NSString stringWithUTF8String: headerValues[i]]
                forHTTPHeaderField: [NSString stringWithUTF8String: headerNames[i]]];

        [[webView mainFrame] stopLoading ];
        [[webView mainFrame] loadRequest: r];

“stringByAddingPercentEscapesUsingEncoding” encodes all the non-URL/non secure URLcharaters.

I have tested it and it works well. It is safe to put this code in.

no, no, no… Like I said above, the goToURL method expects the string to already be encoded. Adding an encoding step there would double-encode it, and break any existing code that uses it!

The idea is that you can use the URL class to build the string that you pass into this function, and that’ll take care of all the messy stuff for you.

I tried encrypting it twice, using “stringByAddingPercentEscapesUsingEncoding” doesn’t encode the characters already encoded.

But you are right, the URL’s passed to the webbrowser should be valid. I will make changes to my code :). Thanks for the help.