Giter Site home page Giter Site logo

False positives about svg4everybody HOT 7 CLOSED

jonathantneal avatar jonathantneal commented on August 18, 2024
False positives

from svg4everybody.

Comments (7)

jonathantneal avatar jonathantneal commented on August 18, 2024

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36

That User Agent string does not pass the regex test.

Could you setup a test page?

from svg4everybody.

liamness avatar liamness commented on August 18, 2024

Thanks for the quick reply. I'm using your polyfill in my blog and I've tried to set it up with 2.0.0 so I can support MS Edge.

from svg4everybody.

jdalton avatar jdalton commented on August 18, 2024

I've been kicking around a feature test that works for most
(except Safari so that could reduce the UA sniffing):

var polycheck = false;

;(function() {
  function check(e) {
    polycheck = use.getBoundingClientRect().width === 1;
    if (e || !--retries) {
      body.removeChild(svg);
      clearInterval(id);
    }
  }

  try {
    var url = URL.createObjectURL(
      new Blob([
        '<svg xmlns="http://www.w3.org/2000/svg">' +
        '<rect width="1" height="1" id="x"/>' +
        '</svg>'
      ], { 'type': 'image/svg+xml' })
    );

    var body = document.body;
    body.insertAdjacentHTML('beforeend',
      '<svg style="position:absolute;visibility:hidden">' +
      '<use xlink:href="' + url + '#x"/>' +
      '</svg>'
    );

    var retries = 3,
        svg = body.lastChild,
        use = svg.firstChild,
        id = setInterval(check, 50);

    use.addEventListener('load', check);
  } catch(e) {}
}());

from svg4everybody.

liamness avatar liamness commented on August 18, 2024

I changed my build process to include the unminified version, so I could step through the code... and I can't replicate the bug anymore. I don't understand why but it all seems to work fine now, so I'm closing the issue. Thanks for taking a look.

from svg4everybody.

patrickkettner avatar patrickkettner commented on August 18, 2024

@jdalton wanna open that up on modernizr?

from svg4everybody.

gregwhitworth avatar gregwhitworth commented on August 18, 2024

Looking at this code, I think it can be simplified and possibly address some coverage for interop differences/bugs by changing 1 to 0, since the external resource was accessed, thus the feature does work.

polycheck = use.getBoundingClientRect().width != 0;

Any issues with this approach? This now results in Chrome/Edge/Firefox all returning true, IE11 returning false.

from svg4everybody.

jpdevries avatar jpdevries commented on August 18, 2024

@gregwhitworth Hm, I'm getting false with this in Safari 10.0.1

var polycheck = false;

;(function() {
  function check(e) {
    polycheck = use.getBoundingClientRect().width != 0;
    if (e || !--retries) {
      body.removeChild(svg);
      clearInterval(id);
    }
  }

  try {
    var url = URL.createObjectURL(
      new Blob([
        '<svg xmlns="http://www.w3.org/2000/svg">' +
        '<rect width="1" height="1" id="x"/>' +
        '</svg>'
      ], { 'type': 'image/svg+xml' })
    );

    var body = document.body;
    body.insertAdjacentHTML('beforeend',
      '<svg style="position:absolute;visibility:hidden">' +
      '<use xlink:href="' + url + '#x"/>' +
      '</svg>'
    );

    var retries = 3,
        svg = body.lastChild,
        use = svg.firstChild,
        id = setInterval(check, 50);

    use.addEventListener('load', check);
  } catch(e) {}
}());

from svg4everybody.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.