[HN Gopher] YouTubePluginReplacement.cpp: YouTube-specific code ... ___________________________________________________________________ YouTubePluginReplacement.cpp: YouTube-specific code in WebKit Author : pcr910303 Score : 169 points Date : 2022-09-18 15:05 UTC (7 hours ago) (HTM) web link (github.com) (TXT) w3m dump (github.com) | evilpie wrote: | Firefox will also rewrite YouTube embeds: | https://searchfox.org/mozilla-central/rev/c6d17806faef8708b6.... | | Firefox also ships a "system" add-on (https://github.com/mozilla- | extensions/webcompat-addon) that has interventions and user-agent | overrides for many websites. See for yourself in Firefox on | about:compat. | cush wrote: | Odd that a quarter of the code is parsing the qsps | NegativeLatency wrote: | The video in one of the test cases is Steve Jobs commencement | address https://www.youtube.com/v/UF8uR6Z6KLc | tcmb wrote: | Probably the Apple-internal version of Rickrolling. | shadowgovt wrote: | I'm not sure if it's still there, but for a long time there was a | chunk of code in the Mozilla code base that hunted for several | browser extensions in Windows every time the browser started up | and did some patch up work in the file system to make sure that | those extensions could be found in the browser because some older | installers would dump them in non-standard places. This was to | avoid the issue that if the user had already installed the | application with the corresponding extension and it was working | in Internet Explorer, it wouldn't automatically work in Firefox | without this patch up process. And in that case, it wasn't the | extension that was broken from the user's point of view... It was | Firefox. | | Some technologies are so fundamental to the web experience that | when they break, the user perceives the browser to be broken, not | that technology. | eastbound wrote: | I bet the AskBar was always in the perfect standard place for | Firefox to find it, despite being run by Oracle (Yes, Oracle | installers for Java included the AskBar. A crime in my | opinion). | danielovichdk wrote: | Most beautiful cpp code I have seen in many years | jyap wrote: | Probably because it's mostly if statements, neat functions and | string translation. | ravenstine wrote: | It's almost as if the reason C++ can suck is actually because | most developers write code that's incomprehensible. | russellbeattie wrote: | I was just about to make this same exact comment! I was half | way down the page and thought, "Wait... What language is this | again?" I had to scroll back up to confirm. | JeffRats wrote: | Clean and readable, more like C than meta filled C++ with | templates. | saagarjha wrote: | Most platform vendors have this in some form or the other. WebKit | has far more here, for example: | https://github.com/WebKit/WebKit/blob/main/Source/WebCore/pa.... | These are cool and all for when you want software to keep | working, but if you're the person writing these, the one thing | you should absolutely make sure to do is reach out to the authors | of the software you're working around to see if they are willing | to fix their code. Most of the time they are! But I invariable | see code go into the OS/browser/whatever and engineers bemoaning | how they have to work super hard on backcompat, and I'm | like..."ok, but when did you send us a bug?" | chrismorgan wrote: | I believe this is about allowing this kind of markup (that exists | on old web pages that haven't been updated for a long time) to | still work: <embed | src="http://www.youtube.com/v/dQw4w9WgXcQ"></embed> | | ... by roughly translating it into <iframe | src="http://www.youtube.com/embed/dQw4w9WgXcQ"></iframe> | | Probably also the <object> equivalent, maybe only that and not | <embed>, I'm not sure. I never had a great deal to do with those | two tags. | | I don't know why it has to be done this way. I'd have thought | that without this extra code it'd roughly fall back to being an | iframe on the original URL, and then YouTube could just check if | it's in a frame and behave as an embed instead of the main UI. | But there's _probably_ a reason why they've all done it this kind | of way. | userbinator wrote: | It's strange that they thought of essentially taking | responsibility for a change that _YouTube_ did to break embeds. | capableweb wrote: | Someone correct me if I'm wrong, but I think <embed> was used | because it embedded a flash player, back when flash existed | on the web. Then browsers decided to get rid of flash, and | something had to replace it. You can't <embed> HTML pages, so | wasn't really up to YouTube if to break it or not. | Dwedit wrote: | Something really really wrong just happened, I just saw an ad | on Youtube. I didn't think that was possible. | pknerd wrote: | Am I the only one who actually visited this Youtube link by | copying and pasting in address bar? | 10000truths wrote: | Anyone who's been on the Internet long enough will have | wisened up to the fabled YouTube link ending in in XcQ. | neodypsis wrote: | > Anyone who's been on the Internet long enough will have | wisened up to the fabled YouTube link ending in in XcQ | | "We've known each other for so long" | chrismorgan wrote: | Funny, it's the dQw that I recognise. | mattnewton wrote: | I didn't need to, there's only one video that makes sense, | and the "...XcG" seemed familiar | eastbound wrote: | So much that the poor people who were also randomly given a | URL finishing with XcQ can't make people read their video, | and Youtube will need a specific exception to ensure | generated codes don't finish with that. | deepstack wrote: | the all the embed tags video broke on my old site with youtube | video embed when this was done, I just changed my code, but I | guess a lot people probably complained. So there you go. | jdmnd wrote: | This is interesting. It looks like there was even some discussion | of making this behaviour part of the standard, since it's | implemented by all of the major browsers. | | https://github.com/whatwg/html/issues/2390 | DaleCurtis wrote: | Chrome has something similar here: | https://source.chromium.org/chromium/chromium/src/+/main:chr... | | We accept contributions from other sites (e.g., Vimeo, | Dailymotion, etc) who wanted to replace their long tail of in the | wild embeds prior to Flash removal. | simonsarris wrote: | Thanks for your work, Dale. | | IMO this was good practice to keep the web running smoothly at | the time. | | It is reminiscent of Windows 95's specific code to see if | SimCity is running, and allocate memory differently if it was. | | > _Jon Ross, who wrote the original version of SimCity for | Windows 3.x, told me that he accidentally left a bug in SimCity | where he read memory that he had just freed. Yep. It worked | fine on Windows 3.x, because the memory never went anywhere. | Here's the amazing part: On beta versions of Windows 95, | SimCity wasn't working in testing. Microsoft tracked down the | bug and added specific code to Windows 95 that looks for | SimCity. If it finds SimCity running, it runs the memory | allocator in a special mode that doesn't free memory right | away. That's the kind of obsession with backward compatibility | that made people willing to upgrade to Windows 95._ | | from: https://www.joelonsoftware.com/2000/05/24/strategy- | letter-ii... | tantalor wrote: | Yeah why fix bugs when you can just enshrine the bug as a | feature. | | Backwards compatibility like this is a mistake. | thought_alarm wrote: | A-list apps have always received special treatment. | | MacOS and Windows are both full of app-specific hacks to | ensure that misbehaving but popular apps continue to work | between system versions. | azinman2 wrote: | Correct. And not even always only A list. | bigyikes wrote: | What you call a "mistake" is actually just having empathy | for the user. User experience is king. | | It's not tech debt, it's a feature. | tshaddox wrote: | Surely it's both? Some technical debt can be okay just | like some personal or corporate debt can be okay. | DrewADesign wrote: | Yeah... I've put well over 10k hours into writing FOSS | and consistently encounter this attitude there, too. I | never imagined we could get this far tolerating such | frequent contempt for both end-users and their advocates, | such as interface designers. If your PR poses even a | theoretical future inconvenience to developers, good luck | getting it merged, regardless of the user benefit. Until | this changes, user-facing open source alternatives will | always be alternatives rather than the standard. | RedShift1 wrote: | Not just devs and end users, but also devs and other | devs. Not in rejecting pulls but changing API's like | renaming functions, removing functions, swapping argument | positions, changing the complete workflow of a library, | etc... without care. The amount of breakage in the OSS | world is just ridiculous. | | I'm probably biased because I deal with a lot of | Javascript where this sort of behaviour is rampant. | baq wrote: | It's easy to optimize for developer convenience when you | aren't getting paid to do the work... arguably it's the | only way non-profit open source software can progress at | all on average. The tails are heavy, though. | ethbr0 wrote: | Boxed software Microsoft: if it breaks, then Microsoft is | wrong. | | FOSS and new Microsoft: if it breaks, have you tried | pulling the latest? Yes? Then it's a bug in your | expectations. | tcmb wrote: | I agree that it's empathy for the user, but I'd say it's | a workaround, and as such it's tech debt. | muspimerol wrote: | A workaround does not necessitate tech debt. "Workaround" | is a conflated term - it basically implies something | works differently than one might expect, which is | subjective. Anyway, what is the alternative? Saying | "that's not my problem"? Users don't care about who is | technically at fault, they care about a well functioning | product. | scarface74 wrote: | The alternative is to let it break and force developers | to update their software. | | Doing that allowed Apple to not have to maintain 32 bit | compatibility which allowed Apple to make the operating | system smaller (all shared libraries have to be | duplicated including in memory) and allowed Apple to | completely remove 32 bit support in the later ARM | processors. | Beltalowda wrote: | "Tech debt" is doing things quickly now with the price | that you have to clean up (i.e. invest more time) later, | hence the word "debt". This is sometimes a good trade- | off, just as financial debt is. Not everything that looks | a bit ugly is "tech debt". | | And yes, it's ugly, but reality is ugly so we have to | deal with it. | scarface74 wrote: | Every piece of code you write automatically becomes code | you have to maintain. It's tech debt. | solardev wrote: | Those who prioritize code correctness over user experience | will soon find themselves in that blessed paradise where | they never have to worry about user experience anymore... | because there are no more users. | sn_master wrote: | It's the difference of an OS targeted exclusively (at the | time) for home users vs one for academia and web servers. | dotnet00 wrote: | Back then you couldn't just bug the game developer to issue | an update patch, and anything significant breaking between | Windows versions affects Windows adoption and not the | adoption of the software the user is actually interested | in. We see the latter even today, with Windows 8 being a | failure for how much it changed and broke user workflows | and Windows 11 getting a decent bit of pushback too. | | In a way this realization is what's finally making Linux | viable for gaming. Instead of expecting developers to bring | compatibility and bug fixes, have the system provide it and | suddenly you can even have an entire gaming console | designed for PC gaming on Linux, thus also giving you | enough momentum for developers to make adjustments so their | game runs better on the compatibility layer. | scarface74 wrote: | Microsoft made most of its money back then in two ways - | corporations and individuals buying Windows upgrades and | bundling Windows with new computers. | | If Windows got a reputation for being incompatible with | apps, people wouldn't upgrade. | | iOS doesn't really have that problem. New phones are always | going to come with new operating systems and if your app | doesn't run on the new OS, users are going to blame the app | developers. | | Also most of the incompatibility with apps and new | operating systems comes from developers using unpublished | APIs. Apple is very strict about not allowing developers to | use unpublished methods [1]. | | [1] I refuse to use the term "private APIs". An API is a | documented method that the platform vendor documents and | promises to support | yusyusyus wrote: | software distribution had a quite different model in that | era. | TakeBlaster16 wrote: | If you play a lot of SimCity on Windows 3.1, then you | upgrade to Windows 95 and SimCity stops working, who are | you going to blame? | mdaniel wrote: | I would have more sympathy for that if Windows 95 were | just suddenly dropped out of the sky to some rock music, | but my experience with MSDN is that they are quite | liberal with access to beta versions so _software | vendors_ can test their products before the unwashed | masses get it | | And I say this as someone who remembers the binders full | of CDROMs that arrived, so not just "download this iso" | modern day conveniences | drdec wrote: | Let's say SimCity took advantage of this beta program and | fixed their buggy software. Great! | | Now how do you get that fixed software to every user who | bought a SimCity CD or floppies? Remember, most of your | users don't have a modem and there is no widespread | internet infrastructure at the time of the Windows 95 | release. | rictic wrote: | You're arguing who is truly at fault, but as a consumer | with less sophistication than "MSDN Subscriber" who are | you going to blame when Win95 doesn't run your favorite | software? | ysavir wrote: | We're talking early 90s. Not only were automatic updates | not a thing, manual updates were hardly thing. If Windows | wanted SimCity to work on their new windows release, the | only option was to make the new windows release work with | SimCity, not the other way around. | markemer wrote: | Yeah. I had this version of SimCity. It came on floppy | disk. I had a 14.4k modem at the time (or maybe still the | stock 2400?) the only way for MSFT to make this work was | to add code like this. Honestly we still do it sometimes. | Emulators routinely emulate bugs because those bugs were | never fixed in the real systems. | Topgamer7 wrote: | I remember the days of burning all sorts of updates for | software to cd or DVD | tibbetts wrote: | I remember the days of going down to my friends store | because he had a modem and knew which BBSes would have | software downloads. I had to bring my own floppy disk | because those things cost money. | nix23 wrote: | But then why not let windows patch simcity, instead of | changing the system, just asking. | solardev wrote: | That'd break SimCity updates, and probably trigger | antivirus warnings, and annoy Maxis devs and lawyers... | | Whereas "we'll tweak our OS to suit your app to ensure it | doesn't break with an upgrade"? That just wins loyalty | from the game devs, users, and everyone involved except | purist-coder types. | scarface74 wrote: | And it makes operating systems larger, more bug prone and | harder to maintain. | | There is a reason that Apple was able to port the core of | iOS and many of the APIs to watches, phones, tablets, set | top boxes, monitors (the latest Apple monitor runs iOS on | an iPhone 11 era processor with 64GB RAM). | solardev wrote: | Yeah, but there's also a reason why you can still run | most Windows 95-era apps on today's PCs, vs not being | able to run most 2-year-old games on M1 Macs. Rosetta is | pretty amazing but it's far from actual compatibility. | | Apple's approach to backward compatibility is very | different from Microsoft's. | | It's not uniquely a Microsoft thing, either. Nvidia's | driver updates frequently (in fact almost always) have | game-specific optimizations. Antivirus and firewall apps | frequently have to make exceptions for certain apps. WINE | and Proton operate on per-game optimizations. Input | controller managers (like Steam's profiles) have | different settings per game. DirectX itself does a lot of | backward compatibility stuff, AND allow different | versions to coexist on the same PC (vs the relatively | tiny market that exists for Metal or Vulkan). | | All these things contribute to PC gaming vastly | outselling the tiny Mac gaming market. As a Mac user, I | wish that weren't so! But MS's approach is way better for | devs and users in that case, even at the cost of the | Windows APIs and libs being huge with a decades-long | tail. | scarface74 wrote: | As a user of a current ARM MacBook Pro 16 inch and a | former x86 MacBook Pro, being able to have a battery that | last 20 hours, doesn't get hot, nor does it sound like a | 747 when I launch Slack, I very much appreciate Apple | being able to transition processors. | | Also seeing that the iOS game market dwarfs the PC game | market in revenue and number of titles (if not quality), | I think Apple made the right choice. | | Microsoft has been unsuccessful trying to get Windows on | ARM to be viable for years before Apple did it and has | failed partially because of the behemoth that Windows is. | | Speaking of Windows and backwards compatibility. There | are at least 8 different ways to define a string in | Windows depending on which API you are calling. String | handling in C is one of the biggest causes of security | vulnerabilities on any platform. | | https://learn.microsoft.com/en-us/cpp/text/how-to- | convert-be... | solardev wrote: | I love my Macbook too, and am hoping it revitalizes the | dead OSX games industry. But its lack of backward | compatibility further hurts its gaming capabilities vs | the already-limited x86 OSX games. It's nice when it does | work and you have some M1-native titles (Baldur's Gate, | etc.) but those are far and few in between. Sure, it's a | great business machine, it's just not a gamer's laptop | (even though its hardware is fully capable). I use my M1 | for most things, but still have to use Windows x86 for | actual gaming. | | Yes, Windows's backward compatibility carries a high | cost. Nobody doubts that. But as a gamer, I would rather | to be able to play games on a shitty OS than to have the | latest, most vertically integrated all-in-one chip and | stellar OS and be limited to a library of like 15 five- | year-old titles. | | As for the "right choice", eh, maybe from a business | angle... but as a gamer, iOS games suck. They probably | have that revenue mostly from lootboxes, not actual | gameplay. I don't know that Apple should be applauded for | turning video gaming into online gambling. That's not | really a hardware/OS stack question anyway though, but a | business decision. And to be fair, many of the actually | curated titles (like the ones on Apple Arcade) are pretty | decent -- though nothing close to the thriving indie | scene on Steam/x86 Windows. | | iOS is more like a console in that they're creating a new | market segment, not necessarily competing with | traditional PC gaming (which has taken a turn for the | worse by adopting mobile lootboxes and such). On the | other hand, OSX and Linux both tried the purist gaming | route with their own APIs and got nowhere. It took WINE | and Proton to really make the Steam Deck a viable | platform (and barely that). | | Do I like this situation? No, I'd rather just have games | be properly cross-platform to begin with. I don't really | understand how cross-platform works in Unreal and Unity, | but if those engines can add native Apple Silicon support | and make it easy for publishers to cross-publish, | hopefully we'll see Macs on future titles alongside | PC/PS/Xbox/Switch. Till then... | scarface74 wrote: | Look at where the mobile gaming revenue is today: | | https://www.giffgaff.com/blog/mobile-gaming-overtakes-pc- | and... | | On top of that, you can carve out the percentage of "PC | Gaming" that is "browser based" since you can run those | on a Mac. The industry is moving toward browser based | streaming games. | | https://www.marketdataforecast.com/market-reports/game- | strea... | anaisbetts wrote: | The hack being described was very very old, this is | exactly what the AppCompat system does in Windows now. | AppCompat shims only apply to specific versions of | specific apps (or get rolled up into "layers" which is | what you get when you mark an app to "Run under XP | compatibility"), and don't end up affecting other ones | markemer wrote: | Yep. It's just the first version of AppCompat. Now you | get to pick a set of bugs and behaviors. It's actually a | pretty great idea to isolate problematic software. | nix23 wrote: | Thanks for then explanation!! | monocasa wrote: | By changing the system they have a flag they can turn on | for any applications that would be helped by a similar | hack. It's not like use after free was a particularly | rare event in mid 90s code. | ysavir wrote: | You mean, like watch for an install of SimCity, and | modify the game's files? I don't have enough experience | in hardware and PCs to know if that was at all possible | or practical. | markemer wrote: | Honestly you could probably do it today, but back then it | would have been a lot harder. You'd have to find every | buggy use after free. Just easier to change the allocator | for it. Probably how you'd do it today under emulation. | nix23 wrote: | >like watch for an install of SimCity, and modify the | game's files? | | Yes exactly! Technically easy, a Lawyers thing maybe? | Someone wrote: | Could also be interesting in a world where most PCs ran | anti-virus tools of various different vendors. | | Imagine Microsoft adding a magic "we're the good guys" | handshake to their OS that would all those anti-virus | tool say "go ahead and do whatever you want". | siva7 wrote: | Nowadays yes, back then this was the more reasonable | approach | eastbound wrote: | My astonishment is that Microsoft _knew_ about SimCity. I was | 15 in 1995 and I thought the world was so big that Microsoft | couldn't possibly know about the myriad of software that | their OS could run. | | It turns out the world was so small that Microsoft could, | probably, inventory less than a hundred products that made | 99% users happy. | benjaminpv wrote: | Raymond Chen talked about how periodically the devs were | tasked with getting a handful of software purchased at | CompUSA or w/e out of a grocery cart, opening them up, | installing them and testing that they worked with the then- | unreleased Win95. | draw_down wrote: | coldcode wrote: | When I was at Apple in the mid 90's (Before Steve) I remember | the Mac OS source code had tons of special app checks, mostly | for various Microsoft (also others) apps that did odd things, | so that older versions would keep running. When they were | working on Copland, I thought it was nuts to write a new OS | from scratch, but still do reimplement the hacks so that | everything would still run. Good thing it all went away. | peyton wrote: | They're still there. IIRC there's a whole workflow/category | in Radar for it. | nikanj wrote: | Wait, I thought the only workflow supported by radar was | ticket filed -> ticket ignored -> product eventually EOL | -> ticket closed | stormbrew wrote: | probably only a 50/50 chance it gets closed tbh. Either | way it's in a black hole to the reporter so they'll never | know. | | (I actually liked radar though, as bug trackers go - by | far the best internal tool apple has imo) | orblivion wrote: | Some people here are complaining that this is a hack, technical | debt, etc. I thought the point would be the political one, as it | were. YouTube.com gets special treatment in a major web browser, | whereas Sal's discount video website has to conform to standards | like all the other plebs. | | It's an erosion (however minor, by itself) of the idea of an open | standard. | scarface74 wrote: | Apple has a list of websites with quirks that don't support its | "generate strong passwords" feature even though there is HTML | spec where you can specify the types of passwords you support. | | https://github.com/apple/password-manager-resources | | Many of these sites are quite obscure. | dopa42365 wrote: | https://github.com/apple/password-manager- | resources/blob/mai... | | For being "quite obscure", I've at least heard of most of | these sites before. Banks with "maxlength: 8", you love to | see it. | masswerk wrote: | If this goes against your philosophy, you can actually disable | this: | | Develop Menu > Disable Site-specific Hacks | eimrine wrote: | Could you tell those who are not familiar with WebKit what this | code actually does? | hadrien01 wrote: | When the first iPhone was released, YouTube used Flash instead | of HTML5. Safari had special code to play the video with the | native player instead of displaying a blank square. I suppose | (from the flash-specific detection in the supportsMIMEType | method) that this code was in charge of that logic. | londons_explore wrote: | Note that while the code was written in 2014 (well _after_ | the iphone was released), someone tried to remove the code | this year[1], and gave up because some sites now rely on this | hack. | | [1]: https://github.com/WebKit/WebKit/commit/049188a35af6c67f | a30c... | thrdbndndn wrote: | It didn't specify which websites, now I'm curious. | oefrha wrote: | Of course, all observable behaviors of your system will be | depended on by somebody. | Anunayj wrote: | Relevant xkcd: https://xkcd.com/1172/ | bdash wrote: | The code was added to the public WebKit source tree, but it | wasn't written at the time. It was upstreamed from the | internal fork of WebKit that Apple used for iOS. | JonathonW wrote: | Also the youTubeFlashPluginReplacementEnabled settings | property that it looks for to check if it's enabled seems | like a strong hint. | leeoniya wrote: | hehe, now let's see all the WebKit-specific code in YouTube :D ___________________________________________________________________ (page generated 2022-09-18 23:00 UTC)