iOS Share Extension: get URL of page when sharing via context menu in Safari : <p><strong>What I want</strong></p>

<p>I'm trying to achieve the following user flow:</p>

<ol>
<li>User is browsing a webpage in iOS Safari.</li>
<li>User selects some content (text and images) and waits for context menu to appear.</li>
<li>User selects the "Share..." item.</li>
<li>User selects my App Extension in the sharing menu that comes up from the bottom.</li>
<li>Selected content and the webpage URL is shared to a remote server via an HTT call.</li>
</ol>

<p><strong>What I tried</strong></p>

<p>I made a Share extension via Xcode. Here's the <code>NSExtension</code> section of my <code>info.plist</code>:</p>

<pre><code>&lt;key&gt;NSExtension&lt;/key&gt;
&lt;dict&gt;
    &lt;key&gt;NSExtensionAttributes&lt;/key&gt;
    &lt;dict&gt;
        &lt;key&gt;NSExtensionActivationRule&lt;/key&gt;
        &lt;dict&gt;
            &lt;key&gt;NSExtensionActivationSupportsWebPageWithMaxCount&lt;/key&gt;
            &lt;integer&gt;1&lt;/integer&gt;
            &lt;key&gt;NSExtensionActivationSupportsText&lt;/key&gt;
            &lt;true/&gt;
            &lt;key&gt;NSExtensionActivationSupportsWebURLWithMaxCount&lt;/key&gt;
            &lt;integer&gt;1&lt;/integer&gt;
        &lt;/dict&gt;
        &lt;key&gt;NSExtensionJavaScriptPreprocessingFile&lt;/key&gt;
        &lt;string&gt;test&lt;/string&gt;
    &lt;/dict&gt;
    &lt;key&gt;NSExtensionMainStoryboard&lt;/key&gt;
    &lt;string&gt;MainInterface&lt;/string&gt;
    &lt;key&gt;NSExtensionPointIdentifier&lt;/key&gt;
    &lt;string&gt;com.apple.share-services&lt;/string&gt;
&lt;/dict&gt;
</code></pre>

<p>Here's the <code>test.js</code> file:</p>

<pre><code>var GetURL = function() {};
GetURL.prototype = {
run: function(arguments) {
    arguments.completionFunction({"URL": document.URL});
}
};
var ExtensionPreprocessingJS = new GetURL;
</code></pre>

<p>I expected the following result: in <code>viewDidLoad</code> method <code>extensionContext?.inputItems</code> would provide me with several input items, through which I would be able to get the selected content and the web URL.</p>

<p><strong>What goes wrong</strong></p>

<p>In <code>viewDidLoad</code> method <code>extensionContext?.inputItems</code> provides me with only one item -- the plain text representation of the selected content (even when I selected images and text at the same time). I can live with plain text, but I need the webpage URL. </p>

<p><strong>My question</strong></p>

<p>How can I get URL of the opened webpage when using a Share extension to share selected content via context menu in iOS Safari?</p>
