[webkit-dev] Controlling the User-agent string from a WebKit client

David Harrison harrison at apple.com
Mon Nov 19 08:27:38 PST 2007


Here is something from WebView.h

     @method setCustomUserAgent:
     @abstract Set the user agent.
     @discussion Setting this means that the webView should use this  
user-agent string
     instead of constructing a user-agent string for each URL. Setting  
it to nil
     causes the webView to construct the user-agent string for each URL
     for best results rendering web pages.
     @param userAgentString The user agent description
- (void)setCustomUserAgent:(NSString *)userAgentString;

There are a couple other user agent related APIs, too.


On Nov 19, 2007, at 8:14 AM, Todd Ditchendorf wrote:

> If you're building a cocoa application that links to WebKit and  
> includes a WebView in its UI, what's the best way to configure the  
> user-agent string the WebView uses in both outgoing HTTP request  
> headers and also the JS window.navigator.userAgent property?
> e.g., say you were building a web browser and wanted to spoof safari.
> for altering the "user-agent" request header, the only thing i an  
> come up with is to implement the ResourceLoadDelegate method:
> webView:resource:willSendRequest:redirectResponse:fromDataSource:
> and return from it a new request that contains the desired header.  
> this seems to work, but not sure if it's best?
> as for the JS navigator.userAgent property, it seems to be read-only  
> when i try to explicitly change it from:
> webView:didClearWindowObject:forFrame:
> I haven't found a way to change the JS property yet.
> seems like this might be a common need... is an ER for a method for  
> controlling the user-agent string in the WebKit client api in order?
> thanks,
> todd
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo/webkit-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.webkit.org/pipermail/webkit-dev/attachments/20071119/51a41dac/attachment.html

More information about the webkit-dev mailing list