WebView: frame locked with source www.youtube.com

I get this message when I try to play a YouTube video in my WebView

Blocked frame with source " https://www.youtube.com " from access to frame with source "Applewebdata: // b102c2f1-19a4-4dea-bff2-b131be89929f". The access request frame has the https protocol; the frame accessed has the applewebdata protocol. Protocols must comply.

In my browser, baseUrl is currently set to nil. I know that I have to change it to @"http://", but many links are based on it, etc. If I change it, I get a blank screen because the html is breaking.

So, I tried to intercept the call on youtube when the user clicks on the youtube link to change baseUrl on the fly. But that seems impossible. For other actions, I use this function and it works well:

- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id < WebPolicyDecisionListener >)listener

How can I solve this problem? The videos worked correctly on the previous OSX, and I use the usual iFrame fragment to enable the video.

<iframe class="youtube-player" type="text/html" width="{$width}" height="{$height}"
      src="http://www.youtube.com/embed/{$youtubelink}?html5=1" frameborder="0">

UPDATE I have to encode the url as a workaround:

<iframe class="youtube-player" type="text/html" width="{$width}" height="{$height}" src="data:text/html;base64,aHR0cDovL3d3dy55b3V0dWJlLmNvbS9lbWJlZC97JHlvdXR1YmVsaW5rfT9odG1sNT0x" frameborder="0">

but i get the url as string text in html.

UPDATE 2 Using the Google APIs.

<div id="youtubep" class="youtube-player"></div>

<script>
var tag = document.createElement('script');

tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);


var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('youtubep', {
height: '390',
width: '640',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady
}
});
}

function onPlayerReady(event) {
event.target.playVideo();
}

</script>

However, it does not work:

[Warning] Untrusted origin: applewebdata://f53223b5-2587-4c0e-9937-bf3e9b07ff92 (www-embed-player.js, line 152, x26)
[Error] XMLHttpRequest cannot load https://redirector.googlevideo.com/videoplayback?mt=1449582813&mv=m&ms=au&source=youtube&key=yt6&clen=41094349&requiressl=yes&mm=31&mn=sn-5hnedn76&gcr=nl&initcwndbps=1451250&id=o-ALVwEvIylUeyOATePUVUFg-cbUR-qvn9AnZ9FdKuwcLH&upn=RA7SrQEDQdw&lmt=1432476385386698&ip=95.97.243.202&sparams=clen%2Cdur%2Cgcr%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cnh%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&fexp=9407194%2C9408500%2C9408710%2C9415030%2C9416126%2C9417204%2C9417683%2C9418204%2C9419541%2C9420310%2C9420452%2C9422141%2C9422596%2C9422618%2C9423662%2C9424480&gir=yes&pl=18&dur=1343.599&sver=3&expire=1449604537&nh=IgpwcjA0LmFtczE2Kg4yMTMuNDYuMTgyLjEwNQ&mime=video%2Fmp4&itag=133&signature=4D2797CB2BE5FCFA7CB78FACD14E8423EC2013B7.329BD308AA58011A920BAEFACA0F5869C7B84FC1&ipbits=0&cpn=b5qfNKIpHmOvNtyU&alr=yes&keepalive=yes&ratebypass=yes&c=WEB&cver=html5&cmo=pf=1&range=0-3730&rn=12&playerretry=2&rbuf=0. Origin https://www.youtube.com is not allowed by Access-Control-Allow-Origin.
+4
source share
4 answers

In principle, there is no need to embed code.

float width = 200.0f;
float height = 200.0f;


UIWebView *wv = [UIWebView new];
wv.frame = CGRectMake(60, 60, width, height);
wv.delegate = self;
// URL from safari address bar.
NSURL *url = [NSURL URLWithString:@"http://www.youtube.com/watch?v=fDXWW5vX-64"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[wv loadRequest:request];

[self.view addSubview:wv];

UIWebViewDelegate View. , .

+1
0

100%, , , iframe. , :

    NSString *website = model.contentVideoURL;
    NSInteger height = self.view.frame.size.height - self.topView.frame.size.height - 70;
    NSString *embedCode = [NSString stringWithFormat:@"<iframe width=\"100%%\" height=\"%li\" src=\"%@\" frameborder=\"0\" allowfullscreen></iframe>",(long)height, website];;
    [[self webView] loadHTMLString:embedCode baseURL:nil];

:

<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>

info.Plist

0

iframe :

<iframe class="youtube-player" type="text/html" width="{$width}" height="{$height}" src="data:text/html,<iframe src=&quot;http://www.youtube.com/embed/{$youtubelink}?html5=1&quot; width=100% height=100% frameborder=0>" frameborder="0"></iframe>
0

Source: https://habr.com/ru/post/1617094/


All Articles