How does the widget in a beer can work?
To answer this question first we need to discuss what makes beer fizzy and how a head forms.
Most beers are carbonated with carbon dioxide (CO2). When the beer is in the can some of this CO2 is dissolved in the beer and some is at the top of the can. The CO2 that is dissolved in the beer is what makes it fizzy. When the can is closed the pressure inside is higher than the pressure outside, so that when you open the can the sudden drop in pressure and the agitation of pouring causes some of the CO2 to bubble out of solution, forming a head on your beer.
A stout like Guinness has a creamier, longer lasting head than a canned lager beer. In addition, Guinness is less fizzy than a regular lager beer. Guinness is canned with a mixture of carbon dioxide and nitrogen. Nitrogen is not absorbed into the beer nearly as well as carbon dioxide, so even though a can of Guinness may be at the same pressure as a can of lager, it contains less CO (and is therefore less fizzy) because the nitrogen makes up some of the pressure.
Because a beer like Guinness contains less dissolved CO2, if you poured it from a can with no widget, the head not be very thick because most of the CO2 would stay dissolved.
The purpose of the widget is to release the CO2 from some of the beer in the can to create the head. The widget is a plastic, nitrogen-filled sphere with a tiny hole in it. The sphere is added to the can before the can is sealed. It floats in the beer, with the hole just slightly below the surface of the beer.
Just before the can is sealed a small shot of liquid nitrogen is added to the beer. This liquid nitrogen evaporates during the rest of the canning process and pressurizes the can. As the pressure increases in the can, beer is slowly forced into the sphere through the hole, compressing the nitrogen inside the sphere.
When you open the can, the pressure inside immediately drops, the compressed gas inside the sphere quickly forces the beer out through the tiny hole into the can. As the beer rushes through the tiny hole, this agitation causes the CO2 that is dissolved in the beer to form tiny bubbles that rise to the surface of the beer. These bubbles help form the head.