dailymotion / vast-client-js

VAST (up to 6) parsing library for JavaScript
https://iabtechlab.com/wp-content/uploads/2022/09/VAST_4.3.pdf
MIT License
367 stars 215 forks source link

[fix] Safari cors error #417

Closed guest363 closed 2 years ago

guest363 commented 2 years ago

[client][parser] When you use in iframe on Safari vastClient can't get VAST. Request is block by CORS.

Description

Issue

Issue Link [Optional]

Type

ZacharieTFR commented 2 years ago

Hello, Thanks for the contribution, but I think that using a custom urlHandler is more appropriate to your need. VASTClient's get method accepts a custom URLHandler as an optional parameter https://github.com/dailymotion/vast-client-js/blob/master/docs/api/vast-client.md#parameters-1

const customUrlHandler = {
  get(url, options, cb) {    
     // Add your fetch code with your CORS handling here 
  }
}
const vastClient = new VASTClient();
vastClient.get('http://example.dailymotion.com/vast.xml', options)
  .then(res => {
    // Do something with the parsed VAST response
  })
  .catch(err => {
    // Deal with the error
  });

Also I'm not sure to understand the need for %5B{key}%5D macro pattern.

guest363 commented 2 years ago

Macro pattern %5B and %5D is for support [ and ] in url encode. That's actualy a not common case, but i faced this problem. Custom URLHandler is a good desigion, thats will fix my broblem, thanks.

ZacharieTFR commented 2 years ago

Got it 👍 I will close this PR, but feel free to open an issue if you face any other problem !