ball - Dave's Blog

Search
My timeline on Mastodon

Changing the User Agent string in UWP WebView

2018 Oct 23, 9:32

There's no perfect way to change the user agent string for the UWP WebView (x-ms-webview in HTML, Windows.UI.Xaml.Controls.WebView in XAML, and Windows.Web.UI.Interop.WebViewControl in Win32) but there are two imperfect methods folks end up using.

The first is to call UrlMkSetSessionOption. This is an old public API that allows you to configure various arcane options including one that is the default user agent string for requests running through urlmon. This API is allowed by the Microsoft Store for UWP apps. The change it applies is process wide which has two potential drawbacks. If you want to be able to have different UA strings set for different requests from a WebView that's not really possible with this solution. The other drawback is if you're using out of process WebView, you need to ensure you're calling into UrlMkSetSessionOption in the WebView's process. You'll need to write third party WinRT that calls UrlMkSetSessionOption, create the out of proc WebView, navigate it to some trusted local page, use AddWebAllowedObject or provide that URI WinRT access, and call into your third party WinRT. You'll need to do that for any new WebView process you create.

The second less generally applicable solution is to use NavigateWithHttpRequestMessage and set the User-Agent HTTP header. In this case you get to control the scope of the user agent string changes but has the limitations that not all sub resource downloads will use this user agent string and for navigations you don't initiate you have to manually intercept and re-request being careful to transfer over all POST body state and HTTP headers correctly. That last part is not actually possible for iframes.

PermalinkCommentsuser-agent uwp webview

Win10 UWP WebView AddWebAllowedObject details

2017 Sep 4, 3:09

The x-ms-webview HTML element has the void addWebAllowedObject(string name, any value) method and the webview XAML element has the void AddWebAllowedObject(String name, Object value) method. The object parameter is projected into the webview’s top-level HTML document’s script engine as a new property on the global object with property name set to the name parameter. It is not injected into the current document but rather it is projected during initialization of the next top-level HTML document to which the webview navigates.

Lifetime

If AddWebAllowedObject is called during a NavigationStarting event handler the object will be injected into the document resulting from the navigation corresponding to that event.

If AddWebAllowedObject is called outside of the NavigationStarting event handler it will apply to the navigation corresponding to the next explicit navigate method called on the webview or the navigation corresponding to the next NavigationStarting event handler that fires, whichever comes first.

To avoid this potential race, you should use AddWebAllowedObject in one of two ways: 1. During a NavigationStarting event handler, 2. Before calling a Navigate method and without returning to the main loop.

If called both before calling a navigate method and in the NavigationStarting event handler then the result is the aggregate of all those calls.

If called multiple times for the same document with the same name the last call wins and the previous are silently ignored.

If AddWebAllowedObject is called for a navigation and that navigation fails or redirects to a different URI, the AddWebAllowedObject call is silently ignored.

After successfully adding an object to a document, the object will no longer be projected once a navigation to a new document occurs.

WinRT access

If AddWebAllowedObject is called for a document with All WinRT access then projection will succeed and the object will be added.

If AddWebAllowedObject is called for a document which has a URI which has no declared WinRT access via ApplicationContentUriRules then Allow for web only WinRT access is given to that document.

If the document has Allow for web only WinRT access then projection will succeed only if the object’s runtimeclass has the Windows.Foundation.Metadata.AllowForWeb metadata attribute.

Object requirements

The object must implement the IAgileObject interface. Because the XAML and HTML webview elements run on ASTA view threads and the webview’s content’s JavaScript thread runs on another ASTA thread a developer should not create their non-agile runtimeclass on the view thread. To encourage end developers to do this correctly we require the object implements IAgileObject.

Property name

The name parameter must be a valid JavaScript property name, otherwise the call will fail silently. If the name is already a property name on the global object, that property is overwritten if the property is configurable. Non-configurable properties on the global object are not overwritten and the AddWebAllowedObject call fails silently. On success, the projected property is writable, configurable, and enumerable.

Errors

Some errors as described above fail silently. Other issues, such as lack of IAgileObject or lack of the AllowForWeb attribute result in an error in the JavaScript developer console.

PermalinkComments

The Dancebulance - Gov Ball 2012 Lineup (by...

2012 Apr 18, 6:10


The Dancebulance - Gov Ball 2012 Lineup (by nathanjbarnatt)

Another Nathan Barnatt video with awesome music and dance moves.  Also enjoying the music video for third song in this video “Barbara Streisand” by Duck Sauce: http://www.youtube.com/watch?v=uu_zwdmz0hE

PermalinkCommentshumor music dance nathan-barnatt video

Musée McCord Museum’s photostream on Flickr.

2012 Jan 15, 10:37


Foot race, Dawson City, YT, about 1900Cricket match, McGill campus, Montreal, QC, about 1890Football game on campus, McGill University, Montreal, QC, about 1900S. S. "Nascopie" at sealing grounds, 1927

Musée McCord Museum’s photostream on Flickr.

PermalinkCommentsphoto old-timey black-and-white history

Douglas Crockford Facts

2010 Mar 18, 7:23Right behind Bruce Schneier, Douglas Crockford now gets his own Facts page including awesome facts like "Crockford is the sole user of the super-strict equality operator (====), which either returns true or kicks you in the balls."PermalinkCommentsdouglas-crockford humor javascript nerd technical

YouTube - HAMSTERDAM HILARIOUS VIDEO! WATCH!

2009 Dec 27, 7:43"Have a look what happens when a huge hamster hits the Amsterdam Canals in a giant inflatable ball!" Almost a good idea. Maybe next time add some paddles to the outside of the ball.PermalinkCommentshumor video youtube hamster amsterdam water

Lessons Learned From Paintball

2009 Dec 16, 2:47

Dressed for Paintball.I played paintball for the first time at Eric's bachelor party a couple months ago. With the worst of my bruises fading I'm examining what I've learned:

PermalinkCommentspaintball lessons

Dressed for Paintball

2009 Dec 16, 2:35

sequelguy posted a photo:

Dressed for Paintball

PermalinkCommentsme washington paintball

Faceball: your face, our balls

2009 Nov 20, 2:42A sport for the office from Yahoo!. Played between two people, who can get more consecutive hits to the other in the face with a ball.
PermalinkCommentshumor video game ball flickr sport yahoo office

Fun With the Minneapolis Mayoral Race - Boing Boing

2009 Nov 3, 5:02The sample ballot for Minneapolis elections is awesome (see second to last entry)PermalinkCommentshumor politics image

How to Google Maps on Vimeo

2009 Aug 31, 4:53From Ira as part of The Balloon Project "... took the lo-fi diy map making essentials (portable helium tank, party balloons, and a disposable video camera) to Paris, France, where they launched a video camera into the sky not knowing where it would go, and created some very unique aerial cartography of the Place de la Concorde.' I'd love to see this run through photo stitching software like Photosynth and then layered on Google Maps.PermalinkCommentsmap balloon art ira-mowen france paris

Baseball Game Friday, House Things Previously

2009 Jul 11, 2:47

Mariners vs Rangers, Safeco Field, SeattleOn Friday Sarah and I went to the Mariners vs Rangers game at Safeco Field with Eric and Jane. The Mariners lost but then before the game the announcement made outside the stadium guaranteed the best service and a good time, not a winning game -- and they were right about the good time.

The night before, we saw The Hangover which was very funny and included Zach Galifianakis who was great. Incidentally, take a look at some of Zach's Between Two Ferns.

Last weekend Sarah and I mounted the TV to the wall which was exciting and we saw a mouse in the house!

PermalinkCommentstv baseball personal mouse house

Safeco Field Concessions Stand

2009 Jul 11, 1:57

sequelguy posted a photo:

Safeco Field Concessions Stand

PermalinkCommentsseattle food washington baseball safecofield

Mariners vs Rangers, Safeco Field, Seattle

2009 Jul 11, 1:57

sequelguy posted a photo:

Mariners vs Rangers, Safeco Field, Seattle

PermalinkCommentsseattle washington baseball safecofield

Sarah and Me at Safeco Field

2009 Jul 11, 1:57

sequelguy posted a photo:

Sarah and Me at Safeco Field

PermalinkCommentsme sarah baseball safecofield

Gravatar - Globally Recognized Avatars

2009 Apr 20, 3:37Web service that hosts avatar images for things like blog comments. The image is ID'ed by a hash of the user's email address. Auto generated or if the user signs up, the image can be whatever they upload. Lots of plugins for different blogging platforms.PermalinkCommentsblog web photo avatar image authentication identity icon hash

meteotek08's photosets on Flickr

2009 Mar 18, 9:35Team of teenagers attach camera to weather balloon and send it to space!PermalinkCommentsphotography photos via:boingboing.comments science space flickr

Investigation of a Few Application Protocols (Updated)

2008 Oct 25, 6:51

Windows allows for application protocols in which, through the registry, you specify a URL scheme and a command line to have that URL passed to your application. Its an easy way to hook a webbrowser up to your application. Anyone can read the doc above and then walk through the registry and pick out the application protocols but just from that info you can't tell what the application expects these URLs to look like. I did a bit of research on some of the application protocols I've seen which is listed below. Good places to look for information on URI schemes: Wikipedia URI scheme, and ESW Wiki UriSchemes.

Some Application Protocols and associated documentation.
Scheme Name Notes
search-ms Windows Search Protocol The search-ms application protocol is a convention for querying the Windows Search index. The protocol enables applications, like Microsoft Windows Explorer, to query the index with parameter-value arguments, including property arguments, previously saved searches, Advanced Query Syntax, Natural Query Syntax, and language code identifiers (LCIDs) for both the Indexer and the query itself. See the MSDN docs for search-ms for more info.
Example: search-ms:query=food
Explorer.AssocProtocol.search-ms
OneNote OneNote Protocol From the OneNote help: /hyperlink "pagetarget" - Starts OneNote and opens the page specified by the pagetarget parameter. To obtain the hyperlink for any page in a OneNote notebook, right-click its page tab and then click Copy Hyperlink to this Page.
Example: onenote:///\\GUMMO\Users\davris\Documents\OneNote%20Notebooks\OneNote%202007%20Guide\Getting%20Started%20with%20OneNote.one#section-id={692F45F5-A42A-415B-8C0D-39A10E88A30F}&end
callto Callto Protocol ESW Wiki Info on callto
Skype callto info
NetMeeting callto info
Example: callto://+12125551234
itpc iTunes Podcast Tells iTunes to subscribe to an indicated podcast. iTunes documentation.
C:\Program Files\iTunes\iTunes.exe /url "%1"
Example: itpc:http://www.npr.org/rss/podcast.php?id=35
iTunes.AssocProtocol.itpc
pcast
iTunes.AssocProtocol.pcast
Magnet Magnet URI Magnet URL scheme described by Wikipedia. Magnet URLs identify a resource by a hash of that resource so that when used in P2P scenarios no central authority is necessary to create URIs for a resource.
mailto Mail Protocol RFC 2368 - Mailto URL Scheme.
Mailto Syntax
Opens mail programs with new message with some parameters filled in, such as the to, from, subject, and body.
Example: mailto:?to=david.risney@gmail.com&subject=test&body=Test of mailto syntax
WindowsMail.Url.Mailto
MMS mms Protocol MSDN describes associated protocols.
Wikipedia describes MMS.
"C:\Program Files\Windows Media Player\wmplayer.exe" "%L"
Also appears to be related to MMS cellphone messages: MMS IETF Draft.
WMP11.AssocProtocol.MMS
secondlife [SecondLife] Opens SecondLife to the specified location, user, etc.
SecondLife Wiki description of the URL scheme.
"C:\Program Files\SecondLife\SecondLife.exe" -set SystemLanguage en-us -url "%1"
Example: secondlife://ahern/128/128/128
skype Skype Protocol Open Skype to call a user or phone number.
Skype's documentation
Wikipedia summary of skype URL scheme
"C:\Program Files\Skype\Phone\Skype.exe" "/uri:%l"
Example: skype:+14035551111?call
skype-plugin Skype Plugin Protocol Handler Something to do with adding plugins to skype? Maybe.
"C:\Program Files\Skype\Plugin Manager\skypePM.exe" "/uri:%1"
svn SVN Protocol Opens TortoiseSVN to browse the repository URL specified in the URL.
C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe /command:repobrowser /path:"%1"
svn+ssh
tsvn
webcal Webcal Protocol Wikipedia describes webcal URL scheme.
Webcal URL scheme description.
A URL that starts with webcal:// points to an Internet location that contains a calendar in iCalendar format.
"C:\Program Files\Windows Calendar\wincal.exe" /webcal "%1"
Example: webcal://www.lightstalkers.org/LS.ics
WindowsCalendar.UrlWebcal.1
zune Zune Protocol Provides access to some Zune operations such as podcast subscription (via Zune Insider).
"c:\Program Files\Zune\Zune.exe" -link:"%1"
Example: zune://subscribe/?name=http://feeds.feedburner.com/wallstrip.
feed Outlook Add RSS Feed Identify a resource that is a feed such as Atom or RSS. Implemented by Outlook to add the indicated feed to Outlook.
Feed URI scheme pre-draft document
"C:\PROGRA~2\MICROS~1\Office12\OUTLOOK.EXE" /share "%1"
im IM Protocol RFC 3860 IM URI scheme description
Like mailto but for instant messaging clients.
Registered by Office Communicator but I was unable to get it to work as described in RFC 3860.
"C:\Program Files (x86)\Microsoft Office Communicator\Communicator.exe" "%1"
tel Tel Protocol RFC 5341 - tel URI scheme IANA assignment
RFC 3966 - tel URI scheme description
Call phone numbers via the tel URI scheme. Implemented by Office Communicator.
"C:\Program Files (x86)\Microsoft Office Communicator\Communicator.exe" "%1"
(Updated 2008-10-27: Added feed, im, and tel from Office Communicator)PermalinkCommentstechnical application protocol shell url windows

Weekend Dinners: Old friends, Old library

2008 Oct 7, 12:21

Last Thursday I saw a bunch of college friends that I hadn't seen in a while, despite all of us working at Microsoft, and Saul and Ciera who were visiting. We had dinner at Typhoon! which I haven't been to in quite a while. Daniil and Val brought their cute child. I got to see Charlie and Matt who I'm not sure I've seen since my 25th birthday. There was much nerdiness. I need to remember to organize such a night myself sometime in near future so I don't have to wait another year to see them.

Carnegie's Public Library in Ballard Seattle is now a restaurant.On the weekend Sarah and I went out to dinner at Carnegie's, a former public library in Ballard, Seattle that's now a restaurant. I saw the restaurant's website in Matt's delicious links and thought it looked interesting. The exterior and entryway look like a public library, but just inside its redone as a sort of modern version of french classical with a bar and two dining rooms. No pictures since my replacement camera only arrived today, but there are photos available. They serve french cuisine which was good and not as expensive as I would have expected. An interesting place, although its a bit of a drive and I'm not sure if we'll be going back soon.

PermalinkCommentscarnegies personal restaurant weekend nontechnical

War Ballooning-Kismet Wireless "Eye in the Sky" (Rick Hill)

2008 Sep 22, 1:21Rick Hill, War Ballooning-Kismet Wireless "Eye in the Sky". Presentation notes from Rick Hill's DefCon talk on WarBallooning.PermalinkCommentshack balloon wireless warballoon defcon security
Older Entries Creative Commons License Some rights reserved.