code
stringlengths
2.5k
150k
kind
stringclasses
1 value
elixir Enumerables and Streams Getting Started Enumerables and Streams ======================= Enumerables ----------- Elixir provides the concept of enumerables and [the `Enum` module](https://hexdocs.pm/elixir/Enum.html) to work with them. We have already learned two enumerables: lists and maps. ``` iex> Enum.map([1, 2, 3], fn x -> x * 2 end) [2, 4, 6] iex> Enum.map(%{1 => 2, 3 => 4}, fn {k, v} -> k * v end) [2, 12] ``` The `Enum` module provides a huge range of functions to transform, sort, group, filter and retrieve items from enumerables. It is one of the modules developers use frequently in their Elixir code. Elixir also provides ranges: ``` iex> Enum.map(1..3, fn x -> x * 2 end) [2, 4, 6] iex> Enum.reduce(1..3, 0, &+/2) 6 ``` The functions in the Enum module are limited to, as the name says, enumerating values in data structures. For specific operations, like inserting and updating particular elements, you may need to reach for modules specific to the data type. For example, if you want to insert an element at a given position in a list, you should use the `List.insert_at/3` function from [the `List` module](https://hexdocs.pm/elixir/List.html), as it would make little sense to insert a value into, for example, a range. We say the functions in the `Enum` module are polymorphic because they can work with diverse data types. In particular, the functions in the `Enum` module can work with any data type that implements [the `Enumerable` protocol](https://hexdocs.pm/elixir/Enumerable.html). We are going to discuss Protocols in a later chapter; for now we are going to move on to a specific kind of enumerable called a stream. Eager vs Lazy ------------- All the functions in the `Enum` module are eager. Many functions expect an enumerable and return a list back: ``` iex> odd? = &(rem(&1, 2) != 0) #Function<6.80484245/1 in :erl_eval.expr/5> iex> Enum.filter(1..3, odd?) [1, 3] ``` This means that when performing multiple operations with `Enum`, each operation is going to generate an intermediate list until we reach the result: ``` iex> 1..100_000 |> Enum.map(&(&1 * 3)) |> Enum.filter(odd?) |> Enum.sum 7500000000 ``` The example above has a pipeline of operations. We start with a range and then multiply each element in the range by 3. This first operation will now create and return a list with `100_000` items. Then we keep all odd elements from the list, generating a new list, now with `50_000` items, and then we sum all entries. The pipe operator ----------------- The `|>` symbol used in the snippet above is the **pipe operator**: it takes the output from the expression on its left side and passes it as the first argument to the function call on its right side. It’s similar to the Unix `|` operator. Its purpose is to highlight the data being transformed by a series of functions. To see how it can make the code cleaner, have a look at the example above rewritten without using the `|>` operator: ``` iex> Enum.sum(Enum.filter(Enum.map(1..100_000, &(&1 * 3)), odd?)) 7500000000 ``` Find more about the pipe operator [by reading its documentation](https://hexdocs.pm/elixir/Kernel.html#%7C%3E/2). Streams ------- As an alternative to `Enum`, Elixir provides [the `Stream` module](https://hexdocs.pm/elixir/Stream.html) which supports lazy operations: ``` iex> 1..100_000 |> Stream.map(&(&1 * 3)) |> Stream.filter(odd?) |> Enum.sum 7500000000 ``` Streams are lazy, composable enumerables. In the example above, `1..100_000 |> Stream.map(&(&1 * 3))` returns a data type, an actual stream, that represents the `map` computation over the range `1..100_000`: ``` iex> 1..100_000 |> Stream.map(&(&1 * 3)) #Stream<[enum: 1..100000, funs: [#Function<34.16982430/1 in Stream.map/2>]]> ``` Furthermore, they are composable because we can pipe many stream operations: ``` iex> 1..100_000 |> Stream.map(&(&1 * 3)) |> Stream.filter(odd?) #Stream<[enum: 1..100000, funs: [...]]> ``` Instead of generating intermediate lists, streams build a series of computations that are invoked only when we pass the underlying stream to the `Enum` module. Streams are useful when working with large, *possibly infinite*, collections. Many functions in the `Stream` module accept any enumerable as an argument and return a stream as a result. It also provides functions for creating streams. For example, `Stream.cycle/1` can be used to create a stream that cycles a given enumerable infinitely. Be careful to not call a function like `Enum.map/2` on such streams, as they would cycle forever: ``` iex> stream = Stream.cycle([1, 2, 3]) #Function<15.16982430/2 in Stream.unfold/2> iex> Enum.take(stream, 10) [1, 2, 3, 1, 2, 3, 1, 2, 3, 1] ``` On the other hand, `Stream.unfold/2` can be used to generate values from a given initial value: ``` iex> stream = Stream.unfold("hełło", &String.next_codepoint/1) #Function<39.75994740/2 in Stream.unfold/2> iex> Enum.take(stream, 3) ["h", "e", "ł"] ``` Another interesting function is `Stream.resource/3` which can be used to wrap around resources, guaranteeing they are opened right before enumeration and closed afterwards, even in the case of failures. For example, `File.stream!/1` builds on top of `Stream.resource/3` to stream files: ``` iex> stream = File.stream!("path/to/file") %File.Stream{ line_or_bytes: :line, modes: [:raw, :read_ahead, :binary], path: "path/to/file", raw: true } iex> Enum.take(stream, 10) ``` The example above will fetch the first 10 lines of the file you have selected. This means streams can be very useful for handling large files or even slow resources like network resources. The amount of functionality in the [`Enum`](https://hexdocs.pm/elixir/Enum.html) and [`Stream`](https://hexdocs.pm/elixir/Stream.html) modules can be daunting at first, but you will get familiar with them case by case. In particular, focus on the `Enum` module first and only move to `Stream` for the particular scenarios where laziness is required, to either deal with slow resources or large, possibly infinite, collections. Next, we’ll look at a feature central to Elixir, Processes, which allows us to write concurrent, parallel and distributed programs in an easy and understandable way. elixir NaiveDateTime NaiveDateTime ============== A NaiveDateTime struct (without a time zone) and functions. The NaiveDateTime struct contains the fields year, month, day, hour, minute, second, microsecond and calendar. New naive datetimes can be built with the [`new/2`](#new/2) and [`new/8`](#new/8) functions or using the `~N` (see [`Kernel.sigil_N/2`](kernel#sigil_N/2)) sigil: ``` iex> ~N[2000-01-01 23:00:07] ~N[2000-01-01 23:00:07] ``` The date and time fields in the struct can be accessed directly: ``` iex> naive = ~N[2000-01-01 23:00:07] iex> naive.year 2000 iex> naive.second 7 ``` We call them "naive" because this datetime representation does not have a time zone. This means the datetime may not actually exist in certain areas in the world even though it is valid. For example, when daylight saving changes are applied by a region, the clock typically moves forward or backward by one hour. This means certain datetimes never occur or may occur more than once. Since [`NaiveDateTime`](#content) is not validated against a time zone, such errors would go unnoticed. Developers should avoid creating the NaiveDateTime structs directly and instead, rely on the functions provided by this module as well as the ones in third-party calendar libraries. Comparing naive date times --------------------------- Comparisons in Elixir using [`==/2`](kernel#==/2), [`>/2`](kernel#%3E/2), [`</2`](kernel#%3C/2) and similar are structural and based on the [`NaiveDateTime`](#content) struct fields. For proper comparison between naive datetimes, use the [`compare/2`](#compare/2) function. Using epochs ------------- The [`add/3`](#add/3) and [`diff/3`](#diff/3) functions can be used for computing with date times or retrieving the number of seconds between instants. For example, if there is an interest in computing the number of seconds from the Unix epoch (1970-01-01 00:00:00): ``` iex> NaiveDateTime.diff(~N[2010-04-17 14:00:00], ~N[1970-01-01 00:00:00]) 1271512800 iex> NaiveDateTime.add(~N[1970-01-01 00:00:00], 1_271_512_800) ~N[2010-04-17 14:00:00] ``` Those functions are optimized to deal with common epochs, such as the Unix Epoch above or the Gregorian Epoch (0000-01-01 00:00:00). Summary ======== Types ------ [t()](#t:t/0) Functions ---------- [add(naive\_datetime, amount\_to\_add, unit \\ :second)](#add/3) Adds a specified amount of time to a [`NaiveDateTime`](#content). [compare(naive\_datetime1, naive\_datetime2)](#compare/2) Compares two [`NaiveDateTime`](#content) structs. [convert(naive\_datetime, calendar)](#convert/2) Converts the given `naive_datetime` from one calendar to another. [convert!(naive\_datetime, calendar)](#convert!/2) Converts the given `naive_datetime` from one calendar to another. [diff(naive\_datetime1, naive\_datetime2, unit \\ :second)](#diff/3) Subtracts `naive_datetime2` from `naive_datetime1`. [from\_erl(tuple, microsecond \\ {0, 0}, calendar \\ Calendar.ISO)](#from_erl/3) Converts an Erlang datetime tuple to a [`NaiveDateTime`](#content) struct. [from\_erl!(tuple, microsecond \\ {0, 0}, calendar \\ Calendar.ISO)](#from_erl!/3) Converts an Erlang datetime tuple to a [`NaiveDateTime`](#content) struct. [from\_iso8601(string, calendar \\ Calendar.ISO)](#from_iso8601/2) Parses the extended "Date and time of day" format described by [ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601). [from\_iso8601!(string, calendar \\ Calendar.ISO)](#from_iso8601!/2) Parses the extended "Date and time of day" format described by [ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601). [new(date, time)](#new/2) Builds a naive datetime from date and time structs. [new(year, month, day, hour, minute, second, microsecond \\ {0, 0}, calendar \\ Calendar.ISO)](#new/8) Builds a new ISO naive datetime. [to\_date(map)](#to_date/1) Converts a [`NaiveDateTime`](#content) into a [`Date`](date). [to\_erl(naive\_datetime)](#to_erl/1) Converts a [`NaiveDateTime`](#content) struct to an Erlang datetime tuple. [to\_iso8601(naive\_datetime, format \\ :extended)](#to_iso8601/2) Converts the given naive datetime to [ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601). [to\_string(naive\_datetime)](#to_string/1) Converts the given naive datetime to a string according to its calendar. [to\_time(map)](#to_time/1) Converts a [`NaiveDateTime`](#content) into [`Time`](time). [truncate(naive\_datetime, precision)](#truncate/2) Returns the given naive datetime with the microsecond field truncated to the given precision (`:microsecond`, `:millisecond` or `:second`). [utc\_now(calendar \\ Calendar.ISO)](#utc_now/1) Returns the current naive datetime in UTC. Types ====== ### t() #### Specs ``` t() :: %NaiveDateTime{ calendar: Calendar.calendar(), day: Calendar.day(), hour: Calendar.hour(), microsecond: Calendar.microsecond(), minute: Calendar.minute(), month: Calendar.month(), second: Calendar.second(), year: Calendar.year() } ``` Functions ========== ### add(naive\_datetime, amount\_to\_add, unit \\ :second) #### Specs ``` add(Calendar.naive_datetime(), integer(), System.time_unit()) :: t() ``` Adds a specified amount of time to a [`NaiveDateTime`](#content). Accepts an `amount_to_add` in any `unit` available from [`System.time_unit/0`](system#t:time_unit/0). Negative values will move backwards in time. #### Examples ``` # adds seconds by default iex> NaiveDateTime.add(~N[2014-10-02 00:29:10], 2) ~N[2014-10-02 00:29:12] # accepts negative offsets iex> NaiveDateTime.add(~N[2014-10-02 00:29:10], -2) ~N[2014-10-02 00:29:08] # can work with other units iex> NaiveDateTime.add(~N[2014-10-02 00:29:10], 2_000, :millisecond) ~N[2014-10-02 00:29:12] # keeps the same precision iex> NaiveDateTime.add(~N[2014-10-02 00:29:10.021], 21, :second) ~N[2014-10-02 00:29:31.021] # changes below the precision will not be visible iex> hidden = NaiveDateTime.add(~N[2014-10-02 00:29:10], 21, :millisecond) iex> hidden.microsecond # ~N[2014-10-02 00:29:10] {21000, 0} # from Gregorian seconds iex> NaiveDateTime.add(~N[0000-01-01 00:00:00], 63_579_428_950) ~N[2014-10-02 00:29:10] ``` Passing a [`DateTime`](datetime) automatically converts it to [`NaiveDateTime`](#content), discarding the time zone information: ``` iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "CET", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: 3600, std_offset: 0, time_zone: "Europe/Warsaw"} iex> NaiveDateTime.add(dt, 21, :second) ~N[2000-02-29 23:00:28] ``` ### compare(naive\_datetime1, naive\_datetime2) #### Specs ``` compare(Calendar.naive_datetime(), Calendar.naive_datetime()) :: :lt | :eq | :gt ``` Compares two [`NaiveDateTime`](#content) structs. Returns `:gt` if first is later than the second and `:lt` for vice versa. If the two NaiveDateTime are equal `:eq` is returned. #### Examples ``` iex> NaiveDateTime.compare(~N[2016-04-16 13:30:15], ~N[2016-04-28 16:19:25]) :lt iex> NaiveDateTime.compare(~N[2016-04-16 13:30:15.1], ~N[2016-04-16 13:30:15.01]) :gt ``` This function can also be used to compare a DateTime without the time zone information: ``` iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "CET", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: 3600, std_offset: 0, time_zone: "Europe/Warsaw"} iex> NaiveDateTime.compare(dt, ~N[2000-02-29 23:00:07]) :eq iex> NaiveDateTime.compare(dt, ~N[2000-01-29 23:00:07]) :gt iex> NaiveDateTime.compare(dt, ~N[2000-03-29 23:00:07]) :lt ``` ### convert(naive\_datetime, calendar) #### Specs ``` convert(Calendar.naive_datetime(), Calendar.calendar()) :: {:ok, t()} | {:error, :incompatible_calendars} ``` Converts the given `naive_datetime` from one calendar to another. If it is not possible to convert unambiguously between the calendars (see [`Calendar.compatible_calendars?/2`](calendar#compatible_calendars?/2)), an `{:error, :incompatible_calendars}` tuple is returned. #### Examples Imagine someone implements `Calendar.Holocene`, a calendar based on the Gregorian calendar that adds exactly 10,000 years to the current Gregorian year: ``` iex> NaiveDateTime.convert(~N[2000-01-01 13:30:15], Calendar.Holocene) {:ok, %NaiveDateTime{calendar: Calendar.Holocene, year: 12000, month: 1, day: 1, hour: 13, minute: 30, second: 15, microsecond: {0, 0}}} ``` ### convert!(naive\_datetime, calendar) #### Specs ``` convert!(Calendar.naive_datetime(), Calendar.calendar()) :: t() ``` Converts the given `naive_datetime` from one calendar to another. If it is not possible to convert unambiguously between the calendars (see [`Calendar.compatible_calendars?/2`](calendar#compatible_calendars?/2)), an ArgumentError is raised. #### Examples Imagine someone implements `Calendar.Holocene`, a calendar based on the Gregorian calendar that adds exactly 10,000 years to the current Gregorian year: ``` iex> NaiveDateTime.convert!(~N[2000-01-01 13:30:15], Calendar.Holocene) %NaiveDateTime{calendar: Calendar.Holocene, year: 12000, month: 1, day: 1, hour: 13, minute: 30, second: 15, microsecond: {0, 0}} ``` ### diff(naive\_datetime1, naive\_datetime2, unit \\ :second) #### Specs ``` diff(Calendar.naive_datetime(), Calendar.naive_datetime(), System.time_unit()) :: integer() ``` Subtracts `naive_datetime2` from `naive_datetime1`. The answer can be returned in any `unit` available from [`System.time_unit/0`](system#t:time_unit/0). This function returns the difference in seconds where seconds are measured according to [`Calendar.ISO`](calendar.iso). #### Examples ``` iex> NaiveDateTime.diff(~N[2014-10-02 00:29:12], ~N[2014-10-02 00:29:10]) 2 iex> NaiveDateTime.diff(~N[2014-10-02 00:29:12], ~N[2014-10-02 00:29:10], :microsecond) 2_000_000 iex> NaiveDateTime.diff(~N[2014-10-02 00:29:10.042], ~N[2014-10-02 00:29:10.021], :millisecond) 21 iex> NaiveDateTime.diff(~N[2014-10-02 00:29:10], ~N[2014-10-02 00:29:12]) -2 iex> NaiveDateTime.diff(~N[-0001-10-02 00:29:10], ~N[-0001-10-02 00:29:12]) -2 # to Gregorian seconds iex> NaiveDateTime.diff(~N[2014-10-02 00:29:10], ~N[0000-01-01 00:00:00]) 63579428950 ``` ### from\_erl(tuple, microsecond \\ {0, 0}, calendar \\ Calendar.ISO) #### Specs ``` from_erl(:calendar.datetime(), Calendar.microsecond(), Calendar.calendar()) :: {:ok, t()} | {:error, atom()} ``` Converts an Erlang datetime tuple to a [`NaiveDateTime`](#content) struct. Attempting to convert an invalid ISO calendar date will produce an error tuple. #### Examples ``` iex> NaiveDateTime.from_erl({{2000, 1, 1}, {13, 30, 15}}) {:ok, ~N[2000-01-01 13:30:15]} iex> NaiveDateTime.from_erl({{2000, 1, 1}, {13, 30, 15}}, {5000, 3}) {:ok, ~N[2000-01-01 13:30:15.005]} iex> NaiveDateTime.from_erl({{2000, 13, 1}, {13, 30, 15}}) {:error, :invalid_date} iex> NaiveDateTime.from_erl({{2000, 13, 1}, {13, 30, 15}}) {:error, :invalid_date} ``` ### from\_erl!(tuple, microsecond \\ {0, 0}, calendar \\ Calendar.ISO) #### Specs ``` from_erl!(:calendar.datetime(), Calendar.microsecond(), Calendar.calendar()) :: t() ``` Converts an Erlang datetime tuple to a [`NaiveDateTime`](#content) struct. Raises if the datetime is invalid. Attempting to convert an invalid ISO calendar date will produce an error tuple. #### Examples ``` iex> NaiveDateTime.from_erl!({{2000, 1, 1}, {13, 30, 15}}) ~N[2000-01-01 13:30:15] iex> NaiveDateTime.from_erl!({{2000, 1, 1}, {13, 30, 15}}, {5000, 3}) ~N[2000-01-01 13:30:15.005] iex> NaiveDateTime.from_erl!({{2000, 13, 1}, {13, 30, 15}}) ** (ArgumentError) cannot convert {{2000, 13, 1}, {13, 30, 15}} to naive datetime, reason: :invalid_date ``` ### from\_iso8601(string, calendar \\ Calendar.ISO) #### Specs ``` from_iso8601(String.t(), Calendar.calendar()) :: {:ok, t()} | {:error, atom()} ``` Parses the extended "Date and time of day" format described by [ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601). Time zone offset may be included in the string but they will be simply discarded as such information is not included in naive date times. As specified in the standard, the separator "T" may be omitted if desired as there is no ambiguity within this function. The year parsed by this function is limited to four digits and, while ISO 8601 allows datetimes to specify 24:00:00 as the zero hour of the next day, this notation is not supported by Elixir. Note leap seconds are not supported by the built-in Calendar.ISO. #### Examples ``` iex> NaiveDateTime.from_iso8601("2015-01-23 23:50:07") {:ok, ~N[2015-01-23 23:50:07]} iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07") {:ok, ~N[2015-01-23 23:50:07]} iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07Z") {:ok, ~N[2015-01-23 23:50:07]} iex> NaiveDateTime.from_iso8601("2015-01-23 23:50:07.0") {:ok, ~N[2015-01-23 23:50:07.0]} iex> NaiveDateTime.from_iso8601("2015-01-23 23:50:07,0123456") {:ok, ~N[2015-01-23 23:50:07.012345]} iex> NaiveDateTime.from_iso8601("2015-01-23 23:50:07.0123456") {:ok, ~N[2015-01-23 23:50:07.012345]} iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07.123Z") {:ok, ~N[2015-01-23 23:50:07.123]} iex> NaiveDateTime.from_iso8601("2015-01-23P23:50:07") {:error, :invalid_format} iex> NaiveDateTime.from_iso8601("2015:01:23 23-50-07") {:error, :invalid_format} iex> NaiveDateTime.from_iso8601("2015-01-23 23:50:07A") {:error, :invalid_format} iex> NaiveDateTime.from_iso8601("2015-01-23 23:50:61") {:error, :invalid_time} iex> NaiveDateTime.from_iso8601("2015-01-32 23:50:07") {:error, :invalid_date} iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07.123+02:30") {:ok, ~N[2015-01-23 23:50:07.123]} iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07.123+00:00") {:ok, ~N[2015-01-23 23:50:07.123]} iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07.123-02:30") {:ok, ~N[2015-01-23 23:50:07.123]} iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07.123-00:00") {:error, :invalid_format} iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07.123-00:60") {:error, :invalid_format} iex> NaiveDateTime.from_iso8601("2015-01-23T23:50:07.123-24:00") {:error, :invalid_format} ``` ### from\_iso8601!(string, calendar \\ Calendar.ISO) #### Specs ``` from_iso8601!(String.t(), Calendar.calendar()) :: t() ``` Parses the extended "Date and time of day" format described by [ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601). Raises if the format is invalid. #### Examples ``` iex> NaiveDateTime.from_iso8601!("2015-01-23T23:50:07.123Z") ~N[2015-01-23 23:50:07.123] iex> NaiveDateTime.from_iso8601!("2015-01-23T23:50:07,123Z") ~N[2015-01-23 23:50:07.123] iex> NaiveDateTime.from_iso8601!("2015-01-23P23:50:07") ** (ArgumentError) cannot parse "2015-01-23P23:50:07" as naive datetime, reason: :invalid_format ``` ### new(date, time) #### Specs ``` new(Date.t(), Time.t()) :: {:ok, t()} ``` Builds a naive datetime from date and time structs. #### Examples ``` iex> NaiveDateTime.new(~D[2010-01-13], ~T[23:00:07.005]) {:ok, ~N[2010-01-13 23:00:07.005]} ``` ### new(year, month, day, hour, minute, second, microsecond \\ {0, 0}, calendar \\ Calendar.ISO) #### Specs ``` new( Calendar.year(), Calendar.month(), Calendar.day(), Calendar.hour(), Calendar.minute(), Calendar.second(), Calendar.microsecond(), Calendar.calendar() ) :: {:ok, t()} | {:error, atom()} ``` Builds a new ISO naive datetime. Expects all values to be integers. Returns `{:ok, naive_datetime}` if each entry fits its appropriate range, returns `{:error, reason}` otherwise. #### Examples ``` iex> NaiveDateTime.new(2000, 1, 1, 0, 0, 0) {:ok, ~N[2000-01-01 00:00:00]} iex> NaiveDateTime.new(2000, 13, 1, 0, 0, 0) {:error, :invalid_date} iex> NaiveDateTime.new(2000, 2, 29, 0, 0, 0) {:ok, ~N[2000-02-29 00:00:00]} iex> NaiveDateTime.new(2000, 2, 30, 0, 0, 0) {:error, :invalid_date} iex> NaiveDateTime.new(2001, 2, 29, 0, 0, 0) {:error, :invalid_date} iex> NaiveDateTime.new(2000, 1, 1, 23, 59, 59, {0, 1}) {:ok, ~N[2000-01-01 23:59:59.0]} iex> NaiveDateTime.new(2000, 1, 1, 23, 59, 59, 999_999) {:ok, ~N[2000-01-01 23:59:59.999999]} iex> NaiveDateTime.new(2000, 1, 1, 24, 59, 59, 999_999) {:error, :invalid_time} iex> NaiveDateTime.new(2000, 1, 1, 23, 60, 59, 999_999) {:error, :invalid_time} iex> NaiveDateTime.new(2000, 1, 1, 23, 59, 60, 999_999) {:error, :invalid_time} iex> NaiveDateTime.new(2000, 1, 1, 23, 59, 59, 1_000_000) {:error, :invalid_time} iex> NaiveDateTime.new(2000, 1, 1, 23, 59, 59, {0, 1}, Calendar.ISO) {:ok, ~N[2000-01-01 23:59:59.0]} ``` ### to\_date(map) #### Specs ``` to_date(Calendar.naive_datetime()) :: Date.t() ``` Converts a [`NaiveDateTime`](#content) into a [`Date`](date). Because [`Date`](date) does not hold time information, data will be lost during the conversion. #### Examples ``` iex> NaiveDateTime.to_date(~N[2002-01-13 23:00:07]) ~D[2002-01-13] ``` ### to\_erl(naive\_datetime) #### Specs ``` to_erl(Calendar.naive_datetime()) :: :calendar.datetime() ``` Converts a [`NaiveDateTime`](#content) struct to an Erlang datetime tuple. Only supports converting naive datetimes which are in the ISO calendar, attempting to convert naive datetimes from other calendars will raise. WARNING: Loss of precision may occur, as Erlang time tuples only store hour/minute/second. #### Examples ``` iex> NaiveDateTime.to_erl(~N[2000-01-01 13:30:15]) {{2000, 1, 1}, {13, 30, 15}} ``` This function can also be used to convert a DateTime to a erl format without the time zone information: ``` iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "CET", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: 3600, std_offset: 0, time_zone: "Europe/Warsaw"} iex> NaiveDateTime.to_erl(dt) {{2000, 2, 29}, {23, 00, 07}} ``` ### to\_iso8601(naive\_datetime, format \\ :extended) #### Specs ``` to_iso8601(Calendar.naive_datetime(), :basic | :extended) :: String.t() ``` Converts the given naive datetime to [ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601). By default, [`NaiveDateTime.to_iso8601/2`](naivedatetime#to_iso8601/2) returns naive datetimes formatted in the "extended" format, for human readability. It also supports the "basic" format through passing the `:basic` option. Only supports converting naive datetimes which are in the ISO calendar, attempting to convert naive datetimes from other calendars will raise. ### Examples ``` iex> NaiveDateTime.to_iso8601(~N[2000-02-28 23:00:13]) "2000-02-28T23:00:13" iex> NaiveDateTime.to_iso8601(~N[2000-02-28 23:00:13.001]) "2000-02-28T23:00:13.001" iex> NaiveDateTime.to_iso8601(~N[2000-02-28 23:00:13.001], :basic) "20000228T230013.001" ``` This function can also be used to convert a DateTime to ISO 8601 without the time zone information: ``` iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "CET", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: 3600, std_offset: 0, time_zone: "Europe/Warsaw"} iex> NaiveDateTime.to_iso8601(dt) "2000-02-29T23:00:07" ``` ### to\_string(naive\_datetime) #### Specs ``` to_string(Calendar.naive_datetime()) :: String.t() ``` Converts the given naive datetime to a string according to its calendar. ### Examples ``` iex> NaiveDateTime.to_string(~N[2000-02-28 23:00:13]) "2000-02-28 23:00:13" iex> NaiveDateTime.to_string(~N[2000-02-28 23:00:13.001]) "2000-02-28 23:00:13.001" iex> NaiveDateTime.to_string(~N[-0100-12-15 03:20:31]) "-0100-12-15 03:20:31" ``` This function can also be used to convert a DateTime to a string without the time zone information: ``` iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "CET", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: 3600, std_offset: 0, time_zone: "Europe/Warsaw"} iex> NaiveDateTime.to_string(dt) "2000-02-29 23:00:07" ``` ### to\_time(map) #### Specs ``` to_time(Calendar.naive_datetime()) :: Time.t() ``` Converts a [`NaiveDateTime`](#content) into [`Time`](time). Because [`Time`](time) does not hold date information, data will be lost during the conversion. #### Examples ``` iex> NaiveDateTime.to_time(~N[2002-01-13 23:00:07]) ~T[23:00:07] ``` ### truncate(naive\_datetime, precision) #### Specs ``` truncate(t(), :microsecond | :millisecond | :second) :: t() ``` Returns the given naive datetime with the microsecond field truncated to the given precision (`:microsecond`, `:millisecond` or `:second`). The given naive datetime is returned unchanged if it already has lower precision than the given precision. #### Examples ``` iex> NaiveDateTime.truncate(~N[2017-11-06 00:23:51.123456], :microsecond) ~N[2017-11-06 00:23:51.123456] iex> NaiveDateTime.truncate(~N[2017-11-06 00:23:51.123456], :millisecond) ~N[2017-11-06 00:23:51.123] iex> NaiveDateTime.truncate(~N[2017-11-06 00:23:51.123456], :second) ~N[2017-11-06 00:23:51] ``` ### utc\_now(calendar \\ Calendar.ISO) #### Specs ``` utc_now(Calendar.calendar()) :: t() ``` Returns the current naive datetime in UTC. Prefer using [`DateTime.utc_now/0`](datetime#utc_now/0) when possible as, opposite to [`NaiveDateTime`](#content), it will keep the time zone information. #### Examples ``` iex> naive_datetime = NaiveDateTime.utc_now() iex> naive_datetime.year >= 2016 true ```
programming_docs
elixir Kernel Kernel ======= [`Kernel`](#content) is Elixir's default environment. It mainly consists of: * basic language primitives, such as arithmetic operators, spawning of processes, data type handling, etc. * macros for control-flow and defining new functionality (modules, functions, and so on) * guard checks for augmenting pattern matching You can use [`Kernel`](#content) functions/macros without the [`Kernel`](#content) prefix anywhere in Elixir code as all its functions and macros are automatically imported. For example, in IEx: ``` iex> is_number(13) true ``` If you don't want to import a function or macro from [`Kernel`](#content), use the `:except` option and then list the function/macro by arity: ``` import Kernel, except: [if: 2, unless: 2] ``` See [`Kernel.SpecialForms.import/2`](kernel.specialforms#import/2) for more information on importing. Elixir also has special forms that are always imported and cannot be skipped. These are described in [`Kernel.SpecialForms`](kernel.specialforms). The standard library --------------------- [`Kernel`](#content) provides the basic capabilities the Elixir standard library is built on top of. It is recommended to explore the standard library for advanced functionality. Here are the main groups of modules in the standard library (this list is not a complete reference, see the documentation sidebar for all entries). ### Built-in types The following modules handle Elixir built-in data types: * [`Atom`](atom) - literal constants with a name (`true`, `false`, and `nil` are atoms) * [`Float`](float) - numbers with floating point precision * [`Function`](function) - a reference to code chunk, created with the [`fn/1`](kernel.specialforms#fn/1) special form * [`Integer`](integer) - whole numbers (not fractions) * [`List`](list) - collections of a variable number of elements (linked lists) * [`Map`](map) - collections of key-value pairs * [`Process`](process) - light-weight threads of execution * [`Port`](port) - mechanisms to interact with the external world * [`Tuple`](tuple) - collections of a fixed number of elements There are two data types without an accompanying module: * Bitstring - a sequence of bits, created with [`Kernel.SpecialForms.<<>>/1`](kernel.specialforms#%3C%3C%3E%3E/1). When the number of bits is divisible by 8, they are called binaries and can be manipulated with Erlang's `:binary` module * Reference - a unique value in the runtime system, created with [`make_ref/0`](#make_ref/0) ### Data types Elixir also provides other data types that are built on top of the types listed above. Some of them are: * [`Date`](date) - `year-month-day` structs in a given calendar * [`DateTime`](datetime) - date and time with time zone in a given calendar * [`Exception`](exception) - data raised from errors and unexpected scenarios * [`MapSet`](mapset) - unordered collections of unique elements * [`NaiveDateTime`](naivedatetime) - date and time without time zone in a given calendar * [`Keyword`](keyword) - lists of two-element tuples, often representing optional values * [`Range`](range) - inclusive ranges between two integers * [`Regex`](regex) - regular expressions * [`String`](string) - UTF-8 encoded binaries representing characters * [`Time`](time) - `hour:minute:second` structs in a given calendar * [`URI`](uri) - representation of URIs that identify resources * [`Version`](version) - representation of versions and requirements ### System modules Modules that interface with the underlying system, such as: * [`IO`](io) - handles input and output * [`File`](file) - interacts with the underlying file system * [`Path`](path) - manipulates file system paths * [`System`](system) - reads and writes system information ### Protocols Protocols add polymorphic dispatch to Elixir. They are contracts implementable by data types. See [`defprotocol/2`](#defprotocol/2) for more information on protocols. Elixir provides the following protocols in the standard library: * [`Collectable`](collectable) - collects data into a data type * [`Enumerable`](enumerable) - handles collections in Elixir. The [`Enum`](enum) module provides eager functions for working with collections, the [`Stream`](stream) module provides lazy functions * [`Inspect`](inspect) - converts data types into their programming language representation * [`List.Chars`](list.chars) - converts data types to their outside world representation as charlists (non-programming based) * [`String.Chars`](string.chars) - converts data types to their outside world representation as strings (non-programming based) ### Process-based and application-centric functionality The following modules build on top of processes to provide concurrency, fault-tolerance, and more. * [`Agent`](agent) - a process that encapsulates mutable state * [`Application`](application) - functions for starting, stopping and configuring applications * [`GenServer`](genserver) - a generic client-server API * [`Registry`](registry) - a key-value process-based storage * [`Supervisor`](supervisor) - a process that is responsible for starting, supervising and shutting down other processes * [`Task`](task) - a process that performs computations * [`Task.Supervisor`](task.supervisor) - a supervisor for managing tasks exclusively ### Supporting documents Elixir documentation also includes supporting documents under the "Pages" section. Those are: * [Compatibility and Deprecations](compatibility-and-deprecations) - lists compatibility between every Elixir version and Erlang/OTP, release schema; lists all deprecated functions, when they were deprecated and alternatives * [Guards](guards) - an introduction to guards and extensions * [Library Guidelines](library-guidelines) - general guidelines, anti-patterns, and rules for those writing libraries * [Naming Conventions](naming-conventions) - naming conventions for Elixir code * [Operators](operators) - lists all Elixir operators and their precedence * [Syntax Reference](syntax-reference) - the language syntax reference * [Typespecs](typespecs)- types and function specifications, including list of types * [Unicode Syntax](unicode-syntax) - outlines Elixir support for Unicode * [Writing Documentation](writing-documentation) - guidelines for writing documentation in Elixir Guards ------- This module includes the built-in guards used by Elixir developers. They are a predefined set of functions and macros that augment pattern matching, typically invoked after the `when` operator. For example: ``` def drive(%User{age: age}) when age >= 16 do ... end ``` The clause above will only be invoked if the user's age is more than or equal to 16. A more complete introduction to guards is available [in the Guards page](guards). Inlining --------- Some of the functions described in this module are inlined by the Elixir compiler into their Erlang counterparts in the [`:erlang` module](http://www.erlang.org/doc/man/erlang.html). Those functions are called BIFs (built-in internal functions) in Erlang-land and they exhibit interesting properties, as some of them are allowed in guards and others are used for compiler optimizations. Most of the inlined functions can be seen in effect when capturing the function: ``` iex> &Kernel.is_atom/1 &:erlang.is_atom/1 ``` Those functions will be explicitly marked in their docs as "inlined by the compiler". Truthy and falsy values ------------------------ Besides the booleans `true` and `false` Elixir also has the concept of a "truthy" or "falsy" value. * a value is truthy when it is neither `false` nor `nil` * a value is falsy when it is either `false` or `nil` Elixir has functions, like [`and/2`](#and/2), that *only* work with booleans, but also functions that work with these truthy/falsy values, like [`&&/2`](#&&/2) and [`!/1`](#!/1). ### Examples We can check the truthiness of a value by using the [`!/1`](#!/1) function twice. Truthy values: ``` iex> !!true true iex> !!5 true iex> !![1,2] true iex> !!"foo" true ``` Falsy values (of which there are exactly two): ``` iex> !!false false iex> !!nil false ``` Summary ======== Guards ------- [left != right](#!=/2) Returns `true` if the two terms are not equal. [left !== right](#!==/2) Returns `true` if the two terms are not exactly equal. [left \* right](#*/2) Arithmetic multiplication. [+value](#+/1) Arithmetic unary plus. [left + right](#+/2) Arithmetic addition. [-value](#-/1) Arithmetic unary minus. [left - right](#-/2) Arithmetic subtraction. [left / right](#//2) Arithmetic division. [left < right](#%3C/2) Returns `true` if left is less than right. [left <= right](#%3C=/2) Returns `true` if left is less than or equal to right. [left == right](#==/2) Returns `true` if the two terms are equal. [left === right](#===/2) Returns `true` if the two terms are exactly equal. [left > right](#%3E/2) Returns `true` if left is more than right. [left >= right](#%3E=/2) Returns `true` if left is more than or equal to right. [abs(number)](#abs/1) Returns an integer or float which is the arithmetical absolute value of `number`. [left and right](#and/2) Boolean and. [binary\_part(binary, start, length)](#binary_part/3) Extracts the part of the binary starting at `start` with length `length`. Binaries are zero-indexed. [bit\_size(bitstring)](#bit_size/1) Returns an integer which is the size in bits of `bitstring`. [byte\_size(bitstring)](#byte_size/1) Returns the number of bytes needed to contain `bitstring`. [ceil(number)](#ceil/1) Returns the smallest integer greater than or equal to `number`. [div(dividend, divisor)](#div/2) Performs an integer division. [elem(tuple, index)](#elem/2) Gets the element at the zero-based `index` in `tuple`. [floor(number)](#floor/1) Returns the largest integer smaller than or equal to `number`. [hd(list)](#hd/1) Returns the head of a list. Raises [`ArgumentError`](argumenterror) if the list is empty. [left in right](#in/2) Checks if the element on the left-hand side is a member of the collection on the right-hand side. [is\_atom(term)](#is_atom/1) Returns `true` if `term` is an atom; otherwise returns `false`. [is\_binary(term)](#is_binary/1) Returns `true` if `term` is a binary; otherwise returns `false`. [is\_bitstring(term)](#is_bitstring/1) Returns `true` if `term` is a bitstring (including a binary); otherwise returns `false`. [is\_boolean(term)](#is_boolean/1) Returns `true` if `term` is either the atom `true` or the atom `false` (i.e., a boolean); otherwise returns `false`. [is\_float(term)](#is_float/1) Returns `true` if `term` is a floating-point number; otherwise returns `false`. [is\_function(term)](#is_function/1) Returns `true` if `term` is a function; otherwise returns `false`. [is\_function(term, arity)](#is_function/2) Returns `true` if `term` is a function that can be applied with `arity` number of arguments; otherwise returns `false`. [is\_integer(term)](#is_integer/1) Returns `true` if `term` is an integer; otherwise returns `false`. [is\_list(term)](#is_list/1) Returns `true` if `term` is a list with zero or more elements; otherwise returns `false`. [is\_map(term)](#is_map/1) Returns `true` if `term` is a map; otherwise returns `false`. [is\_nil(term)](#is_nil/1) Returns `true` if `term` is `nil`, `false` otherwise. [is\_number(term)](#is_number/1) Returns `true` if `term` is either an integer or a floating-point number; otherwise returns `false`. [is\_pid(term)](#is_pid/1) Returns `true` if `term` is a PID (process identifier); otherwise returns `false`. [is\_port(term)](#is_port/1) Returns `true` if `term` is a port identifier; otherwise returns `false`. [is\_reference(term)](#is_reference/1) Returns `true` if `term` is a reference; otherwise returns `false`. [is\_tuple(term)](#is_tuple/1) Returns `true` if `term` is a tuple; otherwise returns `false`. [length(list)](#length/1) Returns the length of `list`. [map\_size(map)](#map_size/1) Returns the size of a map. [node()](#node/0) Returns an atom representing the name of the local node. If the node is not alive, `:nonode@nohost` is returned instead. [node(arg)](#node/1) Returns the node where the given argument is located. The argument can be a PID, a reference, or a port. If the local node is not alive, `:nonode@nohost` is returned. [not(value)](#not/1) Boolean not. [left or right](#or/2) Boolean or. [rem(dividend, divisor)](#rem/2) Computes the remainder of an integer division. [round(number)](#round/1) Rounds a number to the nearest integer. [self()](#self/0) Returns the PID (process identifier) of the calling process. [tl(list)](#tl/1) Returns the tail of a list. Raises [`ArgumentError`](argumenterror) if the list is empty. [trunc(number)](#trunc/1) Returns the integer part of `number`. [tuple\_size(tuple)](#tuple_size/1) Returns the size of a tuple. Functions ---------- [!value](#!/1) Boolean not. [left && right](#&&/2) Provides a short-circuit operator that evaluates and returns the second expression only if the first one evaluates to to a truthy value (neither `false` nor `nil`). Returns the first expression otherwise. [left ++ right](#++/2) Concatenates a proper list and a term, returning a list. [left -- right](#--/2) Removes the first occurrence of an element on the left list for each element on the right. [first..last](#../2) Returns a range with the specified `first` and `last` integers. [left <> right](#%3C%3E/2) Concatenates two binaries. [left =~ right](#=~/2) Matches the term on the `left` against the regular expression or string on the `right`. [@expr](#@/1) Reads and writes attributes of the current module. [alias!(alias)](#alias!/1) When used inside quoting, marks that the given alias should not be hygienized. This means the alias will be expanded when the macro is expanded. [apply(fun, args)](#apply/2) Invokes the given anonymous function `fun` with the list of arguments `args`. [apply(module, function\_name, args)](#apply/3) Invokes the given function from `module` with the list of arguments `args`. [binding(context \\ nil)](#binding/1) Returns the binding for the given context as a keyword list. [def(call, expr \\ nil)](#def/2) Defines a function with the given name and body. [defdelegate(funs, opts)](#defdelegate/2) Defines a function that delegates to another module. [defexception(fields)](#defexception/1) Defines an exception. [defguard(guard)](#defguard/1) Generates a macro suitable for use in guard expressions. [defguardp(guard)](#defguardp/1) Generates a private macro suitable for use in guard expressions. [defimpl(name, opts, do\_block \\ [])](#defimpl/3) Defines an implementation for the given protocol. [defmacro(call, expr \\ nil)](#defmacro/2) Defines a macro with the given name and body. [defmacrop(call, expr \\ nil)](#defmacrop/2) Defines a private macro with the given name and body. [defmodule(alias, do\_block)](#defmodule/2) Defines a module given by name with the given contents. [defoverridable(keywords\_or\_behaviour)](#defoverridable/1) Makes the given functions in the current module overridable. [defp(call, expr \\ nil)](#defp/2) Defines a private function with the given name and body. [defprotocol(name, do\_block)](#defprotocol/2) Defines a protocol. [defstruct(fields)](#defstruct/1) Defines a struct. [destructure(left, right)](#destructure/2) Destructures two lists, assigning each term in the right one to the matching term in the left one. [exit(reason)](#exit/1) Stops the execution of the calling process with the given reason. [function\_exported?(module, function, arity)](#function_exported?/3) Returns `true` if `module` is loaded and contains a public `function` with the given `arity`, otherwise `false`. [get\_and\_update\_in(path, fun)](#get_and_update_in/2) Gets a value and updates a nested data structure via the given `path`. [get\_and\_update\_in(data, keys, fun)](#get_and_update_in/3) Gets a value and updates a nested structure. [get\_in(data, keys)](#get_in/2) Gets a value from a nested structure. [if(condition, clauses)](#if/2) Provides an [`if/2`](#if/2) macro. [inspect(term, opts \\ [])](#inspect/2) Inspects the given argument according to the [`Inspect`](inspect) protocol. The second argument is a keyword list with options to control inspection. [macro\_exported?(module, macro, arity)](#macro_exported?/3) Returns `true` if `module` is loaded and contains a public `macro` with the given `arity`, otherwise `false`. [make\_ref()](#make_ref/0) Returns an almost unique reference. [match?(pattern, expr)](#match?/2) A convenience macro that checks if the right side (an expression) matches the left side (a pattern). [max(first, second)](#max/2) Returns the biggest of the two given terms according to Erlang's term ordering. [min(first, second)](#min/2) Returns the smallest of the two given terms according to Erlang's term ordering. [pop\_in(path)](#pop_in/1) Pops a key from the nested structure via the given `path`. [pop\_in(data, keys)](#pop_in/2) Pops a key from the given nested structure. [put\_elem(tuple, index, value)](#put_elem/3) Puts `value` at the given zero-based `index` in `tuple`. [put\_in(path, value)](#put_in/2) Puts a value in a nested structure via the given `path`. [put\_in(data, keys, value)](#put_in/3) Puts a value in a nested structure. [raise(message)](#raise/1) Raises an exception. [raise(exception, attributes)](#raise/2) Raises an exception. [reraise(message, stacktrace)](#reraise/2) Raises an exception preserving a previous stacktrace. [reraise(exception, attributes, stacktrace)](#reraise/3) Raises an exception preserving a previous stacktrace. [send(dest, message)](#send/2) Sends a message to the given `dest` and returns the message. [sigil\_C(term, modifiers)](#sigil_C/2) Handles the sigil `~C` for charlists. [sigil\_D(date\_string, modifiers)](#sigil_D/2) Handles the sigil `~D` for dates. [sigil\_N(naive\_datetime\_string, modifiers)](#sigil_N/2) Handles the sigil `~N` for naive date times. [sigil\_R(term, modifiers)](#sigil_R/2) Handles the sigil `~R` for regular expressions. [sigil\_S(term, modifiers)](#sigil_S/2) Handles the sigil `~S` for strings. [sigil\_T(time\_string, modifiers)](#sigil_T/2) Handles the sigil `~T` for times. [sigil\_U(datetime\_string, modifiers)](#sigil_U/2) Handles the sigil `~U` to create a UTC [`DateTime`](datetime). [sigil\_W(term, modifiers)](#sigil_W/2) Handles the sigil `~W` for list of words. [sigil\_c(term, modifiers)](#sigil_c/2) Handles the sigil `~c` for charlists. [sigil\_r(term, modifiers)](#sigil_r/2) Handles the sigil `~r` for regular expressions. [sigil\_s(term, modifiers)](#sigil_s/2) Handles the sigil `~s` for strings. [sigil\_w(term, modifiers)](#sigil_w/2) Handles the sigil `~w` for list of words. [spawn(fun)](#spawn/1) Spawns the given function and returns its PID. [spawn(module, fun, args)](#spawn/3) Spawns the given function `fun` from the given `module` passing it the given `args` and returns its PID. [spawn\_link(fun)](#spawn_link/1) Spawns the given function, links it to the current process, and returns its PID. [spawn\_link(module, fun, args)](#spawn_link/3) Spawns the given function `fun` from the given `module` passing it the given `args`, links it to the current process, and returns its PID. [spawn\_monitor(fun)](#spawn_monitor/1) Spawns the given function, monitors it and returns its PID and monitoring reference. [spawn\_monitor(module, fun, args)](#spawn_monitor/3) Spawns the given module and function passing the given args, monitors it and returns its PID and monitoring reference. [struct(struct, fields \\ [])](#struct/2) Creates and updates structs. [struct!(struct, fields \\ [])](#struct!/2) Similar to [`struct/2`](#struct/2) but checks for key validity. [throw(term)](#throw/1) A non-local return from a function. [to\_charlist(term)](#to_charlist/1) Converts the given term to a charlist according to the [`List.Chars`](list.chars) protocol. [to\_string(term)](#to_string/1) Converts the argument to a string according to the [`String.Chars`](string.chars) protocol. [unless(condition, clauses)](#unless/2) Provides an `unless` macro. [update\_in(path, fun)](#update_in/2) Updates a nested structure via the given `path`. [update\_in(data, keys, fun)](#update_in/3) Updates a key in a nested structure. [use(module, opts \\ [])](#use/2) Uses the given module in the current context. [var!(var, context \\ nil)](#var!/2) When used inside quoting, marks that the given variable should not be hygienized. [left |> right](#%7C%3E/2) Pipe operator. [left || right](#%7C%7C/2) Provides a short-circuit operator that evaluates and returns the second expression only if the first one does not evaluate to a truthy value (that is, it is either `nil` or `false`). Returns the first expression otherwise. Guards ======= ### left != right #### Specs ``` term() != term() :: boolean() ``` Returns `true` if the two terms are not equal. This operator considers 1 and 1.0 to be equal. For match comparison, use [`!==/2`](#!==/2) instead. All terms in Elixir can be compared with each other. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> 1 != 2 true iex> 1 != 1.0 false ``` ### left !== right #### Specs ``` term() !== term() :: boolean() ``` Returns `true` if the two terms are not exactly equal. All terms in Elixir can be compared with each other. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> 1 !== 2 true iex> 1 !== 1.0 true ``` ### left \* right #### Specs ``` integer() * integer() :: integer() ``` ``` float() * float() :: float() ``` ``` integer() * float() :: float() ``` ``` float() * integer() :: float() ``` Arithmetic multiplication. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> 1 * 2 2 ``` ### +value #### Specs ``` +value :: value when value: number() ``` Arithmetic unary plus. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> +1 1 ``` ### left + right #### Specs ``` integer() + integer() :: integer() ``` ``` float() + float() :: float() ``` ``` integer() + float() :: float() ``` ``` float() + integer() :: float() ``` Arithmetic addition. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> 1 + 2 3 ``` ### -value #### Specs ``` -0 :: 0 ``` ``` -pos_integer() :: neg_integer() ``` ``` -neg_integer() :: pos_integer() ``` ``` -float() :: float() ``` Arithmetic unary minus. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> -2 -2 ``` ### left - right #### Specs ``` integer() - integer() :: integer() ``` ``` float() - float() :: float() ``` ``` integer() - float() :: float() ``` ``` float() - integer() :: float() ``` Arithmetic subtraction. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> 1 - 2 -1 ``` ### left / right #### Specs ``` number() / number() :: float() ``` Arithmetic division. The result is always a float. Use [`div/2`](#div/2) and [`rem/2`](#rem/2) if you want an integer division or the remainder. Raises [`ArithmeticError`](arithmeticerror) if `right` is 0 or 0.0. Allowed in guard tests. Inlined by the compiler. #### Examples ``` 1 / 2 #=> 0.5 -3.0 / 2.0 #=> -1.5 5 / 1 #=> 5.0 7 / 0 #=> ** (ArithmeticError) bad argument in arithmetic expression ``` ### left < right #### Specs ``` term() < term() :: boolean() ``` Returns `true` if left is less than right. All terms in Elixir can be compared with each other. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> 1 < 2 true ``` ### left <= right #### Specs ``` term() <= term() :: boolean() ``` Returns `true` if left is less than or equal to right. All terms in Elixir can be compared with each other. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> 1 <= 2 true ``` ### left == right #### Specs ``` term() == term() :: boolean() ``` Returns `true` if the two terms are equal. This operator considers 1 and 1.0 to be equal. For stricter semantics, use [`===/2`](#===/2) instead. All terms in Elixir can be compared with each other. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> 1 == 2 false iex> 1 == 1.0 true ``` ### left === right #### Specs ``` term() === term() :: boolean() ``` Returns `true` if the two terms are exactly equal. The terms are only considered to be exactly equal if they have the same value and are of the same type. For example, `1 == 1.0` returns `true`, but since they are of different types, `1 === 1.0` returns `false`. All terms in Elixir can be compared with each other. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> 1 === 2 false iex> 1 === 1.0 false ``` ### left > right #### Specs ``` term() > term() :: boolean() ``` Returns `true` if left is more than right. All terms in Elixir can be compared with each other. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> 1 > 2 false ``` ### left >= right #### Specs ``` term() >= term() :: boolean() ``` Returns `true` if left is more than or equal to right. All terms in Elixir can be compared with each other. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> 1 >= 2 false ``` ### abs(number) #### Specs ``` abs(number()) :: number() ``` Returns an integer or float which is the arithmetical absolute value of `number`. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> abs(-3.33) 3.33 iex> abs(-3) 3 ``` ### left and right Boolean and. If `left` is `false`, returns `false`; otherwise returns `right`. Requires only the `left` operand to be a boolean since it short-circuits. If the `left` operand is not a boolean, an [`ArgumentError`](argumenterror) exception is raised. Allowed in guard tests. #### Examples ``` iex> true and false false iex> true and "yay!" "yay!" ``` ### binary\_part(binary, start, length) #### Specs ``` binary_part(binary(), non_neg_integer(), integer()) :: binary() ``` Extracts the part of the binary starting at `start` with length `length`. Binaries are zero-indexed. If `start` or `length` reference in any way outside the binary, an [`ArgumentError`](argumenterror) exception is raised. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> binary_part("foo", 1, 2) "oo" ``` A negative `length` can be used to extract bytes that come *before* the byte at `start`: ``` iex> binary_part("Hello", 5, -3) "llo" ``` ### bit\_size(bitstring) #### Specs ``` bit_size(bitstring()) :: non_neg_integer() ``` Returns an integer which is the size in bits of `bitstring`. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> bit_size(<<433::16, 3::3>>) 19 iex> bit_size(<<1, 2, 3>>) 24 ``` ### byte\_size(bitstring) #### Specs ``` byte_size(bitstring()) :: non_neg_integer() ``` Returns the number of bytes needed to contain `bitstring`. That is, if the number of bits in `bitstring` is not divisible by 8, the resulting number of bytes will be rounded up (by excess). This operation happens in constant time. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> byte_size(<<433::16, 3::3>>) 3 iex> byte_size(<<1, 2, 3>>) 3 ``` ### ceil(number) #### Specs ``` ceil(number()) :: integer() ``` Returns the smallest integer greater than or equal to `number`. If you want to perform ceil operation on other decimal places, use [`Float.ceil/2`](float#ceil/2) instead. Allowed in guard tests. Inlined by the compiler. ### div(dividend, divisor) #### Specs ``` div(integer(), neg_integer() | pos_integer()) :: integer() ``` Performs an integer division. Raises an [`ArithmeticError`](arithmeticerror) exception if one of the arguments is not an integer, or when the `divisor` is `0`. [`div/2`](#div/2) performs *truncated* integer division. This means that the result is always rounded towards zero. If you want to perform floored integer division (rounding towards negative infinity), use [`Integer.floor_div/2`](integer#floor_div/2) instead. Allowed in guard tests. Inlined by the compiler. #### Examples ``` div(5, 2) #=> 2 div(6, -4) #=> -1 div(-99, 2) #=> -49 div(100, 0) #=> ** (ArithmeticError) bad argument in arithmetic expression ``` ### elem(tuple, index) #### Specs ``` elem(tuple(), non_neg_integer()) :: term() ``` Gets the element at the zero-based `index` in `tuple`. It raises [`ArgumentError`](argumenterror) when index is negative or it is out of range of the tuple elements. Allowed in guard tests. Inlined by the compiler. #### Examples ``` tuple = {:foo, :bar, 3} elem(tuple, 1) #=> :bar elem({}, 0) #=> ** (ArgumentError) argument error elem({:foo, :bar}, 2) #=> ** (ArgumentError) argument error ``` ### floor(number) #### Specs ``` floor(number()) :: integer() ``` Returns the largest integer smaller than or equal to `number`. If you want to perform floor operation on other decimal places, use [`Float.floor/2`](float#floor/2) instead. Allowed in guard tests. Inlined by the compiler. ### hd(list) #### Specs ``` hd(nonempty_maybe_improper_list(elem, any())) :: elem when elem: term() ``` Returns the head of a list. Raises [`ArgumentError`](argumenterror) if the list is empty. It works with improper lists. Allowed in guard tests. Inlined by the compiler. #### Examples ``` hd([1, 2, 3, 4]) #=> 1 hd([]) #=> ** (ArgumentError) argument error hd([1 | 2]) #=> 1 ``` ### left in right Checks if the element on the left-hand side is a member of the collection on the right-hand side. #### Examples ``` iex> x = 1 iex> x in [1, 2, 3] true ``` This operator (which is a macro) simply translates to a call to [`Enum.member?/2`](enum#member?/2). The example above would translate to: ``` Enum.member?([1, 2, 3], x) ``` Elixir also supports `left not in right`, which evaluates to `not(left in right)`: ``` iex> x = 1 iex> x not in [1, 2, 3] false ``` #### Guards The [`in/2`](#in/2) operator (as well as `not in`) can be used in guard clauses as long as the right-hand side is a range or a list. In such cases, Elixir will expand the operator to a valid guard expression. For example: ``` when x in [1, 2, 3] ``` translates to: ``` when x === 1 or x === 2 or x === 3 ``` When using ranges: ``` when x in 1..3 ``` translates to: ``` when is_integer(x) and x >= 1 and x <= 3 ``` Note that only integers can be considered inside a range by `in`. ### AST considerations `left not in right` is parsed by the compiler into the AST: ``` {:not, _, [{:in, _, [left, right]}]} ``` This is the same AST as `not(left in right)`. Additionally, [`Macro.to_string/2`](macro#to_string/2) will translate all occurrences of this AST to `left not in right`. ### is\_atom(term) #### Specs ``` is_atom(term()) :: boolean() ``` Returns `true` if `term` is an atom; otherwise returns `false`. Allowed in guard tests. Inlined by the compiler. ### is\_binary(term) #### Specs ``` is_binary(term()) :: boolean() ``` Returns `true` if `term` is a binary; otherwise returns `false`. A binary always contains a complete number of bytes. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> is_binary("foo") true iex> is_binary(<<1::3>>) false ``` ### is\_bitstring(term) #### Specs ``` is_bitstring(term()) :: boolean() ``` Returns `true` if `term` is a bitstring (including a binary); otherwise returns `false`. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> is_bitstring("foo") true iex> is_bitstring(<<1::3>>) true ``` ### is\_boolean(term) #### Specs ``` is_boolean(term()) :: boolean() ``` Returns `true` if `term` is either the atom `true` or the atom `false` (i.e., a boolean); otherwise returns `false`. Allowed in guard tests. Inlined by the compiler. ### is\_float(term) #### Specs ``` is_float(term()) :: boolean() ``` Returns `true` if `term` is a floating-point number; otherwise returns `false`. Allowed in guard tests. Inlined by the compiler. ### is\_function(term) #### Specs ``` is_function(term()) :: boolean() ``` Returns `true` if `term` is a function; otherwise returns `false`. Allowed in guard tests. Inlined by the compiler. ### is\_function(term, arity) #### Specs ``` is_function(term(), non_neg_integer()) :: boolean() ``` Returns `true` if `term` is a function that can be applied with `arity` number of arguments; otherwise returns `false`. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> is_function(fn x -> x * 2 end, 1) true iex> is_function(fn x -> x * 2 end, 2) false ``` ### is\_integer(term) #### Specs ``` is_integer(term()) :: boolean() ``` Returns `true` if `term` is an integer; otherwise returns `false`. Allowed in guard tests. Inlined by the compiler. ### is\_list(term) #### Specs ``` is_list(term()) :: boolean() ``` Returns `true` if `term` is a list with zero or more elements; otherwise returns `false`. Allowed in guard tests. Inlined by the compiler. ### is\_map(term) #### Specs ``` is_map(term()) :: boolean() ``` Returns `true` if `term` is a map; otherwise returns `false`. Allowed in guard tests. Inlined by the compiler. ### is\_nil(term) Returns `true` if `term` is `nil`, `false` otherwise. Allowed in guard clauses. #### Examples ``` iex> is_nil(1) false iex> is_nil(nil) true ``` ### is\_number(term) #### Specs ``` is_number(term()) :: boolean() ``` Returns `true` if `term` is either an integer or a floating-point number; otherwise returns `false`. Allowed in guard tests. Inlined by the compiler. ### is\_pid(term) #### Specs ``` is_pid(term()) :: boolean() ``` Returns `true` if `term` is a PID (process identifier); otherwise returns `false`. Allowed in guard tests. Inlined by the compiler. ### is\_port(term) #### Specs ``` is_port(term()) :: boolean() ``` Returns `true` if `term` is a port identifier; otherwise returns `false`. Allowed in guard tests. Inlined by the compiler. ### is\_reference(term) #### Specs ``` is_reference(term()) :: boolean() ``` Returns `true` if `term` is a reference; otherwise returns `false`. Allowed in guard tests. Inlined by the compiler. ### is\_tuple(term) #### Specs ``` is_tuple(term()) :: boolean() ``` Returns `true` if `term` is a tuple; otherwise returns `false`. Allowed in guard tests. Inlined by the compiler. ### length(list) #### Specs ``` length(list()) :: non_neg_integer() ``` Returns the length of `list`. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> length([1, 2, 3, 4, 5, 6, 7, 8, 9]) 9 ``` ### map\_size(map) #### Specs ``` map_size(map()) :: non_neg_integer() ``` Returns the size of a map. The size of a map is the number of key-value pairs that the map contains. This operation happens in constant time. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> map_size(%{a: "foo", b: "bar"}) 2 ``` ### node() #### Specs ``` node() :: node() ``` Returns an atom representing the name of the local node. If the node is not alive, `:nonode@nohost` is returned instead. Allowed in guard tests. Inlined by the compiler. ### node(arg) #### Specs ``` node(pid() | reference() | port()) :: node() ``` Returns the node where the given argument is located. The argument can be a PID, a reference, or a port. If the local node is not alive, `:nonode@nohost` is returned. Allowed in guard tests. Inlined by the compiler. ### not(value) #### Specs ``` not true :: false ``` ``` not false :: true ``` Boolean not. `arg` must be a boolean; if it's not, an [`ArgumentError`](argumenterror) exception is raised. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> not false true ``` ### left or right Boolean or. If `left` is `true`, returns `true`; otherwise returns `right`. Requires only the `left` operand to be a boolean since it short-circuits. If the `left` operand is not a boolean, an [`ArgumentError`](argumenterror) exception is raised. Allowed in guard tests. #### Examples ``` iex> true or false true iex> false or 42 42 ``` ### rem(dividend, divisor) #### Specs ``` rem(integer(), neg_integer() | pos_integer()) :: integer() ``` Computes the remainder of an integer division. [`rem/2`](#rem/2) uses truncated division, which means that the result will always have the sign of the `dividend`. Raises an [`ArithmeticError`](arithmeticerror) exception if one of the arguments is not an integer, or when the `divisor` is `0`. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> rem(5, 2) 1 iex> rem(6, -4) 2 ``` ### round(number) #### Specs ``` round(float()) :: integer() ``` ``` round(value) :: value when value: integer() ``` Rounds a number to the nearest integer. If the number is equidistant to the two nearest integers, rounds away from zero. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> round(5.6) 6 iex> round(5.2) 5 iex> round(-9.9) -10 iex> round(-9) -9 iex> round(2.5) 3 iex> round(-2.5) -3 ``` ### self() #### Specs ``` self() :: pid() ``` Returns the PID (process identifier) of the calling process. Allowed in guard clauses. Inlined by the compiler. ### tl(list) #### Specs ``` tl(nonempty_maybe_improper_list(elem, tail)) :: maybe_improper_list(elem, tail) | tail when elem: term(), tail: term() ``` Returns the tail of a list. Raises [`ArgumentError`](argumenterror) if the list is empty. It works with improper lists. Allowed in guard tests. Inlined by the compiler. #### Examples ``` tl([1, 2, 3, :go]) #=> [2, 3, :go] tl([]) #=> ** (ArgumentError) argument error tl([:one]) #=> [] tl([:a, :b | :c]) #=> [:b | :c] tl([:a | %{b: 1}]) #=> %{b: 1} ``` ### trunc(number) #### Specs ``` trunc(value) :: value when value: integer() ``` ``` trunc(float()) :: integer() ``` Returns the integer part of `number`. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> trunc(5.4) 5 iex> trunc(-5.99) -5 iex> trunc(-5) -5 ``` ### tuple\_size(tuple) #### Specs ``` tuple_size(tuple()) :: non_neg_integer() ``` Returns the size of a tuple. This operation happens in constant time. Allowed in guard tests. Inlined by the compiler. #### Examples ``` iex> tuple_size({:a, :b, :c}) 3 ``` Functions ========== ### !value Boolean not. Receives any argument (not just booleans) and returns `true` if the argument is `false` or `nil`; returns `false` otherwise. Not allowed in guard clauses. #### Examples ``` iex> !Enum.empty?([]) false iex> !List.first([]) true ``` ### left && right Provides a short-circuit operator that evaluates and returns the second expression only if the first one evaluates to to a truthy value (neither `false` nor `nil`). Returns the first expression otherwise. Not allowed in guard clauses. #### Examples ``` iex> Enum.empty?([]) && Enum.empty?([]) true iex> List.first([]) && true nil iex> Enum.empty?([]) && List.first([1]) 1 iex> false && throw(:bad) false ``` Note that, unlike [`and/2`](#and/2), this operator accepts any expression as the first argument, not only booleans. ### left ++ right #### Specs ``` list() ++ term() :: maybe_improper_list() ``` Concatenates a proper list and a term, returning a list. The complexity of `a ++ b` is proportional to `length(a)`, so avoid repeatedly appending to lists of arbitrary length, e.g. `list ++ [element]`. Instead, consider prepending via `[element | rest]` and then reversing. If the `right` operand is not a proper list, it returns an improper list. If the `left` operand is not a proper list, it raises [`ArgumentError`](argumenterror). Inlined by the compiler. #### Examples ``` iex> [1] ++ [2, 3] [1, 2, 3] iex> 'foo' ++ 'bar' 'foobar' # returns an improper list iex> [1] ++ 2 [1 | 2] # returns a proper list iex> [1] ++ [2] [1, 2] # improper list on the right will return an improper list iex> [1] ++ [2 | 3] [1, 2 | 3] ``` ### left -- right #### Specs ``` list() -- list() :: list() ``` Removes the first occurrence of an element on the left list for each element on the right. The complexity of `a -- b` is proportional to `length(a) * length(b)`, meaning that it will be very slow if both `a` and `b` are long lists. In such cases, consider converting each list to a [`MapSet`](mapset) and using [`MapSet.difference/2`](mapset#difference/2). Inlined by the compiler. #### Examples ``` iex> [1, 2, 3] -- [1, 2] [3] iex> [1, 2, 3, 2, 1] -- [1, 2, 2] [3, 1] ``` ### first..last Returns a range with the specified `first` and `last` integers. If last is larger than first, the range will be increasing from first to last. If first is larger than last, the range will be decreasing from first to last. If first is equal to last, the range will contain one element, which is the number itself. #### Examples ``` iex> 0 in 1..3 false iex> 1 in 1..3 true iex> 2 in 1..3 true iex> 3 in 1..3 true ``` ### left <> right Concatenates two binaries. #### Examples ``` iex> "foo" <> "bar" "foobar" ``` The [`<>/2`](#%3C%3E/2) operator can also be used in pattern matching (and guard clauses) as long as the left argument is a literal binary: ``` iex> "foo" <> x = "foobar" iex> x "bar" ``` `x <> "bar" = "foobar"` would have resulted in a [`CompileError`](compileerror) exception. ### left =~ right #### Specs ``` String.t() =~ (String.t() | Regex.t()) :: boolean() ``` Matches the term on the `left` against the regular expression or string on the `right`. Returns `true` if `left` matches `right` (if it's a regular expression) or contains `right` (if it's a string). #### Examples ``` iex> "abcd" =~ ~r/c(d)/ true iex> "abcd" =~ ~r/e/ false iex> "abcd" =~ "bc" true iex> "abcd" =~ "ad" false iex> "abcd" =~ "" true ``` ### @expr Reads and writes attributes of the current module. The canonical example for attributes is annotating that a module implements an OTP behaviour, such as [`GenServer`](genserver): ``` defmodule MyServer do @behaviour GenServer # ... callbacks ... end ``` By default Elixir supports all the module attributes supported by Erlang, but custom attributes can be used as well: ``` defmodule MyServer do @my_data 13 IO.inspect(@my_data) #=> 13 end ``` Unlike Erlang, such attributes are not stored in the module by default since it is common in Elixir to use custom attributes to store temporary data that will be available at compile-time. Custom attributes may be configured to behave closer to Erlang by using [`Module.register_attribute/3`](module#register_attribute/3). Finally, notice that attributes can also be read inside functions: ``` defmodule MyServer do @my_data 11 def first_data, do: @my_data @my_data 13 def second_data, do: @my_data end MyServer.first_data() #=> 11 MyServer.second_data() #=> 13 ``` It is important to note that reading an attribute takes a snapshot of its current value. In other words, the value is read at compilation time and not at runtime. Check the [`Module`](module) module for other functions to manipulate module attributes. ### alias!(alias) When used inside quoting, marks that the given alias should not be hygienized. This means the alias will be expanded when the macro is expanded. Check [`Kernel.SpecialForms.quote/2`](kernel.specialforms#quote/2) for more information. ### apply(fun, args) #### Specs ``` apply((... -> any()), [any()]) :: any() ``` Invokes the given anonymous function `fun` with the list of arguments `args`. Inlined by the compiler. #### Examples ``` iex> apply(fn x -> x * 2 end, [2]) 4 ``` ### apply(module, function\_name, args) #### Specs ``` apply(module(), function_name :: atom(), [any()]) :: any() ``` Invokes the given function from `module` with the list of arguments `args`. [`apply/3`](#apply/3) is used to invoke functions where the module, function name or arguments are defined dynamically at runtime. For this reason, you can't invoke macros using [`apply/3`](#apply/3), only functions. Inlined by the compiler. #### Examples ``` iex> apply(Enum, :reverse, [[1, 2, 3]]) [3, 2, 1] ``` ### binding(context \\ nil) Returns the binding for the given context as a keyword list. In the returned result, keys are variable names and values are the corresponding variable values. If the given `context` is `nil` (by default it is), the binding for the current context is returned. #### Examples ``` iex> x = 1 iex> binding() [x: 1] iex> x = 2 iex> binding() [x: 2] iex> binding(:foo) [] iex> var!(x, :foo) = 1 1 iex> binding(:foo) [x: 1] ``` ### def(call, expr \\ nil) Defines a function with the given name and body. #### Examples ``` defmodule Foo do def bar, do: :baz end Foo.bar() #=> :baz ``` A function that expects arguments can be defined as follows: ``` defmodule Foo do def sum(a, b) do a + b end end ``` In the example above, a `sum/2` function is defined; this function receives two arguments and returns their sum. #### Default arguments `\\` is used to specify a default value for a parameter of a function. For example: ``` defmodule MyMath do def multiply_by(number, factor \\ 2) do number * factor end end MyMath.multiply_by(4, 3) #=> 12 MyMath.multiply_by(4) #=> 8 ``` The compiler translates this into multiple functions with different arities, here `MyMath.multiply_by/1` and `MyMath.multiply_by/2`, that represent cases when arguments for parameters with default values are passed or not passed. When defining a function with default arguments as well as multiple explicitly declared clauses, you must write a function head that declares the defaults. For example: ``` defmodule MyString do def join(string1, string2 \\ nil, separator \\ " ") def join(string1, nil, _separator) do string1 end def join(string1, string2, separator) do string1 <> separator <> string2 end end ``` Note that `\\` can't be used with anonymous functions because they can only have a sole arity. #### Function and variable names Function and variable names have the following syntax: A *lowercase ASCII letter* or an *underscore*, followed by any number of *lowercase or uppercase ASCII letters*, *numbers*, or *underscores*. Optionally they can end in either an *exclamation mark* or a *question mark*. For variables, any identifier starting with an underscore should indicate an unused variable. For example: ``` def foo(bar) do [] end #=> warning: variable bar is unused def foo(_bar) do [] end #=> no warning def foo(_bar) do _bar end #=> warning: the underscored variable "_bar" is used after being set ``` #### `rescue`/`catch`/`after`/`else` Function bodies support `rescue`, `catch`, `after`, and `else` as [`Kernel.SpecialForms.try/1`](kernel.specialforms#try/1) does. For example, the following two functions are equivalent: ``` def format(value) do try do format!(value) catch :exit, reason -> {:error, reason} end end def format(value) do format!(value) catch :exit, reason -> {:error, reason} end ``` ### defdelegate(funs, opts) Defines a function that delegates to another module. Functions defined with [`defdelegate/2`](#defdelegate/2) are public and can be invoked from outside the module they're defined in, as if they were defined using [`def/2`](#def/2). Therefore, [`defdelegate/2`](#defdelegate/2) is about extending the current module's public API. If what you want is to invoke a function defined in another module without using its full module name, then use [`alias/2`](kernel.specialforms#alias/2) to shorten the module name or use [`import/2`](kernel.specialforms#import/2) to be able to invoke the function without the module name altogether. Delegation only works with functions; delegating macros is not supported. Check [`def/2`](#def/2) for rules on naming and default arguments. #### Options * `:to` - the module to dispatch to. * `:as` - the function to call on the target given in `:to`. This parameter is optional and defaults to the name being delegated (`funs`). #### Examples ``` defmodule MyList do defdelegate reverse(list), to: Enum defdelegate other_reverse(list), to: Enum, as: :reverse end MyList.reverse([1, 2, 3]) #=> [3, 2, 1] MyList.other_reverse([1, 2, 3]) #=> [3, 2, 1] ``` ### defexception(fields) Defines an exception. Exceptions are structs backed by a module that implements the [`Exception`](exception) behaviour. The [`Exception`](exception) behaviour requires two functions to be implemented: * [`exception/1`](exception#c:exception/1) - receives the arguments given to [`raise/2`](#raise/2) and returns the exception struct. The default implementation accepts either a set of keyword arguments that is merged into the struct or a string to be used as the exception's message. * [`message/1`](exception#c:message/1) - receives the exception struct and must return its message. Most commonly exceptions have a message field which by default is accessed by this function. However, if an exception does not have a message field, this function must be explicitly implemented. Since exceptions are structs, the API supported by [`defstruct/1`](#defstruct/1) is also available in [`defexception/1`](#defexception/1). #### Raising exceptions The most common way to raise an exception is via [`raise/2`](#raise/2): ``` defmodule MyAppError do defexception [:message] end value = [:hello] raise MyAppError, message: "did not get what was expected, got: #{inspect(value)}" ``` In many cases it is more convenient to pass the expected value to [`raise/2`](#raise/2) and generate the message in the [`Exception.exception/1`](exception#c:exception/1) callback: ``` defmodule MyAppError do defexception [:message] @impl true def exception(value) do msg = "did not get what was expected, got: #{inspect(value)}" %MyAppError{message: msg} end end raise MyAppError, value ``` The example above shows the preferred strategy for customizing exception messages. ### defguard(guard) #### Specs ``` defguard(Macro.t()) :: Macro.t() ``` Generates a macro suitable for use in guard expressions. It raises at compile time if the definition uses expressions that aren't allowed in guards, and otherwise creates a macro that can be used both inside or outside guards. Note the convention in Elixir is to name functions/macros allowed in guards with the `is_` prefix, such as [`is_list/1`](#is_list/1). If, however, the function/macro returns a boolean and is not allowed in guards, it should have no prefix and end with a question mark, such as [`Keyword.keyword?/1`](keyword#keyword?/1). #### Example ``` defmodule Integer.Guards do defguard is_even(value) when is_integer(value) and rem(value, 2) == 0 end defmodule Collatz do @moduledoc "Tools for working with the Collatz sequence." import Integer.Guards @doc "Determines the number of steps `n` takes to reach `1`." # If this function never converges, please let me know what `n` you used. def converge(n) when n > 0, do: step(n, 0) defp step(1, step_count) do step_count end defp step(n, step_count) when is_even(n) do step(div(n, 2), step_count + 1) end defp step(n, step_count) do step(3 * n + 1, step_count + 1) end end ``` ### defguardp(guard) #### Specs ``` defguardp(Macro.t()) :: Macro.t() ``` Generates a private macro suitable for use in guard expressions. It raises at compile time if the definition uses expressions that aren't allowed in guards, and otherwise creates a private macro that can be used both inside or outside guards in the current module. Similar to [`defmacrop/2`](#defmacrop/2), [`defguardp/1`](#defguardp/1) must be defined before its use in the current module. ### defimpl(name, opts, do\_block \\ []) Defines an implementation for the given protocol. See the [`Protocol`](protocol) module for more information. ### defmacro(call, expr \\ nil) Defines a macro with the given name and body. Macros must be defined before its usage. Check [`def/2`](#def/2) for rules on naming and default arguments. #### Examples ``` defmodule MyLogic do defmacro unless(expr, opts) do quote do if !unquote(expr), unquote(opts) end end end require MyLogic MyLogic.unless false do IO.puts("It works") end ``` ### defmacrop(call, expr \\ nil) Defines a private macro with the given name and body. Private macros are only accessible from the same module in which they are defined. Private macros must be defined before its usage. Check [`defmacro/2`](#defmacro/2) for more information, and check [`def/2`](#def/2) for rules on naming and default arguments. ### defmodule(alias, do\_block) Defines a module given by name with the given contents. This macro defines a module with the given `alias` as its name and with the given contents. It returns a tuple with four elements: * `:module` * the module name * the binary contents of the module * the result of evaluating the contents block #### Examples ``` iex> defmodule Foo do ...> def bar, do: :baz ...> end iex> Foo.bar() :baz ``` #### Nesting Nesting a module inside another module affects the name of the nested module: ``` defmodule Foo do defmodule Bar do end end ``` In the example above, two modules - `Foo` and `Foo.Bar` - are created. When nesting, Elixir automatically creates an alias to the inner module, allowing the second module `Foo.Bar` to be accessed as `Bar` in the same lexical scope where it's defined (the `Foo` module). This only happens if the nested module is defined via an alias. If the `Foo.Bar` module is moved somewhere else, the references to `Bar` in the `Foo` module need to be updated to the fully-qualified name (`Foo.Bar`) or an alias has to be explicitly set in the `Foo` module with the help of [`Kernel.SpecialForms.alias/2`](kernel.specialforms#alias/2). ``` defmodule Foo.Bar do # code end defmodule Foo do alias Foo.Bar # code here can refer to "Foo.Bar" as just "Bar" end ``` #### Dynamic names Elixir module names can be dynamically generated. This is very useful when working with macros. For instance, one could write: ``` defmodule String.to_atom("Foo#{1}") do # contents ... end ``` Elixir will accept any module name as long as the expression passed as the first argument to [`defmodule/2`](#defmodule/2) evaluates to an atom. Note that, when a dynamic name is used, Elixir won't nest the name under the current module nor automatically set up an alias. #### Reserved module names If you attempt to define a module that already exists, you will get a warning saying that a module has been redefined. There are some modules that Elixir does not currently implement but it may be implement in the future. Those modules are reserved and defining them will result in a compilation error: ``` defmodule Any do # code end #=> ** (CompileError) iex:1: module Any is reserved and cannot be defined ``` Elixir reserves the following module names: `Elixir`, `Any`, `BitString`, `PID`, and `Reference`. ### defoverridable(keywords\_or\_behaviour) Makes the given functions in the current module overridable. An overridable function is lazily defined, allowing a developer to override it. Macros cannot be overridden as functions and vice-versa. #### Example ``` defmodule DefaultMod do defmacro __using__(_opts) do quote do def test(x, y) do x + y end defoverridable test: 2 end end end defmodule InheritMod do use DefaultMod def test(x, y) do x * y + super(x, y) end end ``` As seen as in the example above, `super` can be used to call the default implementation. If `@behaviour` has been defined, `defoverridable` can also be called with a module as an argument. All implemented callbacks from the behaviour above the call to `defoverridable` will be marked as overridable. #### Example ``` defmodule Behaviour do @callback foo :: any end defmodule DefaultMod do defmacro __using__(_opts) do quote do @behaviour Behaviour def foo do "Override me" end defoverridable Behaviour end end end defmodule InheritMod do use DefaultMod def foo do "Overridden" end end ``` ### defp(call, expr \\ nil) Defines a private function with the given name and body. Private functions are only accessible from within the module in which they are defined. Trying to access a private function from outside the module it's defined in results in an [`UndefinedFunctionError`](undefinedfunctionerror) exception. Check [`def/2`](#def/2) for more information. #### Examples ``` defmodule Foo do def bar do sum(1, 2) end defp sum(a, b), do: a + b end Foo.bar() #=> 3 Foo.sum(1, 2) #=> ** (UndefinedFunctionError) undefined function Foo.sum/2 ``` ### defprotocol(name, do\_block) Defines a protocol. See the [`Protocol`](protocol) module for more information. ### defstruct(fields) Defines a struct. A struct is a tagged map that allows developers to provide default values for keys, tags to be used in polymorphic dispatches and compile time assertions. To define a struct, a developer must define both `__struct__/0` and `__struct__/1` functions. [`defstruct/1`](#defstruct/1) is a convenience macro which defines such functions with some conveniences. For more information about structs, please check [`Kernel.SpecialForms.%/2`](kernel.specialforms#%25/2). #### Examples ``` defmodule User do defstruct name: nil, age: nil end ``` Struct fields are evaluated at compile-time, which allows them to be dynamic. In the example below, `10 + 11` is evaluated at compile-time and the age field is stored with value `21`: ``` defmodule User do defstruct name: nil, age: 10 + 11 end ``` The `fields` argument is usually a keyword list with field names as atom keys and default values as corresponding values. [`defstruct/1`](#defstruct/1) also supports a list of atoms as its argument: in that case, the atoms in the list will be used as the struct's field names and they will all default to `nil`. ``` defmodule Post do defstruct [:title, :content, :author] end ``` #### Deriving Although structs are maps, by default structs do not implement any of the protocols implemented for maps. For example, attempting to use a protocol with the `User` struct leads to an error: ``` john = %User{name: "John"} MyProtocol.call(john) ** (Protocol.UndefinedError) protocol MyProtocol not implemented for %User{...} ``` [`defstruct/1`](#defstruct/1), however, allows protocol implementations to be *derived*. This can be done by defining a `@derive` attribute as a list before invoking [`defstruct/1`](#defstruct/1): ``` defmodule User do @derive [MyProtocol] defstruct name: nil, age: 10 + 11 end MyProtocol.call(john) #=> works ``` For each protocol in the `@derive` list, Elixir will assert the protocol has been implemented for `Any`. If the `Any` implementation defines a `__deriving__/3` callback, the callback will be invoked and it should define the implementation module. Otherwise an implementation that simply points to the `Any` implementation is automatically derived. For more information on the `__deriving__/3` callback, see [`Protocol.derive/3`](protocol#derive/3). #### Enforcing keys When building a struct, Elixir will automatically guarantee all keys belongs to the struct: ``` %User{name: "john", unknown: :key} ** (KeyError) key :unknown not found in: %User{age: 21, name: nil} ``` Elixir also allows developers to enforce certain keys must always be given when building the struct: ``` defmodule User do @enforce_keys [:name] defstruct name: nil, age: 10 + 11 end ``` Now trying to build a struct without the name key will fail: ``` %User{age: 21} ** (ArgumentError) the following keys must also be given when building struct User: [:name] ``` Keep in mind `@enforce_keys` is a simple compile-time guarantee to aid developers when building structs. It is not enforced on updates and it does not provide any sort of value-validation. #### Types It is recommended to define types for structs. By convention such type is called `t`. To define a struct inside a type, the struct literal syntax is used: ``` defmodule User do defstruct name: "John", age: 25 @type t :: %__MODULE__{name: String.t(), age: non_neg_integer} end ``` It is recommended to only use the struct syntax when defining the struct's type. When referring to another struct it's better to use `User.t` instead of `%User{}`. The types of the struct fields that are not included in `%User{}` default to `term()` (see [`term/0`](typespecs#built-in-types)). Structs whose internal structure is private to the local module (pattern matching them or directly accessing their fields should not be allowed) should use the `@opaque` attribute. Structs whose internal structure is public should use `@type`. ### destructure(left, right) Destructures two lists, assigning each term in the right one to the matching term in the left one. Unlike pattern matching via `=`, if the sizes of the left and right lists don't match, destructuring simply stops instead of raising an error. #### Examples ``` iex> destructure([x, y, z], [1, 2, 3, 4, 5]) iex> {x, y, z} {1, 2, 3} ``` In the example above, even though the right list has more entries than the left one, destructuring works fine. If the right list is smaller, the remaining elements are simply set to `nil`: ``` iex> destructure([x, y, z], [1]) iex> {x, y, z} {1, nil, nil} ``` The left-hand side supports any expression you would use on the left-hand side of a match: ``` x = 1 destructure([^x, y, z], [1, 2, 3]) ``` The example above will only work if `x` matches the first value in the right list. Otherwise, it will raise a [`MatchError`](matcherror) (like the `=` operator would do). ### exit(reason) #### Specs ``` exit(term()) :: no_return() ``` Stops the execution of the calling process with the given reason. Since evaluating this function causes the process to terminate, it has no return value. Inlined by the compiler. #### Examples When a process reaches its end, by default it exits with reason `:normal`. You can also call [`exit/1`](#exit/1) explicitly if you want to terminate a process but not signal any failure: ``` exit(:normal) ``` In case something goes wrong, you can also use [`exit/1`](#exit/1) with a different reason: ``` exit(:seems_bad) ``` If the exit reason is not `:normal`, all the processes linked to the process that exited will crash (unless they are trapping exits). #### OTP exits Exits are used by the OTP to determine if a process exited abnormally or not. The following exits are considered "normal": * `exit(:normal)` * `exit(:shutdown)` * `exit({:shutdown, term})` Exiting with any other reason is considered abnormal and treated as a crash. This means the default supervisor behaviour kicks in, error reports are emitted, etc. This behaviour is relied on in many different places. For example, [`ExUnit`](https://hexdocs.pm/ex_unit/ExUnit.html) uses `exit(:shutdown)` when exiting the test process to signal linked processes, supervision trees and so on to politely shut down too. #### CLI exits Building on top of the exit signals mentioned above, if the process started by the command line exits with any of the three reasons above, its exit is considered normal and the Operating System process will exit with status 0. It is, however, possible to customize the operating system exit signal by invoking: ``` exit({:shutdown, integer}) ``` This will cause the operating system process to exit with the status given by `integer` while signaling all linked Erlang processes to politely shut down. Any other exit reason will cause the operating system process to exit with status `1` and linked Erlang processes to crash. ### function\_exported?(module, function, arity) #### Specs ``` function_exported?(module(), atom(), arity()) :: boolean() ``` Returns `true` if `module` is loaded and contains a public `function` with the given `arity`, otherwise `false`. Note that this function does not load the module in case it is not loaded. Check [`Code.ensure_loaded/1`](code#ensure_loaded/1) for more information. Inlined by the compiler. #### Examples ``` iex> function_exported?(Enum, :map, 2) true iex> function_exported?(Enum, :map, 10) false iex> function_exported?(List, :to_string, 1) true ``` ### get\_and\_update\_in(path, fun) Gets a value and updates a nested data structure via the given `path`. This is similar to [`get_and_update_in/3`](#get_and_update_in/3), except the path is extracted via a macro rather than passing a list. For example: ``` get_and_update_in(opts[:foo][:bar], &{&1, &1 + 1}) ``` Is equivalent to: ``` get_and_update_in(opts, [:foo, :bar], &{&1, &1 + 1}) ``` This also works with nested structs and the `struct.path.to.value` way to specify paths: ``` get_and_update_in(struct.foo.bar, &{&1, &1 + 1}) ``` Note that in order for this macro to work, the complete path must always be visible by this macro. See the Paths section below. #### Examples ``` iex> users = %{"john" => %{age: 27}, "meg" => %{age: 23}} iex> get_and_update_in(users["john"].age, &{&1, &1 + 1}) {27, %{"john" => %{age: 28}, "meg" => %{age: 23}}} ``` #### Paths A path may start with a variable, local or remote call, and must be followed by one or more: * `foo[bar]` - accesses the key `bar` in `foo`; in case `foo` is nil, `nil` is returned * `foo.bar` - accesses a map/struct field; in case the field is not present, an error is raised Here are some valid paths: ``` users["john"][:age] users["john"].age User.all()["john"].age all_users()["john"].age ``` Here are some invalid ones: ``` # Does a remote call after the initial value users["john"].do_something(arg1, arg2) # Does not access any key or field users ``` ### get\_and\_update\_in(data, keys, fun) #### Specs ``` get_and_update_in( structure :: Access.t(), keys, (term() -> {get_value, update_value} | :pop) ) :: {get_value, structure :: Access.t()} when keys: [any(), ...], update_value: term(), get_value: var ``` Gets a value and updates a nested structure. `data` is a nested structure (that is, a map, keyword list, or struct that implements the [`Access`](access) behaviour). The `fun` argument receives the value of `key` (or `nil` if `key` is not present) and must return one of the following values: * a two-element tuple `{get_value, new_value}`. In this case, `get_value` is the retrieved value which can possibly be operated on before being returned. `new_value` is the new value to be stored under `key`. * `:pop`, which implies that the current value under `key` should be removed from the structure and returned. This function uses the [`Access`](access) module to traverse the structures according to the given `keys`, unless the `key` is a function, which is detailed in a later section. #### Examples This function is useful when there is a need to retrieve the current value (or something calculated in function of the current value) and update it at the same time. For example, it could be used to read the current age of a user while increasing it by one in one pass: ``` iex> users = %{"john" => %{age: 27}, "meg" => %{age: 23}} iex> get_and_update_in(users, ["john", :age], &{&1, &1 + 1}) {27, %{"john" => %{age: 28}, "meg" => %{age: 23}}} ``` #### Functions as keys If a key is a function, the function will be invoked passing three arguments: * the operation (`:get_and_update`) * the data to be accessed * a function to be invoked next This means [`get_and_update_in/3`](#get_and_update_in/3) can be extended to provide custom lookups. The downside is that functions cannot be stored as keys in the accessed data structures. When one of the keys is a function, the function is invoked. In the example below, we use a function to get and increment all ages inside a list: ``` iex> users = [%{name: "john", age: 27}, %{name: "meg", age: 23}] iex> all = fn :get_and_update, data, next -> ...> data |> Enum.map(next) |> Enum.unzip() ...> end iex> get_and_update_in(users, [all, :age], &{&1, &1 + 1}) {[27, 23], [%{name: "john", age: 28}, %{name: "meg", age: 24}]} ``` If the previous value before invoking the function is `nil`, the function *will* receive `nil` as a value and must handle it accordingly (be it by failing or providing a sane default). The [`Access`](access) module ships with many convenience accessor functions, like the `all` anonymous function defined above. See [`Access.all/0`](access#all/0), [`Access.key/2`](access#key/2), and others as examples. ### get\_in(data, keys) #### Specs ``` get_in(Access.t(), [term(), ...]) :: term() ``` Gets a value from a nested structure. Uses the [`Access`](access) module to traverse the structures according to the given `keys`, unless the `key` is a function, which is detailed in a later section. #### Examples ``` iex> users = %{"john" => %{age: 27}, "meg" => %{age: 23}} iex> get_in(users, ["john", :age]) 27 ``` In case any of the entries in the middle returns `nil`, `nil` will be returned as per the [`Access`](access) module: ``` iex> users = %{"john" => %{age: 27}, "meg" => %{age: 23}} iex> get_in(users, ["unknown", :age]) nil ``` #### Functions as keys If a key is a function, the function will be invoked passing three arguments: * the operation (`:get`) * the data to be accessed * a function to be invoked next This means [`get_in/2`](#get_in/2) can be extended to provide custom lookups. The downside is that functions cannot be stored as keys in the accessed data structures. In the example below, we use a function to get all the maps inside a list: ``` iex> users = [%{name: "john", age: 27}, %{name: "meg", age: 23}] iex> all = fn :get, data, next -> Enum.map(data, next) end iex> get_in(users, [all, :age]) [27, 23] ``` If the previous value before invoking the function is `nil`, the function *will* receive `nil` as a value and must handle it accordingly. The [`Access`](access) module ships with many convenience accessor functions, like the `all` anonymous function defined above. See [`Access.all/0`](access#all/0), [`Access.key/2`](access#key/2), and others as examples. ### if(condition, clauses) Provides an [`if/2`](#if/2) macro. This macro expects the first argument to be a condition and the second argument to be a keyword list. #### One-liner examples ``` if(foo, do: bar) ``` In the example above, `bar` will be returned if `foo` evaluates to a truthy value (neither `false` nor `nil`). Otherwise, `nil` will be returned. An `else` option can be given to specify the opposite: ``` if(foo, do: bar, else: baz) ``` #### Blocks examples It's also possible to pass a block to the [`if/2`](#if/2) macro. The first example above would be translated to: ``` if foo do bar end ``` Note that `do/end` become delimiters. The second example would translate to: ``` if foo do bar else baz end ``` In order to compare more than two clauses, the [`cond/1`](kernel.specialforms#cond/1) macro has to be used. ### inspect(term, opts \\ []) #### Specs ``` inspect(Inspect.t(), keyword()) :: String.t() ``` Inspects the given argument according to the [`Inspect`](inspect) protocol. The second argument is a keyword list with options to control inspection. #### Options [`inspect/2`](#inspect/2) accepts a list of options that are internally translated to an [`Inspect.Opts`](inspect.opts) struct. Check the docs for [`Inspect.Opts`](inspect.opts) to see the supported options. #### Examples ``` iex> inspect(:foo) ":foo" iex> inspect([1, 2, 3, 4, 5], limit: 3) "[1, 2, 3, ...]" iex> inspect([1, 2, 3], pretty: true, width: 0) "[1,\n 2,\n 3]" iex> inspect("olá" <> <<0>>) "<<111, 108, 195, 161, 0>>" iex> inspect("olá" <> <<0>>, binaries: :as_strings) "\"olá\\0\"" iex> inspect("olá", binaries: :as_binaries) "<<111, 108, 195, 161>>" iex> inspect('bar') "'bar'" iex> inspect([0 | 'bar']) "[0, 98, 97, 114]" iex> inspect(100, base: :octal) "0o144" iex> inspect(100, base: :hex) "0x64" ``` Note that the [`Inspect`](inspect) protocol does not necessarily return a valid representation of an Elixir term. In such cases, the inspected result must start with `#`. For example, inspecting a function will return: ``` inspect(fn a, b -> a + b end) #=> #Function<...> ``` The [`Inspect`](inspect) protocol can be derived to hide certain fields from structs, so they don't show up in logs, inspects and similar. See the "Deriving" section of the documentation of the [`Inspect`](inspect) protocol for more information. ### macro\_exported?(module, macro, arity) #### Specs ``` macro_exported?(module(), atom(), arity()) :: boolean() ``` Returns `true` if `module` is loaded and contains a public `macro` with the given `arity`, otherwise `false`. Note that this function does not load the module in case it is not loaded. Check [`Code.ensure_loaded/1`](code#ensure_loaded/1) for more information. If `module` is an Erlang module (as opposed to an Elixir module), this function always returns `false`. #### Examples ``` iex> macro_exported?(Kernel, :use, 2) true iex> macro_exported?(:erlang, :abs, 1) false ``` ### make\_ref() #### Specs ``` make_ref() :: reference() ``` Returns an almost unique reference. The returned reference will re-occur after approximately 2^82 calls; therefore it is unique enough for practical purposes. Inlined by the compiler. #### Examples ``` make_ref() #=> #Reference<0.0.0.135> ``` ### match?(pattern, expr) A convenience macro that checks if the right side (an expression) matches the left side (a pattern). #### Examples ``` iex> match?(1, 1) true iex> match?(1, 2) false iex> match?({1, _}, {1, 2}) true iex> map = %{a: 1, b: 2} iex> match?(%{a: _}, map) true iex> a = 1 iex> match?(^a, 1) true ``` [`match?/2`](#match?/2) is very useful when filtering or finding a value in an enumerable: ``` iex> list = [a: 1, b: 2, a: 3] iex> Enum.filter(list, &match?({:a, _}, &1)) [a: 1, a: 3] ``` Guard clauses can also be given to the match: ``` iex> list = [a: 1, b: 2, a: 3] iex> Enum.filter(list, &match?({:a, x} when x < 2, &1)) [a: 1] ``` However, variables assigned in the match will not be available outside of the function call (unlike regular pattern matching with the `=` operator): ``` iex> match?(_x, 1) true iex> binding() [] ``` ### max(first, second) #### Specs ``` max(first, second) :: first | second when first: term(), second: term() ``` Returns the biggest of the two given terms according to Erlang's term ordering. If the terms compare equal, the first one is returned. Inlined by the compiler. #### Examples ``` iex> max(1, 2) 2 iex> max(:a, :b) :b ``` Using Erlang's term ordering means that comparisons are structural and not semantic. For example, when comparing dates: ``` iex> max(~D[2017-03-31], ~D[2017-04-01]) ~D[2017-03-31] ``` In the example above, [`max/2`](#max/2) returned March 31st instead of April 1st because the structural comparison compares the day before the year. In such cases it is common for modules to provide functions such as [`Date.compare/2`](date#compare/2) that perform semantic comparison. ### min(first, second) #### Specs ``` min(first, second) :: first | second when first: term(), second: term() ``` Returns the smallest of the two given terms according to Erlang's term ordering. If the terms compare equal, the first one is returned. Inlined by the compiler. #### Examples ``` iex> min(1, 2) 1 iex> min("foo", "bar") "bar" ``` Using Erlang's term ordering means that comparisons are structural and not semantic. For example, when comparing dates: ``` iex> min(~D[2017-03-31], ~D[2017-04-01]) ~D[2017-04-01] ``` In the example above, [`min/2`](#min/2) returned April 1st instead of March 31st because the structural comparison compares the day before the year. In such cases it is common for modules to provide functions such as [`Date.compare/2`](date#compare/2) that perform semantic comparison. ### pop\_in(path) Pops a key from the nested structure via the given `path`. This is similar to [`pop_in/2`](#pop_in/2), except the path is extracted via a macro rather than passing a list. For example: ``` pop_in(opts[:foo][:bar]) ``` Is equivalent to: ``` pop_in(opts, [:foo, :bar]) ``` Note that in order for this macro to work, the complete path must always be visible by this macro. For more information about the supported path expressions, please check [`get_and_update_in/2`](#get_and_update_in/2) docs. #### Examples ``` iex> users = %{"john" => %{age: 27}, "meg" => %{age: 23}} iex> pop_in(users["john"][:age]) {27, %{"john" => %{}, "meg" => %{age: 23}}} iex> users = %{john: %{age: 27}, meg: %{age: 23}} iex> pop_in(users.john[:age]) {27, %{john: %{}, meg: %{age: 23}}} ``` In case any entry returns `nil`, its key will be removed and the deletion will be considered a success. ### pop\_in(data, keys) #### Specs ``` pop_in(data, [Access.get_and_update_fun(term(), data) | term(), ...]) :: {term(), data} when data: Access.container() ``` Pops a key from the given nested structure. Uses the [`Access`](access) protocol to traverse the structures according to the given `keys`, unless the `key` is a function. If the key is a function, it will be invoked as specified in [`get_and_update_in/3`](#get_and_update_in/3). #### Examples ``` iex> users = %{"john" => %{age: 27}, "meg" => %{age: 23}} iex> pop_in(users, ["john", :age]) {27, %{"john" => %{}, "meg" => %{age: 23}}} ``` In case any entry returns `nil`, its key will be removed and the deletion will be considered a success. ``` iex> users = %{"john" => %{age: 27}, "meg" => %{age: 23}} iex> pop_in(users, ["jane", :age]) {nil, %{"john" => %{age: 27}, "meg" => %{age: 23}}} ``` ### put\_elem(tuple, index, value) #### Specs ``` put_elem(tuple(), non_neg_integer(), term()) :: tuple() ``` Puts `value` at the given zero-based `index` in `tuple`. Inlined by the compiler. #### Examples ``` iex> tuple = {:foo, :bar, 3} iex> put_elem(tuple, 0, :baz) {:baz, :bar, 3} ``` ### put\_in(path, value) Puts a value in a nested structure via the given `path`. This is similar to [`put_in/3`](#put_in/3), except the path is extracted via a macro rather than passing a list. For example: ``` put_in(opts[:foo][:bar], :baz) ``` Is equivalent to: ``` put_in(opts, [:foo, :bar], :baz) ``` This also works with nested structs and the `struct.path.to.value` way to specify paths: ``` put_in(struct.foo.bar, :baz) ``` Note that in order for this macro to work, the complete path must always be visible by this macro. For more information about the supported path expressions, please check [`get_and_update_in/2`](#get_and_update_in/2) docs. #### Examples ``` iex> users = %{"john" => %{age: 27}, "meg" => %{age: 23}} iex> put_in(users["john"][:age], 28) %{"john" => %{age: 28}, "meg" => %{age: 23}} iex> users = %{"john" => %{age: 27}, "meg" => %{age: 23}} iex> put_in(users["john"].age, 28) %{"john" => %{age: 28}, "meg" => %{age: 23}} ``` ### put\_in(data, keys, value) #### Specs ``` put_in(Access.t(), [term(), ...], term()) :: Access.t() ``` Puts a value in a nested structure. Uses the [`Access`](access) module to traverse the structures according to the given `keys`, unless the `key` is a function. If the key is a function, it will be invoked as specified in [`get_and_update_in/3`](#get_and_update_in/3). #### Examples ``` iex> users = %{"john" => %{age: 27}, "meg" => %{age: 23}} iex> put_in(users, ["john", :age], 28) %{"john" => %{age: 28}, "meg" => %{age: 23}} ``` In case any of the entries in the middle returns `nil`, an error will be raised when trying to access it next. ### raise(message) Raises an exception. If the argument `msg` is a binary, it raises a [`RuntimeError`](runtimeerror) exception using the given argument as message. If `msg` is an atom, it just calls [`raise/2`](#raise/2) with the atom as the first argument and `[]` as the second argument. If `msg` is an exception struct, it is raised as is. If `msg` is anything else, `raise` will fail with an [`ArgumentError`](argumenterror) exception. #### Examples ``` iex> raise "oops" ** (RuntimeError) oops try do 1 + :foo rescue x in [ArithmeticError] -> IO.puts("that was expected") raise x end ``` ### raise(exception, attributes) Raises an exception. Calls the `exception/1` function on the given argument (which has to be a module name like [`ArgumentError`](argumenterror) or [`RuntimeError`](runtimeerror)) passing `attrs` as the attributes in order to retrieve the exception struct. Any module that contains a call to the [`defexception/1`](#defexception/1) macro automatically implements the [`Exception.exception/1`](exception#c:exception/1) callback expected by [`raise/2`](#raise/2). For more information, see [`defexception/1`](#defexception/1). #### Examples ``` iex> raise(ArgumentError, "Sample") ** (ArgumentError) Sample ``` ### reraise(message, stacktrace) Raises an exception preserving a previous stacktrace. Works like [`raise/1`](#raise/1) but does not generate a new stacktrace. Notice that `__STACKTRACE__` can be used inside catch/rescue to retrieve the current stacktrace. #### Examples ``` try do raise "oops" rescue exception -> reraise exception, __STACKTRACE__ end ``` ### reraise(exception, attributes, stacktrace) Raises an exception preserving a previous stacktrace. [`reraise/3`](#reraise/3) works like [`reraise/2`](#reraise/2), except it passes arguments to the `exception/1` function as explained in [`raise/2`](#raise/2). #### Examples ``` try do raise "oops" rescue exception -> reraise WrapperError, [exception: exception], __STACKTRACE__ end ``` ### send(dest, message) #### Specs ``` send(dest :: Process.dest(), message) :: message when message: any() ``` Sends a message to the given `dest` and returns the message. `dest` may be a remote or local PID, a local port, a locally registered name, or a tuple in the form of `{registered_name, node}` for a registered name at another node. Inlined by the compiler. #### Examples ``` iex> send(self(), :hello) :hello ``` ### sigil\_C(term, modifiers) Handles the sigil `~C` for charlists. It returns a charlist without interpolations and without escape characters, except for the escaping of the closing sigil character itself. #### Examples ``` iex> ~C(foo) 'foo' iex> ~C(f#{o}o) 'f\#{o}o' ``` ### sigil\_D(date\_string, modifiers) Handles the sigil `~D` for dates. The lower case `~d` variant does not exist as interpolation and escape characters are not useful for date sigils. More information on dates can be found in the [`Date`](date) module. #### Examples ``` iex> ~D[2015-01-13] ~D[2015-01-13] ``` ### sigil\_N(naive\_datetime\_string, modifiers) Handles the sigil `~N` for naive date times. The lower case `~n` variant does not exist as interpolation and escape characters are not useful for date time sigils. More information on naive date times can be found in the [`NaiveDateTime`](naivedatetime) module. #### Examples ``` iex> ~N[2015-01-13 13:00:07] ~N[2015-01-13 13:00:07] iex> ~N[2015-01-13T13:00:07.001] ~N[2015-01-13 13:00:07.001] ``` ### sigil\_R(term, modifiers) Handles the sigil `~R` for regular expressions. It returns a regular expression pattern without interpolations and without escape characters. Note it still supports escape of Regex tokens (such as escaping `+` or `?`) and it also requires you to escape the closing sigil character itself if it appears on the Regex. More information on regexes can be found in the [`Regex`](regex) module. #### Examples ``` iex> Regex.match?(~R(f#{1,3}o), "f#o") true ``` ### sigil\_S(term, modifiers) Handles the sigil `~S` for strings. It returns a string without interpolations and without escape characters, except for the escaping of the closing sigil character itself. #### Examples ``` iex> ~S(foo) "foo" iex> ~S(f#{o}o) "f\#{o}o" iex> ~S(\o/) "\\o/" ``` However, if you want to re-use the sigil character itself on the string, you need to escape it: ``` iex> ~S((\)) "()" ``` ### sigil\_T(time\_string, modifiers) Handles the sigil `~T` for times. The lower case `~t` variant does not exist as interpolation and escape characters are not useful for time sigils. More information on times can be found in the [`Time`](time) module. #### Examples ``` iex> ~T[13:00:07] ~T[13:00:07] iex> ~T[13:00:07.001] ~T[13:00:07.001] ``` ### sigil\_U(datetime\_string, modifiers) Handles the sigil `~U` to create a UTC [`DateTime`](datetime). The lower case `~u` variant does not exist as interpolation and escape characters are not useful for date time sigils. The given `datetime_string` must include "Z" or "00:00" offset which marks it as UTC, otherwise an error is raised. More information on date times can be found in the [`DateTime`](datetime) module. #### Examples ``` iex> ~U[2015-01-13 13:00:07Z] ~U[2015-01-13 13:00:07Z] iex> ~U[2015-01-13T13:00:07.001+00:00] ~U[2015-01-13 13:00:07.001Z] ``` ### sigil\_W(term, modifiers) Handles the sigil `~W` for list of words. It returns a list of "words" split by whitespace without interpolations and without escape characters, except for the escaping of the closing sigil character itself. #### Modifiers * `s`: words in the list are strings (default) * `a`: words in the list are atoms * `c`: words in the list are charlists #### Examples ``` iex> ~W(foo #{bar} baz) ["foo", "\#{bar}", "baz"] ``` ### sigil\_c(term, modifiers) Handles the sigil `~c` for charlists. It returns a charlist as if it was a single quoted string, unescaping characters and replacing interpolations. #### Examples ``` iex> ~c(foo) 'foo' iex> ~c(f#{:o}o) 'foo' iex> ~c(f\#{:o}o) 'f\#{:o}o' ``` ### sigil\_r(term, modifiers) Handles the sigil `~r` for regular expressions. It returns a regular expression pattern, unescaping characters and replacing interpolations. More information on regular expressions can be found in the [`Regex`](regex) module. #### Examples ``` iex> Regex.match?(~r(foo), "foo") true iex> Regex.match?(~r/abc/, "abc") true ``` ### sigil\_s(term, modifiers) Handles the sigil `~s` for strings. It returns a string as if it was a double quoted string, unescaping characters and replacing interpolations. #### Examples ``` iex> ~s(foo) "foo" iex> ~s(f#{:o}o) "foo" iex> ~s(f\#{:o}o) "f\#{:o}o" ``` ### sigil\_w(term, modifiers) Handles the sigil `~w` for list of words. It returns a list of "words" split by whitespace. Character unescaping and interpolation happens for each word. #### Modifiers * `s`: words in the list are strings (default) * `a`: words in the list are atoms * `c`: words in the list are charlists #### Examples ``` iex> ~w(foo #{:bar} baz) ["foo", "bar", "baz"] iex> ~w(foo #{" bar baz "}) ["foo", "bar", "baz"] iex> ~w(--source test/enum_test.exs) ["--source", "test/enum_test.exs"] iex> ~w(foo bar baz)a [:foo, :bar, :baz] ``` ### spawn(fun) #### Specs ``` spawn((() -> any())) :: pid() ``` Spawns the given function and returns its PID. Typically developers do not use the `spawn` functions, instead they use abstractions such as [`Task`](task), [`GenServer`](genserver) and [`Agent`](agent), built on top of `spawn`, that spawns processes with more conveniences in terms of introspection and debugging. Check the [`Process`](process) module for more process-related functions. The anonymous function receives 0 arguments, and may return any value. Inlined by the compiler. #### Examples ``` current = self() child = spawn(fn -> send(current, {self(), 1 + 2}) end) receive do {^child, 3} -> IO.puts("Received 3 back") end ``` ### spawn(module, fun, args) #### Specs ``` spawn(module(), atom(), list()) :: pid() ``` Spawns the given function `fun` from the given `module` passing it the given `args` and returns its PID. Typically developers do not use the `spawn` functions, instead they use abstractions such as [`Task`](task), [`GenServer`](genserver) and [`Agent`](agent), built on top of `spawn`, that spawns processes with more conveniences in terms of introspection and debugging. Check the [`Process`](process) module for more process-related functions. Inlined by the compiler. #### Examples ``` spawn(SomeModule, :function, [1, 2, 3]) ``` ### spawn\_link(fun) #### Specs ``` spawn_link((() -> any())) :: pid() ``` Spawns the given function, links it to the current process, and returns its PID. Typically developers do not use the `spawn` functions, instead they use abstractions such as [`Task`](task), [`GenServer`](genserver) and [`Agent`](agent), built on top of `spawn`, that spawns processes with more conveniences in terms of introspection and debugging. Check the [`Process`](process) module for more process-related functions. For more information on linking, check [`Process.link/1`](process#link/1). The anonymous function receives 0 arguments, and may return any value. Inlined by the compiler. #### Examples ``` current = self() child = spawn_link(fn -> send(current, {self(), 1 + 2}) end) receive do {^child, 3} -> IO.puts("Received 3 back") end ``` ### spawn\_link(module, fun, args) #### Specs ``` spawn_link(module(), atom(), list()) :: pid() ``` Spawns the given function `fun` from the given `module` passing it the given `args`, links it to the current process, and returns its PID. Typically developers do not use the `spawn` functions, instead they use abstractions such as [`Task`](task), [`GenServer`](genserver) and [`Agent`](agent), built on top of `spawn`, that spawns processes with more conveniences in terms of introspection and debugging. Check the [`Process`](process) module for more process-related functions. For more information on linking, check [`Process.link/1`](process#link/1). Inlined by the compiler. #### Examples ``` spawn_link(SomeModule, :function, [1, 2, 3]) ``` ### spawn\_monitor(fun) #### Specs ``` spawn_monitor((() -> any())) :: {pid(), reference()} ``` Spawns the given function, monitors it and returns its PID and monitoring reference. Typically developers do not use the `spawn` functions, instead they use abstractions such as [`Task`](task), [`GenServer`](genserver) and [`Agent`](agent), built on top of `spawn`, that spawns processes with more conveniences in terms of introspection and debugging. Check the [`Process`](process) module for more process-related functions. The anonymous function receives 0 arguments, and may return any value. Inlined by the compiler. #### Examples ``` current = self() spawn_monitor(fn -> send(current, {self(), 1 + 2}) end) ``` ### spawn\_monitor(module, fun, args) #### Specs ``` spawn_monitor(module(), atom(), list()) :: {pid(), reference()} ``` Spawns the given module and function passing the given args, monitors it and returns its PID and monitoring reference. Typically developers do not use the `spawn` functions, instead they use abstractions such as [`Task`](task), [`GenServer`](genserver) and [`Agent`](agent), built on top of `spawn`, that spawns processes with more conveniences in terms of introspection and debugging. Check the [`Process`](process) module for more process-related functions. Inlined by the compiler. #### Examples ``` spawn_monitor(SomeModule, :function, [1, 2, 3]) ``` ### struct(struct, fields \\ []) #### Specs ``` struct(module() | struct(), Enum.t()) :: struct() ``` Creates and updates structs. The `struct` argument may be an atom (which defines `defstruct`) or a `struct` itself. The second argument is any [`Enumerable`](enumerable) that emits two-element tuples (key-value pairs) during enumeration. Keys in the [`Enumerable`](enumerable) that don't exist in the struct are automatically discarded. Note that keys must be atoms, as only atoms are allowed when defining a struct. This function is useful for dynamically creating and updating structs, as well as for converting maps to structs; in the latter case, just inserting the appropriate `:__struct__` field into the map may not be enough and [`struct/2`](#struct/2) should be used instead. #### Examples ``` defmodule User do defstruct name: "john" end struct(User) #=> %User{name: "john"} opts = [name: "meg"] user = struct(User, opts) #=> %User{name: "meg"} struct(user, unknown: "value") #=> %User{name: "meg"} struct(User, %{name: "meg"}) #=> %User{name: "meg"} # String keys are ignored struct(User, %{"name" => "meg"}) #=> %User{name: "john"} ``` ### struct!(struct, fields \\ []) #### Specs ``` struct!(module() | struct(), Enum.t()) :: struct() ``` Similar to [`struct/2`](#struct/2) but checks for key validity. The function [`struct!/2`](#struct!/2) emulates the compile time behaviour of structs. This means that: * when building a struct, as in `struct!(SomeStruct, key: :value)`, it is equivalent to `%SomeStruct{key: :value}` and therefore this function will check if every given key-value belongs to the struct. If the struct is enforcing any key via `@enforce_keys`, those will be enforced as well; * when updating a struct, as in `struct!(%SomeStruct{}, key: :value)`, it is equivalent to `%SomeStruct{struct | key: :value}` and therefore this function will check if every given key-value belongs to the struct. However, updating structs does not enforce keys, as keys are enforced only when building; ### throw(term) #### Specs ``` throw(term()) :: no_return() ``` A non-local return from a function. Check [`Kernel.SpecialForms.try/1`](kernel.specialforms#try/1) for more information. Inlined by the compiler. ### to\_charlist(term) Converts the given term to a charlist according to the [`List.Chars`](list.chars) protocol. #### Examples ``` iex> to_charlist(:foo) 'foo' ``` ### to\_string(term) Converts the argument to a string according to the [`String.Chars`](string.chars) protocol. This is the function invoked when there is string interpolation. #### Examples ``` iex> to_string(:foo) "foo" ``` ### unless(condition, clauses) Provides an `unless` macro. This macro evaluates and returns the `do` block passed in as the second argument if `condition` evaluates to a falsy value (`false` or `nil`). Otherwise, it returns the value of the `else` block if present or `nil` if not. See also [`if/2`](#if/2). #### Examples ``` iex> unless(Enum.empty?([]), do: "Hello") nil iex> unless(Enum.empty?([1, 2, 3]), do: "Hello") "Hello" iex> unless Enum.sum([2, 2]) == 5 do ...> "Math still works" ...> else ...> "Math is broken" ...> end "Math still works" ``` ### update\_in(path, fun) Updates a nested structure via the given `path`. This is similar to [`update_in/3`](#update_in/3), except the path is extracted via a macro rather than passing a list. For example: ``` update_in(opts[:foo][:bar], &(&1 + 1)) ``` Is equivalent to: ``` update_in(opts, [:foo, :bar], &(&1 + 1)) ``` This also works with nested structs and the `struct.path.to.value` way to specify paths: ``` update_in(struct.foo.bar, &(&1 + 1)) ``` Note that in order for this macro to work, the complete path must always be visible by this macro. For more information about the supported path expressions, please check [`get_and_update_in/2`](#get_and_update_in/2) docs. #### Examples ``` iex> users = %{"john" => %{age: 27}, "meg" => %{age: 23}} iex> update_in(users["john"][:age], &(&1 + 1)) %{"john" => %{age: 28}, "meg" => %{age: 23}} iex> users = %{"john" => %{age: 27}, "meg" => %{age: 23}} iex> update_in(users["john"].age, &(&1 + 1)) %{"john" => %{age: 28}, "meg" => %{age: 23}} ``` ### update\_in(data, keys, fun) #### Specs ``` update_in(Access.t(), [term(), ...], (term() -> term())) :: Access.t() ``` Updates a key in a nested structure. Uses the [`Access`](access) module to traverse the structures according to the given `keys`, unless the `key` is a function. If the key is a function, it will be invoked as specified in [`get_and_update_in/3`](#get_and_update_in/3). #### Examples ``` iex> users = %{"john" => %{age: 27}, "meg" => %{age: 23}} iex> update_in(users, ["john", :age], &(&1 + 1)) %{"john" => %{age: 28}, "meg" => %{age: 23}} ``` In case any of the entries in the middle returns `nil`, an error will be raised when trying to access it next. ### use(module, opts \\ []) Uses the given module in the current context. When calling: ``` use MyModule, some: :options ``` the `__using__/1` macro from the `MyModule` module is invoked with the second argument passed to `use` as its argument. Since `__using__/1` is a macro, all the usual macro rules apply, and its return value should be quoted code that is then inserted where [`use/2`](#use/2) is called. #### Examples For example, in order to write test cases using the [`ExUnit`](https://hexdocs.pm/ex_unit/ExUnit.html) framework provided with Elixir, a developer should `use` the [`ExUnit.Case`](https://hexdocs.pm/ex_unit/ExUnit.Case.html) module: ``` defmodule AssertionTest do use ExUnit.Case, async: true test "always pass" do assert true end end ``` In this example, [`ExUnit.Case.__using__/1`](https://hexdocs.pm/ex_unit/ExUnit.Case.html#__using__/1) is called with the keyword list `[async: true]` as its argument; [`use/2`](#use/2) translates to: ``` defmodule AssertionTest do require ExUnit.Case ExUnit.Case.__using__(async: true) test "always pass" do assert true end end ``` [`ExUnit.Case`](https://hexdocs.pm/ex_unit/ExUnit.Case.html) will then define the `__using__/1` macro: ``` defmodule ExUnit.Case do defmacro __using__(opts) do # do something with opts quote do # return some code to inject in the caller end end end ``` #### Best practices `__using__/1` is typically used when there is a need to set some state (via module attributes) or callbacks (like `@before_compile`, see the documentation for [`Module`](module) for more information) into the caller. `__using__/1` may also be used to alias, require, or import functionality from different modules: ``` defmodule MyModule do defmacro __using__(_opts) do quote do import MyModule.Foo import MyModule.Bar import MyModule.Baz alias MyModule.Repo end end end ``` However, do not provide `__using__/1` if all it does is to import, alias or require the module itself. For example, avoid this: ``` defmodule MyModule do defmacro __using__(_opts) do quote do import MyModule end end end ``` In such cases, developers should instead import or alias the module directly, so that they can customize those as they wish, without the indirection behind [`use/2`](#use/2). Finally, developers should also avoid defining functions inside the `__using__/1` callback, unless those functions are the default implementation of a previously defined `@callback` or are functions meant to be overridden (see [`defoverridable/1`](#defoverridable/1)). Even in these cases, defining functions should be seen as a "last resort". In case you want to provide some existing functionality to the user module, please define it in a module which will be imported accordingly; for example, [`ExUnit.Case`](https://hexdocs.pm/ex_unit/ExUnit.Case.html) doesn't define the `test/3` macro in the module that calls `use ExUnit.Case`, but it defines [`ExUnit.Case.test/3`](https://hexdocs.pm/ex_unit/ExUnit.Case.html#test/3) and just imports that into the caller when used. ### var!(var, context \\ nil) When used inside quoting, marks that the given variable should not be hygienized. The argument can be either a variable unquoted or in standard tuple form `{name, meta, context}`. Check [`Kernel.SpecialForms.quote/2`](kernel.specialforms#quote/2) for more information. ### left |> right Pipe operator. This operator introduces the expression on the left-hand side as the first argument to the function call on the right-hand side. #### Examples ``` iex> [1, [2], 3] |> List.flatten() [1, 2, 3] ``` The example above is the same as calling `List.flatten([1, [2], 3])`. The `|>` operator is mostly useful when there is a desire to execute a series of operations resembling a pipeline: ``` iex> [1, [2], 3] |> List.flatten() |> Enum.map(fn x -> x * 2 end) [2, 4, 6] ``` In the example above, the list `[1, [2], 3]` is passed as the first argument to the [`List.flatten/1`](list#flatten/1) function, then the flattened list is passed as the first argument to the [`Enum.map/2`](enum#map/2) function which doubles each element of the list. In other words, the expression above simply translates to: ``` Enum.map(List.flatten([1, [2], 3]), fn x -> x * 2 end) ``` #### Pitfalls There are two common pitfalls when using the pipe operator. The first one is related to operator precedence. For example, the following expression: ``` String.graphemes "Hello" |> Enum.reverse ``` Translates to: ``` String.graphemes("Hello" |> Enum.reverse()) ``` which results in an error as the [`Enumerable`](enumerable) protocol is not defined for binaries. Adding explicit parentheses resolves the ambiguity: ``` String.graphemes("Hello") |> Enum.reverse() ``` Or, even better: ``` "Hello" |> String.graphemes() |> Enum.reverse() ``` The second pitfall is that the `|>` operator works on calls. For example, when you write: ``` "Hello" |> some_function() ``` Elixir sees the right-hand side is a function call and pipes to it. This means that, if you want to pipe to an anonymous or captured function, it must also be explicitly called. Given the anonymous function: ``` fun = fn x -> IO.puts(x) end fun.("Hello") ``` This won't work as it will rather try to invoke the local function `fun`: ``` "Hello" |> fun() ``` This works: ``` "Hello" |> fun.() ``` As you can see, the `|>` operator retains the same semantics as when the pipe is not used since both require the `fun.(...)` notation. ### left || right Provides a short-circuit operator that evaluates and returns the second expression only if the first one does not evaluate to a truthy value (that is, it is either `nil` or `false`). Returns the first expression otherwise. Not allowed in guard clauses. #### Examples ``` iex> Enum.empty?([1]) || Enum.empty?([1]) false iex> List.first([]) || true true iex> Enum.empty?([1]) || 1 1 iex> Enum.empty?([]) || throw(:bad) true ``` Note that, unlike [`or/2`](#or/2), this operator accepts any expression as the first argument, not only booleans.
programming_docs
elixir try, catch, and rescue Getting Started try, catch, and rescue ====================== Elixir has three error mechanisms: errors, throws, and exits. In this chapter, we will explore each of them and include remarks about when each should be used. Errors ------ Errors (or *exceptions*) are used when exceptional things happen in the code. A sample error can be retrieved by trying to add a number into an atom: ``` iex> :foo + 1 ** (ArithmeticError) bad argument in arithmetic expression :erlang.+(:foo, 1) ``` A runtime error can be raised any time by using `raise/1`: ``` iex> raise "oops" ** (RuntimeError) oops ``` Other errors can be raised with `raise/2` passing the error name and a list of keyword arguments: ``` iex> raise ArgumentError, message: "invalid argument foo" ** (ArgumentError) invalid argument foo ``` You can also define your own errors by creating a module and using the `defexception` construct inside it; this way, you’ll create an error with the same name as the module it’s defined in. The most common case is to define a custom exception with a message field: ``` iex> defmodule MyError do iex> defexception message: "default message" iex> end iex> raise MyError ** (MyError) default message iex> raise MyError, message: "custom message" ** (MyError) custom message ``` Errors can be **rescued** using the `try/rescue` construct: ``` iex> try do ...> raise "oops" ...> rescue ...> e in RuntimeError -> e ...> end %RuntimeError{message: "oops"} ``` The example above rescues the runtime error and returns the error itself which is then printed in the `iex` session. If you don’t have any use for the error, you don’t have to provide it: ``` iex> try do ...> raise "oops" ...> rescue ...> RuntimeError -> "Error!" ...> end "Error!" ``` In practice, however, Elixir developers rarely use the `try/rescue` construct. For example, many languages would force you to rescue an error when a file cannot be opened successfully. Elixir instead provides a `File.read/1` function which returns a tuple containing information about whether the file was opened successfully: ``` iex> File.read "hello" {:error, :enoent} iex> File.write "hello", "world" :ok iex> File.read "hello" {:ok, "world"} ``` There is no `try/rescue` here. In case you want to handle multiple outcomes of opening a file, you can use pattern matching within the `case` construct: ``` iex> case File.read "hello" do ...> {:ok, body} -> IO.puts "Success: #{body}" ...> {:error, reason} -> IO.puts "Error: #{reason}" ...> end ``` At the end of the day, it’s up to your application to decide if an error while opening a file is exceptional or not. That’s why Elixir doesn’t impose exceptions on `File.read/1` and many other functions. Instead, it leaves it up to the developer to choose the best way to proceed. For the cases where you do expect a file to exist (and the lack of that file is truly an *error*) you may use `File.read!/1`: ``` iex> File.read! "unknown" ** (File.Error) could not read file unknown: no such file or directory (elixir) lib/file.ex:272: File.read!/1 ``` Many functions in the standard library follow the pattern of having a counterpart that raises an exception instead of returning tuples to match against. The convention is to create a function (`foo`) which returns `{:ok, result}` or `{:error, reason}` tuples and another function (`foo!`, same name but with a trailing `!`) that takes the same arguments as `foo` but which raises an exception if there’s an error. `foo!` should return the result (not wrapped in a tuple) if everything goes fine. The [`File` module](https://hexdocs.pm/elixir/File.html) is a good example of this convention. In Elixir, we avoid using `try/rescue` because **we don’t use errors for control flow**. We take errors literally: they are reserved for unexpected and/or exceptional situations. In case you actually need flow control constructs, *throws* should be used. That’s what we are going to see next. Throws ------ In Elixir, a value can be thrown and later be caught. `throw` and `catch` are reserved for situations where it is not possible to retrieve a value unless by using `throw` and `catch`. Those situations are quite uncommon in practice except when interfacing with libraries that do not provide a proper API. For example, let’s imagine the `Enum` module did not provide any API for finding a value and that we needed to find the first multiple of 13 in a list of numbers: ``` iex> try do ...> Enum.each -50..50, fn(x) -> ...> if rem(x, 13) == 0, do: throw(x) ...> end ...> "Got nothing" ...> catch ...> x -> "Got #{x}" ...> end "Got -39" ``` Since `Enum` *does* provide a proper API, in practice `Enum.find/2` is the way to go: ``` iex> Enum.find -50..50, &(rem(&1, 13) == 0) -39 ``` Exits ----- All Elixir code runs inside processes that communicate with each other. When a process dies of “natural causes” (e.g., unhandled exceptions), it sends an `exit` signal. A process can also die by explicitly sending an `exit` signal: ``` iex> spawn_link fn -> exit(1) end ** (EXIT from #PID<0.56.0>) evaluator process exited with reason: 1 ``` In the example above, the linked process died by sending an `exit` signal with a value of 1. The Elixir shell automatically handles those messages and prints them to the terminal. `exit` can also be “caught” using `try/catch`: ``` iex> try do ...> exit "I am exiting" ...> catch ...> :exit, _ -> "not really" ...> end "not really" ``` Using `try/catch` is already uncommon and using it to catch exits is even rarer. `exit` signals are an important part of the fault tolerant system provided by the Erlang VM. Processes usually run under supervision trees which are themselves processes that listen to `exit` signals from the supervised processes. Once an `exit` signal is received, the supervision strategy kicks in and the supervised process is restarted. It is exactly this supervision system that makes constructs like `try/catch` and `try/rescue` so uncommon in Elixir. Instead of rescuing an error, we’d rather “fail fast” since the supervision tree will guarantee our application will go back to a known initial state after the error. After ----- Sometimes it’s necessary to ensure that a resource is cleaned up after some action that could potentially raise an error. The `try/after` construct allows you to do that. For example, we can open a file and use an `after` clause to close it–even if something goes wrong: ``` iex> {:ok, file} = File.open "sample", [:utf8, :write] iex> try do ...> IO.write file, "olá" ...> raise "oops, something went wrong" ...> after ...> File.close(file) ...> end ** (RuntimeError) oops, something went wrong ``` The `after` clause will be executed regardless of whether or not the tried block succeeds. Note, however, that if a linked process exits, this process will exit and the `after` clause will not get run. Thus `after` provides only a soft guarantee. Luckily, files in Elixir are also linked to the current processes and therefore they will always get closed if the current process crashes, independent of the `after` clause. You will find the same to be true for other resources like ETS tables, sockets, ports and more. Sometimes you may want to wrap the entire body of a function in a `try` construct, often to guarantee some code will be executed afterwards. In such cases, Elixir allows you to omit the `try` line: ``` iex> defmodule RunAfter do ...> def without_even_trying do ...> raise "oops" ...> after ...> IO.puts "cleaning up!" ...> end ...> end iex> RunAfter.without_even_trying cleaning up! ** (RuntimeError) oops ``` Elixir will automatically wrap the function body in a `try` whenever one of `after`, `rescue` or `catch` is specified. Else ---- If an `else` block is present, it will match on the results of the `try` block whenever the `try` block finishes without a throw or an error. ``` iex> x = 2 2 iex> try do ...> 1 / x ...> rescue ...> ArithmeticError -> ...> :infinity ...> else ...> y when y < 1 and y > -1 -> ...> :small ...> _ -> ...> :large ...> end :small ``` Exceptions in the `else` block are not caught. If no pattern inside the `else` block matches, an exception will be raised; this exception is not caught by the current `try/catch/rescue/after` block. Variables scope --------------- It is important to bear in mind that variables defined inside `try/catch/rescue/after` blocks do not leak to the outer context. This is because the `try` block may fail and as such the variables may never be bound in the first place. In other words, this code is invalid: ``` iex> try do ...> raise "fail" ...> what_happened = :did_not_raise ...> rescue ...> _ -> what_happened = :rescued ...> end iex> what_happened ** (RuntimeError) undefined function: what_happened/0 ``` Instead, you can store the value of the `try` expression: ``` iex> what_happened = ...> try do ...> raise "fail" ...> :did_not_raise ...> rescue ...> _ -> :rescued ...> end iex> what_happened :rescued ``` This finishes our introduction to `try`, `catch`, and `rescue`. You will find they are used less frequently in Elixir than in other languages, although they may be handy in some situations where a library or some particular code is not playing “by the rules”. elixir Logger.Translator Logger.Translator ================== Default translation for Erlang log messages. Logger allows developers to rewrite log messages provided by OTP applications into a format more compatible with Elixir log messages by providing a translator. A translator is simply a tuple containing a module and a function that can be added and removed via the [`Logger.add_translator/1`](logger#add_translator/1) and [`Logger.remove_translator/1`](logger#remove_translator/1) functions and is invoked for every Erlang message above the minimum log level with four arguments: * `min_level` - the current Logger level * `level` - the level of the message being translated * `kind` - if the message is a `:report` or `:format` * `message` - the message to format. If it is `:report`, it is a tuple with `{report_type, report_data}`, if it is `:format`, it is a tuple with `{format_message, format_args}`. The function must return: * `{:ok, chardata, metadata}` - if the message translation with its metadata * `{:ok, chardata}` - the translated message * `:skip` - if the message is not meant to be translated nor logged * `:none` - if there is no translation, which triggers the next translator See the function [`translate/4`](#translate/4) in this module for an example implementation and the default messages translated by Logger. Summary ======== Functions ---------- [translate(min\_level, level, kind, message)](#translate/4) Built-in translation function. Functions ========== ### translate(min\_level, level, kind, message) Built-in translation function. elixir Macro Macro ====== Conveniences for working with macros. Custom Sigils -------------- To create a custom sigil, define a function with the name `sigil_{identifier}` that takes two arguments. The first argument will be the string, the second will be a charlist containing any modifiers. If the sigil is lower case (such as `sigil_x`) then the string argument will allow interpolation. If the sigil is upper case (such as `sigil_X`) then the string will not be interpolated. Valid modifiers include only lower and upper case letters. Other characters will cause a syntax error. The module containing the custom sigil must be imported before the sigil syntax can be used. ### Examples ``` defmodule MySigils do defmacro sigil_x(term, [?r]) do quote do unquote(term) |> String.reverse() end end defmacro sigil_x(term, _modifiers) do term end defmacro sigil_X(term, [?r]) do quote do unquote(term) |> String.reverse() end end defmacro sigil_X(term, _modifiers) do term end end import MySigils ~x(with #{"inter" <> "polation"}) #=>"with interpolation" ~x(with #{"inter" <> "polation"})r #=>"noitalopretni htiw" ~X(without #{"interpolation"}) #=>"without \#{"interpolation"}" ~X(without #{"interpolation"})r #=>"}\"noitalopretni\"{# tuohtiw" ``` Summary ======== Types ------ [expr()](#t:expr/0) Represents expressions in the AST [literal()](#t:literal/0) Represents literals in the AST [t()](#t:t/0) Abstract Syntax Tree (AST) Functions ---------- [camelize(string)](#camelize/1) Converts the given string to CamelCase format. [decompose\_call(ast)](#decompose_call/1) Decomposes a local or remote call into its remote part (when provided), function name and argument list. [escape(expr, opts \\ [])](#escape/2) Recursively escapes a value so it can be inserted into a syntax tree. [expand(ast, env)](#expand/2) Receives an AST node and expands it until it can no longer be expanded. [expand\_once(ast, env)](#expand_once/2) Receives an AST node and expands it once. [generate\_arguments(amount, context)](#generate_arguments/2) Generates AST nodes for a given number of required argument variables using [`Macro.var/2`](macro#var/2). [operator?(name, arity)](#operator?/2) Returns `true` if the given name and arity is an operator. [pipe(expr, call\_args, position)](#pipe/3) Pipes `expr` into the `call_args` at the given `position`. [postwalk(ast, fun)](#postwalk/2) Performs a depth-first, post-order traversal of quoted expressions. [postwalk(ast, acc, fun)](#postwalk/3) Performs a depth-first, post-order traversal of quoted expressions using an accumulator. [prewalk(ast, fun)](#prewalk/2) Performs a depth-first, pre-order traversal of quoted expressions. [prewalk(ast, acc, fun)](#prewalk/3) Performs a depth-first, pre-order traversal of quoted expressions using an accumulator. [quoted\_literal?(term)](#quoted_literal?/1) Returns `true` if the given quoted expression is an AST literal. [special\_form?(name, arity)](#special_form?/2) Returns `true` if the given name and arity is a special form. [struct!(module, env)](#struct!/2) Expands the struct given by `module` in the given `env`. [to\_string(tree, fun \\ fn \_ast, string -> string end)](#to_string/2) Converts the given expression AST to a string. [traverse(ast, acc, pre, post)](#traverse/4) Performs a depth-first traversal of quoted expressions using an accumulator. [underscore(atom)](#underscore/1) Converts the given atom or binary to underscore format. [unescape\_string(chars)](#unescape_string/1) Unescapes the given chars. [unescape\_string(chars, map)](#unescape_string/2) Unescapes the given chars according to the map given. [unpipe(expr)](#unpipe/1) Breaks a pipeline expression into a list. [update\_meta(quoted, fun)](#update_meta/2) Applies the given function to the node metadata if it contains one. [validate(expr)](#validate/1) Validates the given expressions are valid quoted expressions. [var(var, context)](#var/2) Generates an AST node representing the variable given by the atoms `var` and `context`. Types ====== ### expr() #### Specs ``` expr() :: {expr() | atom(), keyword(), atom() | [t()]} ``` Represents expressions in the AST ### literal() #### Specs ``` literal() :: atom() | number() | binary() | (... -> any()) | {t(), t()} | [t()] ``` Represents literals in the AST ### t() #### Specs ``` t() :: expr() | literal() ``` Abstract Syntax Tree (AST) Functions ========== ### camelize(string) #### Specs ``` camelize(String.t()) :: String.t() ``` Converts the given string to CamelCase format. This function was designed to camelize language identifiers/tokens, that's why it belongs to the [`Macro`](#content) module. Do not use it as a general mechanism for camelizing strings as it does not support Unicode or characters that are not valid in Elixir identifiers. #### Examples ``` iex> Macro.camelize("foo_bar") "FooBar" ``` If uppercase characters are present, they are not modified in any way as a mechanism to preserve acronyms: ``` iex> Macro.camelize("API.V1") "API.V1" iex> Macro.camelize("API_SPEC") "API_SPEC" ``` ### decompose\_call(ast) #### Specs ``` decompose_call(t()) :: {atom(), [t()]} | {t(), atom(), [t()]} | :error ``` Decomposes a local or remote call into its remote part (when provided), function name and argument list. Returns `:error` when an invalid call syntax is provided. #### Examples ``` iex> Macro.decompose_call(quote(do: foo)) {:foo, []} iex> Macro.decompose_call(quote(do: foo())) {:foo, []} iex> Macro.decompose_call(quote(do: foo(1, 2, 3))) {:foo, [1, 2, 3]} iex> Macro.decompose_call(quote(do: Elixir.M.foo(1, 2, 3))) {{:__aliases__, [], [:Elixir, :M]}, :foo, [1, 2, 3]} iex> Macro.decompose_call(quote(do: 42)) :error ``` ### escape(expr, opts \\ []) #### Specs ``` escape(term(), keyword()) :: t() ``` Recursively escapes a value so it can be inserted into a syntax tree. #### Examples ``` iex> Macro.escape(:foo) :foo iex> Macro.escape({:a, :b, :c}) {:{}, [], [:a, :b, :c]} iex> Macro.escape({:unquote, [], [1]}, unquote: true) 1 ``` #### Options * `:unquote` - when true, this function leaves [`unquote/1`](kernel.specialforms#unquote/1) and [`unquote_splicing/1`](kernel.specialforms#unquote_splicing/1) statements unescaped, effectively unquoting the contents on escape. This option is useful only when escaping ASTs which may have quoted fragments in them. Defaults to false. * `:prune_metadata` - when true, removes metadata from escaped AST nodes. Note this option changes the semantics of escaped code and it should only be used when escaping ASTs, never values. Defaults to false. As an example, [`ExUnit`](https://hexdocs.pm/ex_unit/ExUnit.html) stores the AST of every assertion, so when an assertion fails we can show code snippets to users. Without this option, each time the test module is compiled, we get a different MD5 of the module byte code, because the AST contains metadata, such as counters, specific to the compilation environment. By pruning the metadata, we ensure that the module is deterministic and reduce the amount of data [`ExUnit`](https://hexdocs.pm/ex_unit/ExUnit.html) needs to keep around. #### Comparison to [`Kernel.SpecialForms.quote/2`](kernel.specialforms#quote/2) The [`escape/2`](#escape/2) function is sometimes confused with [`Kernel.SpecialForms.quote/2`](kernel.specialforms#quote/2), because the above examples behave the same with both. The key difference is best illustrated when the value to escape is stored in a variable. ``` iex> Macro.escape({:a, :b, :c}) {:{}, [], [:a, :b, :c]} iex> quote do: {:a, :b, :c} {:{}, [], [:a, :b, :c]} iex> value = {:a, :b, :c} iex> Macro.escape(value) {:{}, [], [:a, :b, :c]} iex> quote do: value {:value, [], __MODULE__} iex> value = {:a, :b, :c} iex> quote do: unquote(value) {:a, :b, :c} ``` [`escape/2`](#escape/2) is used to escape *values* (either directly passed or variable bound), while [`Kernel.SpecialForms.quote/2`](kernel.specialforms#quote/2) produces syntax trees for expressions. ### expand(ast, env) Receives an AST node and expands it until it can no longer be expanded. Note this function does not traverse the AST, only the root node is expanded. This function uses [`expand_once/2`](#expand_once/2) under the hood. Check it out for more information and examples. ### expand\_once(ast, env) Receives an AST node and expands it once. The following contents are expanded: * Macros (local or remote) * Aliases are expanded (if possible) and return atoms * Compilation environment macros ([`__CALLER__/0`](kernel.specialforms#__CALLER__/0), [`__DIR__/0`](kernel.specialforms#__DIR__/0), [`__ENV__/0`](kernel.specialforms#__ENV__/0) and [`__MODULE__/0`](kernel.specialforms#__MODULE__/0)) * Module attributes reader (`@foo`) If the expression cannot be expanded, it returns the expression itself. This function does not traverse the AST, only the root node is expanded. [`expand_once/2`](#expand_once/2) performs the expansion just once. Check [`expand/2`](#expand/2) to perform expansion until the node can no longer be expanded. #### Examples In the example below, we have a macro that generates a module with a function named `name_length` that returns the length of the module name. The value of this function will be calculated at compilation time and not at runtime. Consider the implementation below: ``` defmacro defmodule_with_length(name, do: block) do length = length(Atom.to_charlist(name)) quote do defmodule unquote(name) do def name_length, do: unquote(length) unquote(block) end end end ``` When invoked like this: ``` defmodule_with_length My.Module do def other_function, do: ... end ``` The compilation will fail because `My.Module` when quoted is not an atom, but a syntax tree as follows: ``` {:__aliases__, [], [:My, :Module]} ``` That said, we need to expand the aliases node above to an atom, so we can retrieve its length. Expanding the node is not straightforward because we also need to expand the caller aliases. For example: ``` alias MyHelpers, as: My defmodule_with_length My.Module do def other_function, do: ... end ``` The final module name will be `MyHelpers.Module` and not `My.Module`. With [`Macro.expand/2`](macro#expand/2), such aliases are taken into consideration. Local and remote macros are also expanded. We could rewrite our macro above to use this function as: ``` defmacro defmodule_with_length(name, do: block) do expanded = Macro.expand(name, __CALLER__) length = length(Atom.to_charlist(expanded)) quote do defmodule unquote(name) do def name_length, do: unquote(length) unquote(block) end end end ``` ### generate\_arguments(amount, context) #### Specs ``` generate_arguments(0, context :: atom()) :: [] ``` ``` generate_arguments(pos_integer(), context) :: [{atom(), [], context}, ...] when context: atom() ``` Generates AST nodes for a given number of required argument variables using [`Macro.var/2`](macro#var/2). #### Examples ``` iex> Macro.generate_arguments(2, __MODULE__) [{:arg1, [], __MODULE__}, {:arg2, [], __MODULE__}] ``` ### operator?(name, arity) #### Specs ``` operator?(name :: atom(), arity()) :: boolean() ``` Returns `true` if the given name and arity is an operator. ### pipe(expr, call\_args, position) #### Specs ``` pipe(t(), t(), integer()) :: t() ``` Pipes `expr` into the `call_args` at the given `position`. ### postwalk(ast, fun) #### Specs ``` postwalk(t(), (t() -> t())) :: t() ``` Performs a depth-first, post-order traversal of quoted expressions. ### postwalk(ast, acc, fun) #### Specs ``` postwalk(t(), any(), (t(), any() -> {t(), any()})) :: {t(), any()} ``` Performs a depth-first, post-order traversal of quoted expressions using an accumulator. ### prewalk(ast, fun) #### Specs ``` prewalk(t(), (t() -> t())) :: t() ``` Performs a depth-first, pre-order traversal of quoted expressions. ### prewalk(ast, acc, fun) #### Specs ``` prewalk(t(), any(), (t(), any() -> {t(), any()})) :: {t(), any()} ``` Performs a depth-first, pre-order traversal of quoted expressions using an accumulator. ### quoted\_literal?(term) #### Specs ``` quoted_literal?(literal()) :: true ``` ``` quoted_literal?(expr()) :: false ``` Returns `true` if the given quoted expression is an AST literal. ### special\_form?(name, arity) #### Specs ``` special_form?(name :: atom(), arity()) :: boolean() ``` Returns `true` if the given name and arity is a special form. ### struct!(module, env) #### Specs ``` struct!(module, Macro.Env.t()) :: %module{} when module: module() ``` Expands the struct given by `module` in the given `env`. This is useful when a struct needs to be expanded at compilation time and the struct being expanded may or may not have been compiled. This function is even capable of expanding structs defined under the module being compiled. It will raise [`CompileError`](compileerror) if the struct is not available. ### to\_string(tree, fun \\ fn \_ast, string -> string end) #### Specs ``` to_string(t(), (t(), String.t() -> String.t())) :: String.t() ``` Converts the given expression AST to a string. The given `fun` is called for every node in the AST with two arguments: the AST of the node being printed and the string representation of that same node. The return value of this function is used as the final string representation for that AST node. This function discards all formatting of the original code. #### Examples ``` iex> Macro.to_string(quote(do: foo.bar(1, 2, 3))) "foo.bar(1, 2, 3)" iex> Macro.to_string(quote(do: 1 + 2), fn ...> 1, _string -> "one" ...> 2, _string -> "two" ...> _ast, string -> string ...> end) "one + two" ``` ### traverse(ast, acc, pre, post) #### Specs ``` traverse(t(), any(), (t(), any() -> {t(), any()}), (t(), any() -> {t(), any()})) :: {t(), any()} ``` Performs a depth-first traversal of quoted expressions using an accumulator. ### underscore(atom) #### Specs ``` underscore(atom() | String.t()) :: String.t() ``` Converts the given atom or binary to underscore format. If an atom is given, it is assumed to be an Elixir module, so it is converted to a binary and then processed. This function was designed to underscore language identifiers/tokens, that's why it belongs to the [`Macro`](#content) module. Do not use it as a general mechanism for underscoring strings as it does not support Unicode or characters that are not valid in Elixir identifiers. #### Examples ``` iex> Macro.underscore("FooBar") "foo_bar" iex> Macro.underscore("Foo.Bar") "foo/bar" iex> Macro.underscore(Foo.Bar) "foo/bar" ``` In general, `underscore` can be thought of as the reverse of `camelize`, however, in some cases formatting may be lost: ``` iex> Macro.underscore("SAPExample") "sap_example" iex> Macro.camelize("sap_example") "SapExample" iex> Macro.camelize("hello_10") "Hello10" ``` ### unescape\_string(chars) #### Specs ``` unescape_string(String.t()) :: String.t() ``` Unescapes the given chars. This is the unescaping behaviour used by default in Elixir single- and double-quoted strings. Check [`unescape_string/2`](#unescape_string/2) for information on how to customize the escaping map. In this setup, Elixir will escape the following: `\0`, `\a`, `\b`, `\d`, `\e`, `\f`, `\n`, `\r`, `\s`, `\t` and `\v`. Bytes can be given as hexadecimals via `\xNN` and Unicode code points as `\uNNNN` escapes. This function is commonly used on sigil implementations (like `~r`, `~s` and others) which receive a raw, unescaped string. #### Examples ``` iex> Macro.unescape_string("example\\n") "example\n" ``` In the example above, we pass a string with `\n` escaped and return a version with it unescaped. ### unescape\_string(chars, map) #### Specs ``` unescape_string(String.t(), (non_neg_integer() -> non_neg_integer() | false)) :: String.t() ``` Unescapes the given chars according to the map given. Check [`unescape_string/1`](#unescape_string/1) if you want to use the same map as Elixir single- and double-quoted strings. #### Map The map must be a function. The function receives an integer representing the code point of the character it wants to unescape. Here is the default mapping function implemented by Elixir: ``` def unescape_map(unicode), do: true def unescape_map(hex), do: true def unescape_map(?0), do: ?0 def unescape_map(?a), do: ?\a def unescape_map(?b), do: ?\b def unescape_map(?d), do: ?\d def unescape_map(?e), do: ?\e def unescape_map(?f), do: ?\f def unescape_map(?n), do: ?\n def unescape_map(?r), do: ?\r def unescape_map(?s), do: ?\s def unescape_map(?t), do: ?\t def unescape_map(?v), do: ?\v def unescape_map(e), do: e ``` If the `unescape_map/1` function returns `false`, the char is not escaped and the backslash is kept in the string. Hexadecimals and Unicode code points will be escaped if the map function returns `true` for `?x`. Unicode code points if the map function returns `true` for `?u`. #### Examples Using the `unescape_map/1` function defined above is easy: ``` Macro.unescape_string("example\\n", &unescape_map(&1)) ``` ### unpipe(expr) #### Specs ``` unpipe(t()) :: [t()] ``` Breaks a pipeline expression into a list. The AST for a pipeline (a sequence of applications of `|>`) is similar to the AST of a sequence of binary operators or function applications: the top-level expression is the right-most `:|>` (which is the last one to be executed), and its left-hand and right-hand sides are its arguments: ``` quote do: 100 |> div(5) |> div(2) #=> {:|>, _, [arg1, arg2]} ``` In the example above, the `|>` pipe is the right-most pipe; `arg1` is the AST for `100 |> div(5)`, and `arg2` is the AST for `div(2)`. It's often useful to have the AST for such a pipeline as a list of function applications. This function does exactly that: ``` Macro.unpipe(quote do: 100 |> div(5) |> div(2)) #=> [{100, 0}, {{:div, [], [5]}, 0}, {{:div, [], [2]}, 0}] ``` We get a list that follows the pipeline directly: first the `100`, then the `div(5)` (more precisely, its AST), then `div(2)`. The `0` as the second element of the tuples is the position of the previous element in the pipeline inside the current function application: `{{:div, [], [5]}, 0}` means that the previous element (`100`) will be inserted as the 0th (first) argument to the [`div/2`](kernel#div/2) function, so that the AST for that function will become `{:div, [], [100, 5]}` (`div(100, 5)`). ### update\_meta(quoted, fun) #### Specs ``` update_meta(t(), (keyword() -> keyword())) :: t() ``` Applies the given function to the node metadata if it contains one. This is often useful when used with [`Macro.prewalk/2`](macro#prewalk/2) to remove information like lines and hygienic counters from the expression for either storage or comparison. #### Examples ``` iex> quoted = quote line: 10, do: sample() {:sample, [line: 10], []} iex> Macro.update_meta(quoted, &Keyword.delete(&1, :line)) {:sample, [], []} ``` ### validate(expr) #### Specs ``` validate(term()) :: :ok | {:error, term()} ``` Validates the given expressions are valid quoted expressions. Checks the [`Macro.t/0`](macro#t:t/0) for the specification of a valid quoted expression. It returns `:ok` if the expression is valid. Otherwise it returns a tuple in the form of `{:error, remainder}` where `remainder` is the invalid part of the quoted expression. #### Examples ``` iex> Macro.validate({:two_element, :tuple}) :ok iex> Macro.validate({:three, :element, :tuple}) {:error, {:three, :element, :tuple}} iex> Macro.validate([1, 2, 3]) :ok iex> Macro.validate([1, 2, 3, {4}]) {:error, {4}} ``` ### var(var, context) #### Specs ``` var(var, context) :: {var, [], context} when var: atom(), context: atom() ``` Generates an AST node representing the variable given by the atoms `var` and `context`. #### Examples In order to build a variable, a context is expected. Most of the times, in order to preserve hygiene, the context must be [`__MODULE__/0`](kernel.specialforms#__MODULE__/0): ``` iex> Macro.var(:foo, __MODULE__) {:foo, [], __MODULE__} ``` However, if there is a need to access the user variable, nil can be given: ``` iex> Macro.var(:foo, nil) {:foo, [], nil} ```
programming_docs
elixir Recursion Getting Started Recursion ========= Loops through recursion ----------------------- Due to immutability, loops in Elixir (as in any functional programming language) are written differently from imperative languages. For example, in an imperative language like C, one would write: ``` for(i = 0; i < sizeof(array); i++) { array[i] = array[i] * 2; } ``` In the example above, we are mutating both the array and the variable `i`. However, data structures in Elixir are immutable. For this reason, functional languages rely on recursion: a function is called recursively until a condition is reached that stops the recursive action from continuing. No data is mutated in this process. Consider the example below that prints a string an arbitrary number of times: ``` defmodule Recursion do def print_multiple_times(msg, n) when n <= 1 do IO.puts msg end def print_multiple_times(msg, n) do IO.puts msg print_multiple_times(msg, n - 1) end end Recursion.print_multiple_times("Hello!", 3) # Hello! # Hello! # Hello! ``` Similar to `case`, a function may have many clauses. A particular clause is executed when the arguments passed to the function match the clause’s argument patterns and its guard evaluates to `true`. When `print_multiple_times/2` is initially called in the example above, the argument `n` is equal to `3`. The first clause has a guard which says “use this definition if and only if `n` is less than or equal to `1`”. Since this is not the case, Elixir proceeds to the next clause’s definition. The second definition matches the pattern and has no guard so it will be executed. It first prints our `msg` and then calls itself passing `n - 1` (`2`) as the second argument. Our `msg` is printed and `print_multiple_times/2` is called again, this time with the second argument set to `1`. Because `n` is now set to `1`, the guard in our first definition of `print_multiple_times/2` evaluates to true, and we execute this particular definition. The `msg` is printed, and there is nothing left to execute. We defined `print_multiple_times/2` so that, no matter what number is passed as the second argument, it either triggers our first definition (known as a *base case*) or it triggers our second definition, which will ensure that we get exactly one step closer to our base case. Reduce and map algorithms ------------------------- Let’s now see how we can use the power of recursion to sum a list of numbers: ``` defmodule Math do def sum_list([head | tail], accumulator) do sum_list(tail, head + accumulator) end def sum_list([], accumulator) do accumulator end end IO.puts Math.sum_list([1, 2, 3], 0) #=> 6 ``` We invoke `sum_list` with the list `[1, 2, 3]` and the initial value `0` as arguments. We will try each clause until we find one that matches according to the pattern matching rules. In this case, the list `[1, 2, 3]` matches against `[head | tail]` which binds `head` to `1` and `tail` to `[2, 3]`; `accumulator` is set to `0`. Then, we add the head of the list to the accumulator `head + accumulator` and call `sum_list` again, recursively, passing the tail of the list as its first argument. The tail will once again match `[head | tail]` until the list is empty, as seen below: ``` sum_list [1, 2, 3], 0 sum_list [2, 3], 1 sum_list [3], 3 sum_list [], 6 ``` When the list is empty, it will match the final clause which returns the final result of `6`. The process of taking a list and *reducing* it down to one value is known as a *reduce algorithm* and is central to functional programming. What if we instead want to double all of the values in our list? ``` defmodule Math do def double_each([head | tail]) do [head * 2 | double_each(tail)] end def double_each([]) do [] end end ``` ``` $ iex math.exs ``` ``` iex> Math.double_each([1, 2, 3]) #=> [2, 4, 6] ``` Here we have used recursion to traverse a list, doubling each element and returning a new list. The process of taking a list and *mapping* over it is known as a *map algorithm*. Recursion and [tail call](https://en.wikipedia.org/wiki/Tail_call) optimization are an important part of Elixir and are commonly used to create loops. However, when programming in Elixir you will rarely use recursion as above to manipulate lists. The [`Enum` module](https://hexdocs.pm/elixir/Enum.html), which we’re going to see in the next chapter, already provides many conveniences for working with lists. For instance, the examples above could be written as: ``` iex> Enum.reduce([1, 2, 3], 0, fn(x, acc) -> x + acc end) 6 iex> Enum.map([1, 2, 3], fn(x) -> x * 2 end) [2, 4, 6] ``` Or, using the capture syntax: ``` iex> Enum.reduce([1, 2, 3], 0, &+/2) 6 iex> Enum.map([1, 2, 3], &(&1 * 2)) [2, 4, 6] ``` Let’s take a deeper look at `Enumerable` and, while we’re at it, its lazy counterpart, `Stream`. elixir Config Config ======= A simple keyword-based configuration API. Example -------- This module is most commonly used to define application configuration, typically in `config/config.exs`: ``` import Config config :some_app, key1: "value1", key2: "value2" import_config "#{Mix.env()}.exs" ``` `import Config` will import the functions [`config/2`](#config/2), [`config/3`](#config/3) and [`import_config/1`](#import_config/1) to help you manage your configuration. [`config/2`](#config/2) and [`config/3`](#config/3) are used to define key-value configuration for a given application. Once Mix starts, it will automatically evaluate the configuration file and persist the configuration above into `:some_app`'s application environment, which can be accessed in as follows: ``` "value1" = Application.fetch_env!(:some_app, :key1) ``` Finally, the line `import_config "#{Mix.env()}.exs"` will import other config files, based on the current Mix environment, such as `config/dev.exs` and `config/test.exs`. [`Config`](#content) also provides a low-level API for evaluating and reading configuration, under the [`Config.Reader`](config.reader) module. **Important:** if you are writing a library to be used by other developers, it is generally recommended to avoid the application environment, as the application environment is effectively a global storage. For more information, read our [library guidelines](library-guidelines). Migrating from `use Mix.Config` -------------------------------- The `Config` module in Elixir was introduced in v1.9 as a replacement to [`Mix.Config`](https://hexdocs.pm/mix/Mix.Config.html), which was specific to Mix and has been deprecated. You can leverage [`Config`](#content) instead of [`Mix.Config`](https://hexdocs.pm/mix/Mix.Config.html) in two steps. The first step is to replace `use Mix.Config` at the top of your config files by `import Config`. The second is to make sure your [`import_config/1`](#import_config/1) calls do not have a wildcard character. If so, you need to perform the wildcard lookup manually. For example, if you did: ``` import_config "../apps/*/config/config.exs" ``` It has to be replaced by: ``` for config <- "../apps/*/config/config.exs" |> Path.expand(__DIR__) |> Path.wildcard() do import_config config end ``` config/releases.exs -------------------- If you are using releases, see [`mix release`](https://hexdocs.pm/mix/Mix.Tasks.Release.html), there another configuration file called `config/releases.exs`. While `config/config.exs` and friends mentioned in the previous section are executed whenever you run a Mix command, including when you assemble a release, `config/releases.exs` is execute every time your production system boots. Since Mix is not available in a production system, `config/releases.exs` must not use any of the functions from Mix. Summary ======== Functions ---------- [config(root\_key, opts)](#config/2) Configures the given `root_key`. [config(root\_key, key, opts)](#config/3) Configures the given `key` for the given `root_key`. [import\_config(file)](#import_config/1) Imports configuration from the given file. Functions ========== ### config(root\_key, opts) Configures the given `root_key`. Keyword lists are always deep-merged. #### Examples The given `opts` are merged into the existing configuration for the given `root_key`. Conflicting keys are overridden by the ones specified in `opts`. For example, the application configuration below ``` config :logger, level: :warn, backends: [:console] config :logger, level: :info, truncate: 1024 ``` will have a final configuration for `:logger` of: ``` [level: :info, backends: [:console], truncate: 1024] ``` ### config(root\_key, key, opts) Configures the given `key` for the given `root_key`. Keyword lists are always deep merged. #### Examples The given `opts` are merged into the existing values for `key` in the given `root_key`. Conflicting keys are overridden by the ones specified in `opts`. For example, the application configuration below ``` config :ecto, Repo, log_level: :warn, adapter: Ecto.Adapters.Postgres config :ecto, Repo, log_level: :info, pool_size: 10 ``` will have a final value of the configuration for the `Repo` key in the `:ecto` application of: ``` [log_level: :info, pool_size: 10, adapter: Ecto.Adapters.Postgres] ``` ### import\_config(file) Imports configuration from the given file. In case the file doesn't exist, an error is raised. If file is a relative, it will be expanded relatively to the directory the current configuration file is in. #### Examples This is often used to emulate configuration across environments: ``` import_config "#{Mix.env()}.exs" ``` elixir Task Task ===== Conveniences for spawning and awaiting tasks. Tasks are processes meant to execute one particular action throughout their lifetime, often with little or no communication with other processes. The most common use case for tasks is to convert sequential code into concurrent code by computing a value asynchronously: ``` task = Task.async(fn -> do_some_work() end) res = do_some_other_work() res + Task.await(task) ``` Tasks spawned with `async` can be awaited on by their caller process (and only their caller) as shown in the example above. They are implemented by spawning a process that sends a message to the caller once the given computation is performed. Besides [`async/1`](#async/1) and [`await/2`](#await/2), tasks can also be started as part of a supervision tree and dynamically spawned on remote nodes. We will explore all three scenarios next. async and await ---------------- One of the common uses of tasks is to convert sequential code into concurrent code with [`Task.async/1`](task#async/1) while keeping its semantics. When invoked, a new process will be created, linked and monitored by the caller. Once the task action finishes, a message will be sent to the caller with the result. [`Task.await/2`](task#await/2) is used to read the message sent by the task. There are two important things to consider when using `async`: 1. If you are using async tasks, you **must await** a reply as they are *always* sent. If you are not expecting a reply, consider using [`Task.start_link/1`](task#start_link/1) detailed below. 2. async tasks link the caller and the spawned process. This means that, if the caller crashes, the task will crash too and vice-versa. This is on purpose: if the process meant to receive the result no longer exists, there is no purpose in completing the computation. If this is not desired, use [`Task.start/1`](task#start/1) or consider starting the task under a [`Task.Supervisor`](task.supervisor) using `async_nolink` or `start_child`. [`Task.yield/2`](task#yield/2) is an alternative to [`await/2`](#await/2) where the caller will temporarily block, waiting until the task replies or crashes. If the result does not arrive within the timeout, it can be called again at a later moment. This allows checking for the result of a task multiple times. If a reply does not arrive within the desired time, [`Task.shutdown/2`](task#shutdown/2) can be used to stop the task. Supervised tasks ----------------- It is also possible to spawn a task under a supervisor. The [`Task`](#content) module implements the [`child_spec/1`](#child_spec/1) function, which allows it to be started directly under a supervisor by passing a tuple with a function to run: ``` Supervisor.start_link([ {Task, fn -> :some_work end} ], strategy: :one_for_one) ``` However, if you want to invoke a specific module, function and arguments, or give the task process a name, you need to define the task in its own module: ``` defmodule MyTask do use Task def start_link(arg) do Task.start_link(__MODULE__, :run, [arg]) end def run(arg) do # ... end end ``` And then passing it to the supervisor: ``` Supervisor.start_link([ {MyTask, arg} ], strategy: :one_for_one) ``` Since these tasks are supervised and not directly linked to the caller, they cannot be awaited on. [`start_link/1`](#start_link/1), unlike [`async/1`](#async/1), returns `{:ok, pid}` (which is the result expected by supervisors). `use Task` defines a [`child_spec/1`](#child_spec/1) function, allowing the defined module to be put under a supervision tree. The generated [`child_spec/1`](#child_spec/1) can be customized with the following options: * `:id` - the child specification identifier, defaults to the current module * `:restart` - when the child should be restarted, defaults to `:temporary` * `:shutdown` - how to shut down the child, either immediately or by giving it time to shut down Opposite to [`GenServer`](genserver), [`Agent`](agent) and [`Supervisor`](supervisor), a Task has a default `:restart` of `:temporary`. This means the task will not be restarted even if it crashes. If you desire the task to be restarted for non-successful exits, do: ``` use Task, restart: :transient ``` If you want the task to always be restarted: ``` use Task, restart: :permanent ``` See the "Child specification" section in the [`Supervisor`](supervisor) module for more detailed information. The `@doc` annotation immediately preceding `use Task` will be attached to the generated [`child_spec/1`](#child_spec/1) function. Dynamically supervised tasks ----------------------------- The [`Task.Supervisor`](task.supervisor) module allows developers to dynamically create multiple supervised tasks. A short example is: ``` {:ok, pid} = Task.Supervisor.start_link() task = Task.Supervisor.async(pid, fn -> # Do something end) Task.await(task) ``` However, in the majority of cases, you want to add the task supervisor to your supervision tree: ``` Supervisor.start_link([ {Task.Supervisor, name: MyApp.TaskSupervisor} ], strategy: :one_for_one) ``` Now you can dynamically start supervised tasks: ``` Task.Supervisor.start_child(MyApp.TaskSupervisor, fn -> # Do something end) ``` Or even use the async/await pattern: ``` Task.Supervisor.async(MyApp.TaskSupervisor, fn -> # Do something end) |> Task.await() ``` Finally, check [`Task.Supervisor`](task.supervisor) for other supported operations. Distributed tasks ------------------ Since Elixir provides a [`Task.Supervisor`](task.supervisor), it is easy to use one to dynamically start tasks across nodes: ``` # On the remote node Task.Supervisor.start_link(name: MyApp.DistSupervisor) # On the client supervisor = {MyApp.DistSupervisor, :remote@local} Task.Supervisor.async(supervisor, MyMod, :my_fun, [arg1, arg2, arg3]) ``` Note that, when working with distributed tasks, one should use the [`Task.Supervisor.async/4`](task.supervisor#async/4) function that expects explicit module, function and arguments, instead of [`Task.Supervisor.async/2`](task.supervisor#async/2) that works with anonymous functions. That's because anonymous functions expect the same module version to exist on all involved nodes. Check the [`Agent`](agent) module documentation for more information on distributed processes as the limitations described there apply to the whole ecosystem. Ancestor and Caller Tracking ----------------------------- Whenever you start a new process, Elixir annotates the parent of that process through the `$ancestors` key in the process dictionary. This is often used to track the hierarchy inside a supervision tree. For example, we recommend developers to always start tasks under a supervisor. This provides more visibility and allows you to control how those tasks are terminated when a node shuts down. That might look something like `Task.Supervisor.start_child(MySupervisor, task_specification)`. This means that, although your code is the one who invokes the task, the actual ancestor of the task is the supervisor, as the supervisor is the one effectively starting it. To track the relationship between your code and the task, we use the `$callers` key in the process dictionary. Therefore, assuming the [`Task.Supervisor`](task.supervisor) call above, we have: ``` [your code] -- calls --> [supervisor] ---- spawns --> [task] ``` Which means we store the following relationships: ``` [your code] [supervisor] <-- ancestor -- [task] ^ | |--------------------- caller ---------------------| ``` The list of callers of the current process can be retrieved from the Process dictionary with `Process.get(:"$callers")`. This will return either `nil` or a list `[pid_n, ..., pid2, pid1]` with at least one entry Where `pid_n` is the PID that called the current process, `pid2` called `pid_n`, and `pid2` was called by `pid1`. Summary ======== Types ------ [t()](#t:t/0) The Task type. Functions ---------- [%Task{}](#__struct__/0) The Task struct. [async(fun)](#async/1) Starts a task that must be awaited on. [async(module, function\_name, args)](#async/3) Starts a task that must be awaited on. [async\_stream(enumerable, fun, options \\ [])](#async_stream/3) Returns a stream that runs the given function `fun` concurrently on each element in `enumerable`. [async\_stream(enumerable, module, function\_name, args, options \\ [])](#async_stream/5) Returns a stream where the given function (`module` and `function_name`) is mapped concurrently on each element in `enumerable`. [await(task, timeout \\ 5000)](#await/2) Awaits a task reply and returns it. [child\_spec(arg)](#child_spec/1) Returns a specification to start a task under a supervisor. [shutdown(task, shutdown \\ 5000)](#shutdown/2) Unlinks and shuts down the task, and then checks for a reply. [start(fun)](#start/1) Starts a task. [start(module, function\_name, args)](#start/3) Starts a task. [start\_link(fun)](#start_link/1) Starts a process linked to the current process. [start\_link(module, function\_name, args)](#start_link/3) Starts a task as part of a supervision tree. [yield(task, timeout \\ 5000)](#yield/2) Temporarily blocks the current process waiting for a task reply. [yield\_many(tasks, timeout \\ 5000)](#yield_many/2) Yields to multiple tasks in the given time interval. Types ====== ### t() #### Specs ``` t() :: %Task{owner: pid() | nil, pid: pid() | nil, ref: reference() | nil} ``` The Task type. See `%Task{}` for information about each field of the structure. Functions ========== ### %Task{} The Task struct. It contains these fields: * `:pid` - the PID of the task process; `nil` if the task does not use a task process * `:ref` - the task monitor reference * `:owner` - the PID of the process that started the task ### async(fun) #### Specs ``` async((() -> any())) :: t() ``` Starts a task that must be awaited on. `fun` must be a zero-arity anonymous function. This function spawns a process that is linked to and monitored by the caller process. A [`Task`](#content) struct is returned containing the relevant information. Read the [`Task`](#content) module documentation for more information about the general usage of [`async/1`](#async/1) and [`async/3`](#async/3). See also [`async/3`](#async/3). ### async(module, function\_name, args) #### Specs ``` async(module(), atom(), [term()]) :: t() ``` Starts a task that must be awaited on. A [`Task`](#content) struct is returned containing the relevant information. Developers must eventually call [`Task.await/2`](task#await/2) or [`Task.yield/2`](task#yield/2) followed by [`Task.shutdown/2`](task#shutdown/2) on the returned task. Read the [`Task`](#content) module documentation for more information about the general usage of [`async/1`](#async/1) and [`async/3`](#async/3). #### Linking This function spawns a process that is linked to and monitored by the caller process. The linking part is important because it aborts the task if the parent process dies. It also guarantees the code before async/await has the same properties after you add the async call. For example, imagine you have this: ``` x = heavy_fun() y = some_fun() x + y ``` Now you want to make the `heavy_fun()` async: ``` x = Task.async(&heavy_fun/0) y = some_fun() Task.await(x) + y ``` As before, if `heavy_fun/0` fails, the whole computation will fail, including the parent process. If you don't want the task to fail then you must change the `heavy_fun/0` code in the same way you would achieve it if you didn't have the async call. For example, to either return `{:ok, val} | :error` results or, in more extreme cases, by using `try/rescue`. In other words, an asynchronous task should be thought of as an extension of a process rather than a mechanism to isolate it from all errors. If you don't want to link the caller to the task, then you must use a supervised task with [`Task.Supervisor`](task.supervisor) and call [`Task.Supervisor.async_nolink/2`](task.supervisor#async_nolink/2). In any case, avoid any of the following: * Setting `:trap_exit` to `true` - trapping exits should be used only in special circumstances as it would make your process immune to not only exits from the task but from any other processes. Moreover, even when trapping exits, calling `await` will still exit if the task has terminated without sending its result back. * Unlinking the task process started with `async`/`await`. If you unlink the processes and the task does not belong to any supervisor, you may leave dangling tasks in case the parent dies. #### Message format The reply sent by the task will be in the format `{ref, result}`, where `ref` is the monitor reference held by the task struct and `result` is the return value of the task function. ### async\_stream(enumerable, fun, options \\ []) #### Specs ``` async_stream(Enumerable.t(), (term() -> term()), keyword()) :: Enumerable.t() ``` Returns a stream that runs the given function `fun` concurrently on each element in `enumerable`. Works the same as [`async_stream/5`](#async_stream/5) but with an anonymous function instead of a module-function-arguments tuple. `fun` must be a one-arity anonymous function. Each `enumerable` element is passed as argument to the given function `fun` and processed by its own task. The tasks will be linked to the current process, similarly to [`async/1`](#async/1). #### Example Count the code points in each string asynchronously, then add the counts together using reduce. ``` iex> strings = ["long string", "longer string", "there are many of these"] iex> stream = Task.async_stream(strings, fn text -> text |> String.codepoints() |> Enum.count() end) iex> Enum.reduce(stream, 0, fn {:ok, num}, acc -> num + acc end) 47 ``` See [`async_stream/5`](#async_stream/5) for discussion, options, and more examples. ### async\_stream(enumerable, module, function\_name, args, options \\ []) #### Specs ``` async_stream(Enumerable.t(), module(), atom(), [term()], keyword()) :: Enumerable.t() ``` Returns a stream where the given function (`module` and `function_name`) is mapped concurrently on each element in `enumerable`. Each element of `enumerable` will be prepended to the given `args` and processed by its own task. The tasks will be linked to an intermediate process that is then linked to the current process. This means a failure in a task terminates the current process and a failure in the current process terminates all tasks. When streamed, each task will emit `{:ok, value}` upon successful completion or `{:exit, reason}` if the caller is trapping exits. The order of results depends on the value of the `:ordered` option. The level of concurrency and the time tasks are allowed to run can be controlled via options (see the "Options" section below). Consider using [`Task.Supervisor.async_stream/6`](task.supervisor#async_stream/6) to start tasks under a supervisor. If you find yourself trapping exits to handle exits inside the async stream, consider using [`Task.Supervisor.async_stream_nolink/6`](task.supervisor#async_stream_nolink/6) to start tasks that are not linked to the calling process. #### Options * `:max_concurrency` - sets the maximum number of tasks to run at the same time. Defaults to [`System.schedulers_online/0`](system#schedulers_online/0). * `:ordered` - whether the results should be returned in the same order as the input stream. This option is useful when you have large streams and don't want to buffer results before they are delivered. This is also useful when you're using the tasks for side effects. Defaults to `true`. * `:timeout` - the maximum amount of time (in milliseconds) each task is allowed to execute for. Defaults to `5000`. * `:on_timeout` - what to do when a task times out. The possible values are: + `:exit` (default) - the process that spawned the tasks exits. + `:kill_task` - the task that timed out is killed. The value emitted for that task is `{:exit, :timeout}`. #### Example Let's build a stream and then enumerate it: ``` stream = Task.async_stream(collection, Mod, :expensive_fun, []) Enum.to_list(stream) ``` The concurrency can be increased or decreased using the `:max_concurrency` option. For example, if the tasks are IO heavy, the value can be increased: ``` max_concurrency = System.schedulers_online() * 2 stream = Task.async_stream(collection, Mod, :expensive_fun, [], max_concurrency: max_concurrency) Enum.to_list(stream) ``` If you do not care about the results of the computation, you can run the stream with [`Stream.run/1`](stream#run/1). Also set `ordered: false`, as you don't care about the order of the results either: ``` stream = Task.async_stream(collection, Mod, :expensive_fun, [], ordered: false) Stream.run(stream) ``` ### await(task, timeout \\ 5000) #### Specs ``` await(t(), timeout()) :: term() ``` Awaits a task reply and returns it. In case the task process dies, the current process will exit with the same reason as the task. A timeout in milliseconds or `:infinity`, can be given with a default value of `5000`. If the timeout is exceeded, then the current process will exit. If the task process is linked to the current process which is the case when a task is started with `async`, then the task process will also exit. If the task process is trapping exits or not linked to the current process, then it will continue to run. This function assumes the task's monitor is still active or the monitor's `:DOWN` message is in the message queue. If it has been demonitored, or the message already received, this function will wait for the duration of the timeout awaiting the message. This function can only be called once for any given task. If you want to be able to check multiple times if a long-running task has finished its computation, use [`yield/2`](#yield/2) instead. #### Compatibility with OTP behaviours It is not recommended to `await` a long-running task inside an OTP behaviour such as [`GenServer`](genserver). Instead, you should match on the message coming from a task inside your [`GenServer.handle_info/2`](genserver#c:handle_info/2) callback. For more information on the format of the message, see the documentation for [`async/1`](#async/1). #### Examples ``` iex> task = Task.async(fn -> 1 + 1 end) iex> Task.await(task) 2 ``` ### child\_spec(arg) #### Specs ``` child_spec(term()) :: Supervisor.child_spec() ``` Returns a specification to start a task under a supervisor. `arg` is passed as the argument to [`Task.start_link/1`](task#start_link/1) in the `:start` field of the spec. For more information, see the [`Supervisor`](supervisor) module, the [`Supervisor.child_spec/2`](supervisor#child_spec/2) function and the [`Supervisor.child_spec/0`](supervisor#t:child_spec/0) type. ### shutdown(task, shutdown \\ 5000) #### Specs ``` shutdown(t(), timeout() | :brutal_kill) :: {:ok, term()} | {:exit, term()} | nil ``` Unlinks and shuts down the task, and then checks for a reply. Returns `{:ok, reply}` if the reply is received while shutting down the task, `{:exit, reason}` if the task died, otherwise `nil`. The second argument is either a timeout or `:brutal_kill`. In case of a timeout, a `:shutdown` exit signal is sent to the task process and if it does not exit within the timeout, it is killed. With `:brutal_kill` the task is killed straight away. In case the task terminates abnormally (possibly killed by another process), this function will exit with the same reason. It is not required to call this function when terminating the caller, unless exiting with reason `:normal` or if the task is trapping exits. If the caller is exiting with a reason other than `:normal` and the task is not trapping exits, the caller's exit signal will stop the task. The caller can exit with reason `:shutdown` to shut down all of its linked processes, including tasks, that are not trapping exits without generating any log messages. If a task's monitor has already been demonitored or received and there is not a response waiting in the message queue this function will return `{:exit, :noproc}` as the result or exit reason can not be determined. ### start(fun) #### Specs ``` start((() -> any())) :: {:ok, pid()} ``` Starts a task. `fun` must be a zero-arity anonymous function. This is only used when the task is used for side-effects (i.e. no interest in the returned result) and it should not be linked to the current process. ### start(module, function\_name, args) #### Specs ``` start(module(), atom(), [term()]) :: {:ok, pid()} ``` Starts a task. This is only used when the task is used for side-effects (i.e. no interest in the returned result) and it should not be linked to the current process. ### start\_link(fun) #### Specs ``` start_link((() -> any())) :: {:ok, pid()} ``` Starts a process linked to the current process. `fun` must be a zero-arity anonymous function. This is often used to start the process as part of a supervision tree. ### start\_link(module, function\_name, args) #### Specs ``` start_link(module(), atom(), [term()]) :: {:ok, pid()} ``` Starts a task as part of a supervision tree. ### yield(task, timeout \\ 5000) #### Specs ``` yield(t(), timeout()) :: {:ok, term()} | {:exit, term()} | nil ``` Temporarily blocks the current process waiting for a task reply. Returns `{:ok, reply}` if the reply is received, `nil` if no reply has arrived, or `{:exit, reason}` if the task has already exited. Keep in mind that normally a task failure also causes the process owning the task to exit. Therefore this function can return `{:exit, reason}` only if * the task process exited with the reason `:normal` * it isn't linked to the caller * the caller is trapping exits A timeout, in milliseconds or `:infinity`, can be given with a default value of `5000`. If the time runs out before a message from the task is received, this function will return `nil` and the monitor will remain active. Therefore [`yield/2`](#yield/2) can be called multiple times on the same task. This function assumes the task's monitor is still active or the monitor's `:DOWN` message is in the message queue. If it has been demonitored or the message already received, this function will wait for the duration of the timeout awaiting the message. If you intend to shut the task down if it has not responded within `timeout` milliseconds, you should chain this together with [`shutdown/1`](#shutdown/1), like so: ``` case Task.yield(task, timeout) || Task.shutdown(task) do {:ok, result} -> result nil -> Logger.warn("Failed to get a result in #{timeout}ms") nil end ``` That ensures that if the task completes after the `timeout` but before [`shutdown/1`](#shutdown/1) has been called, you will still get the result, since [`shutdown/1`](#shutdown/1) is designed to handle this case and return the result. ### yield\_many(tasks, timeout \\ 5000) #### Specs ``` yield_many([t()], timeout()) :: [{t(), {:ok, term()} | {:exit, term()} | nil}] ``` Yields to multiple tasks in the given time interval. This function receives a list of tasks and waits for their replies in the given time interval. It returns a list of two-element tuples, with the task as the first element and the yielded result as the second. The tasks in the returned list will be in the same order as the tasks supplied in the `tasks` input argument. Similarly to [`yield/2`](#yield/2), each task's result will be * `{:ok, term}` if the task has successfully reported its result back in the given time interval * `{:exit, reason}` if the task has died * `nil` if the task keeps running past the timeout A timeout, in milliseconds or `:infinity`, can be given with a default value of `5000`. Check [`yield/2`](#yield/2) for more information. #### Example [`Task.yield_many/2`](task#yield_many/2) allows developers to spawn multiple tasks and retrieve the results received in a given timeframe. If we combine it with [`Task.shutdown/2`](task#shutdown/2), it allows us to gather those results and cancel the tasks that have not replied in time. Let's see an example. ``` tasks = for i <- 1..10 do Task.async(fn -> Process.sleep(i * 1000) i end) end tasks_with_results = Task.yield_many(tasks, 5000) results = Enum.map(tasks_with_results, fn {task, res} -> # Shut down the tasks that did not reply nor exit res || Task.shutdown(task, :brutal_kill) end) # Here we are matching only on {:ok, value} and # ignoring {:exit, _} (crashed tasks) and `nil` (no replies) for {:ok, value} <- results do IO.inspect(value) end ``` In the example above, we create tasks that sleep from 1 up to 10 seconds and return the number of seconds they slept for. If you execute the code all at once, you should see 1 up to 5 printed, as those were the tasks that have replied in the given time. All other tasks will have been shut down using the [`Task.shutdown/2`](task#shutdown/2) call.
programming_docs
elixir Basic types Getting Started Basic types =========== In this chapter we will learn more about Elixir basic types: integers, floats, booleans, atoms, strings, lists and tuples. Some basic types are: ``` iex> 1 # integer iex> 0x1F # integer iex> 1.0 # float iex> true # boolean iex> :atom # atom / symbol iex> "elixir" # string iex> [1, 2, 3] # list iex> {1, 2, 3} # tuple ``` Basic arithmetic ---------------- Open up `iex` and type the following expressions: ``` iex> 1 + 2 3 iex> 5 * 5 25 iex> 10 / 2 5.0 ``` Notice that `10 / 2` returned a float `5.0` instead of an integer `5`. This is expected. In Elixir, the operator `/` always returns a float. If you want to do integer division or get the division remainder, you can invoke the `div` and `rem` functions: ``` iex> div(10, 2) 5 iex> div 10, 2 5 iex> rem 10, 3 1 ``` Notice that Elixir allows you to drop the parentheses when invoking named functions. This feature gives a cleaner syntax when writing declarations and control-flow constructs. Elixir also supports shortcut notations for entering binary, octal, and hexadecimal numbers: ``` iex> 0b1010 10 iex> 0o777 511 iex> 0x1F 31 ``` Float numbers require a dot followed by at least one digit and also support `e` for scientific notation: ``` iex> 1.0 1.0 iex> 1.0e-10 1.0e-10 ``` Floats in Elixir are 64-bit double precision. You can invoke the `round` function to get the closest integer to a given float, or the `trunc` function to get the integer part of a float. ``` iex> round(3.58) 4 iex> trunc(3.58) 3 ``` Identifying functions and documentation --------------------------------------- Functions in Elixir are identified by both their name and their arity. The arity of a function describes the number of arguments that the function takes. From this point on we will use both the function name and its arity to describe functions throughout the documentation. `round/1` identifies the function which is named `round` and takes `1` argument, whereas `round/2` identifies a different (nonexistent) function with the same name but with an arity of `2`. We can also use this syntax to access documentation. The Elixir shell defines the `h` function, which you can use to access documentation for any function. For example, typing `h round/1` is going to print the documentation for the `round/1` function: ``` iex> h round/1 def round() Rounds a number to the nearest integer. ``` `h round/1` works because it is defined in `Kernel` module. All functions in the `Kernel` module are automatically imported into our namespace. Most often you will also include the module name when looking up for documentation for a given function: ``` iex> h Kernel.round/1 def round() Rounds a number to the nearest integer. ``` You can use the module+function to lookup for anything, including operators (try `h Kernel.+/2`). Invoking `h` without arguments displays the documentation for `IEx.Helpers`, which is where `h` and other functionality is defined. Booleans -------- Elixir supports `true` and `false` as booleans: ``` iex> true true iex> true == false false ``` Elixir provides a bunch of predicate functions to check for a value type. For example, the `is_boolean/1` function can be used to check if a value is a boolean or not: ``` iex> is_boolean(true) true iex> is_boolean(1) false ``` You can also use `is_integer/1`, `is_float/1` or `is_number/1` to check, respectively, if an argument is an integer, a float, or either. Atoms ----- An atom is a constant whose value is its own name. Some other languages call these symbols. They are often useful to enumerate over distinct values, such as: ``` iex> :apple :apple iex> :orange :orange iex> :watermelon :watermelon ``` Atoms are equal if their names are equal. ``` iex> :apple == :apple true iex> :apple == :orange false ``` Often they are used to express the state of an operation, by using values such as `:ok` and `:error`. The booleans `true` and `false` are also atoms: ``` iex> true == :true true iex> is_atom(false) true iex> is_boolean(:false) true ``` Elixir allows you to skip the leading `:` for the atoms `false`, `true` and `nil`. Finally, Elixir has a construct called aliases which we will explore later. Aliases start in upper case and are also atoms: ``` iex> is_atom(Hello) true ``` Strings ------- Strings in Elixir are delimited by double quotes, and they are encoded in UTF-8: ``` iex> "hellö" "hellö" ``` > Note: if you are running on Windows, there is a chance your terminal does not use UTF-8 by default. You can change the encoding of your current session by running `chcp 65001` before entering IEx. > > Elixir also supports string interpolation: ``` iex> string = :world iex> "hellö #{string}" "hellö world" ``` Strings can have line breaks in them. You can introduce them using escape sequences: ``` iex> "hello ...> world" "hello\nworld" iex> "hello\nworld" "hello\nworld" ``` You can print a string using the `IO.puts/1` function from the `IO` module: ``` iex> IO.puts "hello\nworld" hello world :ok ``` Notice that the `IO.puts/1` function returns the atom `:ok` after printing. Strings in Elixir are represented internally by contiguous sequences of bytes known as binaries: ``` iex> is_binary("hellö") true ``` We can also get the number of bytes in a string: ``` iex> byte_size("hellö") 6 ``` Notice that the number of bytes in that string is 6, even though it has 5 graphemes. That’s because the grapheme “ö” takes 2 bytes to be represented in UTF-8. We can get the actual length of the string, based on the number of graphemes, by using the `String.length/1` function: ``` iex> String.length("hellö") 5 ``` The [String module](https://hexdocs.pm/elixir/String.html) contains a bunch of functions that operate on strings as defined in the Unicode standard: ``` iex> String.upcase("hellö") "HELLÖ" ``` Anonymous functions ------------------- Elixir also provides anonymous functions. Anonymous functions allow us to store and pass executable code around as if it was an integer or a string. They are delimited by the keywords `fn` and `end`: ``` iex> add = fn a, b -> a + b end #Function<12.71889879/2 in :erl_eval.expr/5> iex> add.(1, 2) 3 iex> is_function(add) true ``` In the example above, we defined an anonymous function that receives two arguments, `a` and `b`, and returns the result of `a + b`. The arguments are always on the left-hand side of `->` and the code to be executed on the right-hand side. The anonymous function is stored in the variable `add`. Parenthesised arguments after the anonymous function indicate that we want the function to be evaluated, not just its definition returned. Note that a dot (`.`) between the variable and parentheses is required to invoke an anonymous function. The dot ensures there is no ambiguity between calling the anonymous function matched to a variable `add` and a named function `add/2`. We will explore named functions when dealing with [Modules and Functions](modules-and-functions), since named functions can only be defined within a module. For now, just remember that Elixir makes a clear distinction between anonymous functions and named functions. Anonymous functions in Elixir are also identified by the number of arguments they receive. We can check if a function is of any given arity by using `is_function/2`: ``` # check if add is a function that expects exactly 2 arguments iex> is_function(add, 2) true # check if add is a function that expects exactly 1 argument iex> is_function(add, 1) false ``` Finally, anonymous functions are also closures and as such they can access variables that are in scope when the function is defined. Let’s define a new anonymous function that uses the `add` anonymous function we have previously defined: ``` iex> double = fn a -> add.(a, a) end #Function<6.71889879/1 in :erl_eval.expr/5> iex> double.(2) 4 ``` A variable assigned inside a function does not affect its surrounding environment: ``` iex> x = 42 42 iex> (fn -> x = 0 end).() 0 iex> x 42 ``` (Linked) Lists -------------- Elixir uses square brackets to specify a list of values. Values can be of any type: ``` iex> [1, 2, true, 3] [1, 2, true, 3] iex> length [1, 2, 3] 3 ``` Two lists can be concatenated or subtracted using the `++/2` and `--/2` operators respectively: ``` iex> [1, 2, 3] ++ [4, 5, 6] [1, 2, 3, 4, 5, 6] iex> [1, true, 2, false, 3, true] -- [true, false] [1, 2, 3, true] ``` List operators never modify the existing list. Concatenating to or removing elements from a list returns a new list. We say that Elixir data structures are *immutable*. One advantage of immutability is that it leads to clearer code. You can freely pass the data around with the guarantee no one will mutate it in memory - only transform it. Throughout the tutorial, we will talk a lot about the head and tail of a list. The head is the first element of a list and the tail is the remainder of the list. They can be retrieved with the functions `hd/1` and `tl/1`. Let’s assign a list to a variable and retrieve its head and tail: ``` iex> list = [1, 2, 3] iex> hd(list) 1 iex> tl(list) [2, 3] ``` Getting the head or the tail of an empty list throws an error: ``` iex> hd [] ** (ArgumentError) argument error ``` Sometimes you will create a list and it will return a value in single quotes. For example: ``` iex> [11, 12, 13] '\v\f\r' iex> [104, 101, 108, 108, 111] 'hello' ``` When Elixir sees a list of printable ASCII numbers, Elixir will print that as a charlist (literally a list of characters). Charlists are quite common when interfacing with existing Erlang code. Whenever you see a value in IEx and you are not quite sure what it is, you can use the `i/1` to retrieve information about it: ``` iex> i 'hello' Term 'hello' Data type List Description ... Raw representation [104, 101, 108, 108, 111] Reference modules List Implemented protocols ... ``` Keep in mind single-quoted and double-quoted representations are not equivalent in Elixir as they are represented by different types: ``` iex> 'hello' == "hello" false ``` Single quotes are charlists, double quotes are strings. We will talk more about them in the [“Binaries, strings and charlists”](binaries-strings-and-char-lists) chapter. Tuples ------ Elixir uses curly brackets to define tuples. Like lists, tuples can hold any value: ``` iex> {:ok, "hello"} {:ok, "hello"} iex> tuple_size {:ok, "hello"} 2 ``` Tuples store elements contiguously in memory. This means accessing a tuple element by index or getting the tuple size is a fast operation. Indexes start from zero: ``` iex> tuple = {:ok, "hello"} {:ok, "hello"} iex> elem(tuple, 1) "hello" iex> tuple_size(tuple) 2 ``` It is also possible to put an element at a particular index in a tuple with `put_elem/3`: ``` iex> tuple = {:ok, "hello"} {:ok, "hello"} iex> put_elem(tuple, 1, "world") {:ok, "world"} iex> tuple {:ok, "hello"} ``` Notice that `put_elem/3` returned a new tuple. The original tuple stored in the `tuple` variable was not modified. Like lists, tuples are also immutable. Every operation on a tuple returns a new tuple, it never changes the given one. Lists or tuples? ---------------- What is the difference between lists and tuples? Lists are stored in memory as linked lists, meaning that each element in a list holds its value and points to the following element until the end of the list is reached. This means accessing the length of a list is a linear operation: we need to traverse the whole list in order to figure out its size. Similarly, the performance of list concatenation depends on the length of the left-hand list: ``` iex> list = [1, 2, 3] # This is fast as we only need to traverse `[0]` to prepend to `list` iex> [0] ++ list [0, 1, 2, 3] # This is slow as we need to traverse `list` to append 4 iex> list ++ [4] [1, 2, 3, 4] ``` Tuples, on the other hand, are stored contiguously in memory. This means getting the tuple size or accessing an element by index is fast. However, updating or adding elements to tuples is expensive because it requires creating a new tuple in memory: ``` iex> tuple = {:a, :b, :c, :d} iex> put_elem(tuple, 2, :e) {:a, :b, :e, :d} ``` Note that this applies only to the tuple itself, not its contents. For instance, when you update a tuple, all entries are shared between the old and the new tuple, except for the entry that has been replaced. In other words, tuples and lists in Elixir are capable of sharing their contents. This reduces the amount of memory allocation the language needs to perform and is only possible thanks to the immutable semantics of the language. Those performance characteristics dictate the usage of those data structures. One very common use case for tuples is to use them to return extra information from a function. For example, `File.read/1` is a function that can be used to read file contents. It returns a tuple: ``` iex> File.read("path/to/existing/file") {:ok, "... contents ..."} iex> File.read("path/to/unknown/file") {:error, :enoent} ``` If the path given to `File.read/1` exists, it returns a tuple with the atom `:ok` as the first element and the file contents as the second. Otherwise, it returns a tuple with `:error` and the error description. Most of the time, Elixir is going to guide you to do the right thing. For example, there is an `elem/2` function to access a tuple item but there is no built-in equivalent for lists: ``` iex> tuple = {:ok, "hello"} {:ok, "hello"} iex> elem(tuple, 1) "hello" ``` When counting the elements in a data structure, Elixir also abides by a simple rule: the function is named `size` if the operation is in constant time (i.e. the value is pre-calculated) or `length` if the operation is linear (i.e. calculating the length gets slower as the input grows). As a mnemonic, both “length” and “linear” start with “l”. For example, we have used 4 counting functions so far: `byte_size/1` (for the number of bytes in a string), `tuple_size/1` (for tuple size), `length/1` (for list length) and `String.length/1` (for the number of graphemes in a string). We use `byte_size` to get the number of bytes in a string – a cheap operation. Retrieving the number of Unicode graphemes, on the other hand, uses `String.length`, and may be expensive as it relies on a traversal of the entire string. Elixir also provides `Port`, `Reference`, and `PID` as data types (usually used in process communication), and we will take a quick look at them when talking about processes. For now, let’s take a look at some of the basic operators that go with our basic types. elixir Range Range ====== Defines a range. A range represents a sequence of one or many, ascending or descending, consecutive integers. Ranges can be either increasing (`first <= last`) or decreasing (`first > last`). Ranges are also always inclusive. A range is represented internally as a struct. However, the most common form of creating and matching on ranges is via the [`../2`](kernel#../2) macro, auto-imported from [`Kernel`](kernel): ``` iex> range = 1..3 1..3 iex> first..last = range iex> first 1 iex> last 3 ``` A range implements the [`Enumerable`](enumerable) protocol, which means functions in the [`Enum`](enum) module can be used to work with ranges: ``` iex> range = 1..10 1..10 iex> Enum.reduce(range, 0, fn i, acc -> i * i + acc end) 385 iex> Enum.count(range) 10 iex> Enum.member?(range, 11) false iex> Enum.member?(range, 8) true ``` Such function calls are efficient memory-wise no matter the size of the range. The implementation of the [`Enumerable`](enumerable) protocol uses logic based solely on the endpoints and does not materialize the whole list of integers. Summary ======== Types ------ [t()](#t:t/0) [t(first, last)](#t:t/2) Functions ---------- [disjoint?(range1, range2)](#disjoint?/2) Checks if two ranges are disjoint. [new(first, last)](#new/2) Creates a new range. Types ====== ### t() #### Specs ``` t() :: %Range{first: integer(), last: integer()} ``` ### t(first, last) #### Specs ``` t(first, last) :: %Range{first: first, last: last} ``` Functions ========== ### disjoint?(range1, range2) #### Specs ``` disjoint?(t(), t()) :: boolean() ``` Checks if two ranges are disjoint. #### Examples ``` iex> Range.disjoint?(1..5, 6..9) true iex> Range.disjoint?(5..1, 6..9) true iex> Range.disjoint?(1..5, 5..9) false iex> Range.disjoint?(1..5, 2..7) false ``` ### new(first, last) #### Specs ``` new(integer(), integer()) :: t() ``` Creates a new range. elixir ExUnit ExUnit ======= Unit testing framework for Elixir. Example -------- A basic setup for ExUnit is shown below: ``` # File: assertion_test.exs # 1) Start ExUnit. ExUnit.start() # 2) Create a new test module (test case) and use "ExUnit.Case". defmodule AssertionTest do # 3) Notice we pass "async: true", this runs the test case # concurrently with other test cases. The individual tests # within each test case are still run serially. use ExUnit.Case, async: true # 4) Use the "test" macro instead of "def" for clarity. test "the truth" do assert true end end ``` To run the tests above, run the file using `elixir` from the command line. Assuming you named the file `assertion_test.exs`, you can run it as: ``` elixir assertion_test.exs ``` Case, Callbacks and Assertions ------------------------------- See [`ExUnit.Case`](exunit.case) and [`ExUnit.Callbacks`](exunit.callbacks) for more information about defining test cases and setting up callbacks. The [`ExUnit.Assertions`](exunit.assertions) module contains a set of macros to generate assertions with appropriate error messages. Integration with Mix --------------------- Mix is the project management and build tool for Elixir. Invoking [`mix test`](https://hexdocs.pm/mix/Mix.Tasks.Test.html) from the command line will run the tests in each file matching the pattern `*_test.exs` found in the `test` directory of your project. You must create a `test_helper.exs` file inside the `test` directory and put the code common to all tests there. The minimum example of a `test_helper.exs` file would be: ``` # test/test_helper.exs ExUnit.start() ``` Mix will load the `test_helper.exs` file before executing the tests. It is not necessary to `require` the `test_helper.exs` file in your test files. See [`Mix.Tasks.Test`](https://hexdocs.pm/mix/Mix.Tasks.Test.html) for more information. Summary ======== Types ------ [failed()](#t:failed/0) The error state returned by [`ExUnit.Test`](exunit.test) and [`ExUnit.TestModule`](exunit.testmodule) [state()](#t:state/0) All tests start with a state of `nil`. [suite\_result()](#t:suite_result/0) A map representing the results of running a test suite Functions ---------- [after\_suite(function)](#after_suite/1) Sets a callback to be executed after the completion of a test suite. [configuration()](#configuration/0) Returns ExUnit configuration. [configure(options)](#configure/1) Configures ExUnit. [plural\_rule(word)](#plural_rule/1) Returns the pluralization for `word`. [plural\_rule(word, pluralization)](#plural_rule/2) Registers a `pluralization` for `word`. [run()](#run/0) Runs the tests. It is invoked automatically if ExUnit is started via [`start/1`](#start/1). [start(options \\ [])](#start/1) Starts ExUnit and automatically runs tests right before the VM terminates. Types ====== ### failed() #### Specs ``` failed() :: [{Exception.kind(), reason :: term(), Exception.stacktrace()}] ``` The error state returned by [`ExUnit.Test`](exunit.test) and [`ExUnit.TestModule`](exunit.testmodule) ### state() #### Specs ``` state() :: nil | {:failed, failed()} | {:skipped, binary()} | {:excluded, binary()} | {:invalid, module()} ``` All tests start with a state of `nil`. A finished test can be in one of five states: 1. Passed (also represented by `nil`) 2. Failed 3. Skipped (via @tag :skip) 4. Excluded (via :exclude filters) 5. Invalid (when setup\_all fails) ### suite\_result() #### Specs ``` suite_result() :: %{ excluded: non_neg_integer(), failures: non_neg_integer(), skipped: non_neg_integer(), total: non_neg_integer() } ``` A map representing the results of running a test suite Functions ========== ### after\_suite(function) #### Specs ``` after_suite((suite_result() -> any())) :: :ok ``` Sets a callback to be executed after the completion of a test suite. Callbacks set with [`after_suite/1`](#after_suite/1) must accept a single argument, which is a map containing the results of the test suite's execution. If [`after_suite/1`](#after_suite/1) is called multiple times, the callbacks will be called in reverse order. In other words, the last callback set will be the first to be called. ### configuration() #### Specs ``` configuration() :: Keyword.t() ``` Returns ExUnit configuration. ### configure(options) #### Specs ``` configure(Keyword.t()) :: :ok ``` Configures ExUnit. #### Options ExUnit supports the following options: * `:assert_receive_timeout` - the timeout to be used on `assert_receive` calls in milliseconds, defaults to `100`; * `:autorun` - if ExUnit should run by default on exit. Defaults to `true`; * `:capture_log` - if ExUnit should default to keeping track of log messages and print them on test failure. Can be overridden for individual tests via `@tag capture_log: false`. Defaults to `false`; * `:colors` - a keyword list of colors to be used by some formatters. The only option so far is `[enabled: boolean]` which defaults to [`IO.ANSI.enabled?/0`](https://hexdocs.pm/elixir/IO.ANSI.html#enabled?/0); * `:exclude` - specifies which tests are run by skipping tests that match the filter; * `:failures_manifest_file` - specifies a path to the file used to store failures between runs; * `:formatters` - the formatters that will print results, defaults to `[ExUnit.CLIFormatter]`; * `:include` - specifies which tests are run by skipping tests that do not match the filter. Keep in mind that all tests are included by default, so unless they are excluded first, the `:include` option has no effect. To only run the tests that match the `:include` filter, exclude the `:test` tag first (see the documentation for [`ExUnit.Case`](exunit.case) for more information on tags); * `:max_cases` - maximum number of tests to run in parallel. Only tests from different modules run in parallel. It defaults to `System.schedulers_online * 2` to optimize both CPU-bound and IO-bound tests; * `:max_failures` - the suite stops evaluating tests when this number of test failures is reached. All tests within a module that fail when using the `setup_all/1,2` callbacks are counted as failures. Defaults to `:infinity`; * `:module_load_timeout` - the timeout to be used when loading a test module in milliseconds, defaults to `60_000`; * `:only_test_ids` - a list of `{module_name, test_name}` tuples that limits what tests get run; * `:refute_receive_timeout` - the timeout to be used on `refute_receive` calls in milliseconds, defaults to `100`; * `:seed` - an integer seed value to randomize the test suite. This seed is also mixed with the test module and name to create a new unique seed on every test, which is automatically fed into the `:rand` module. This provides randomness between tests, but predictable and reproducible results; * `:slowest` - prints timing information for the N slowest tests. Running ExUnit with slow test reporting automatically runs in `trace` mode. It is disabled by default; * `:stacktrace_depth` - configures the stacktrace depth to be used on formatting and reporters, defaults to `20`; * `:timeout` - sets the timeout for the tests in milliseconds, defaults to `60_000`; * `:trace` - sets ExUnit into trace mode, this sets `:max_cases` to `1` and prints each test case and test while running. Note that in trace mode test timeouts will be ignored as timeout is set to `:infinity`. * `:test_location_relative_path` - the test location is the file:line information printed by tests as a shortcut to run a given test. When this value is set, the value is used as a prefix for the test itself. This is typically used by Mix to properly set-up umbrella projects Any arbitrary configuration can also be passed to [`configure/1`](#configure/1) or [`start/1`](#start/1), and these options can then be used in places such as custom formatters. These other options will be ignored by ExUnit itself. ### plural\_rule(word) #### Specs ``` plural_rule(binary()) :: binary() ``` Returns the pluralization for `word`. If one is not registered, returns the word appended with an "s". ### plural\_rule(word, pluralization) #### Specs ``` plural_rule(binary(), binary()) :: :ok ``` Registers a `pluralization` for `word`. If one is already registered, it is replaced. ### run() #### Specs ``` run() :: suite_result() ``` Runs the tests. It is invoked automatically if ExUnit is started via [`start/1`](#start/1). Returns a map containing the total number of tests, the number of failures, the number of excluded tests and the number of skipped tests. ### start(options \\ []) #### Specs ``` start(Keyword.t()) :: :ok ``` Starts ExUnit and automatically runs tests right before the VM terminates. It accepts a set of `options` to configure [`ExUnit`](#content) (the same ones accepted by [`configure/1`](#configure/1)). If you want to run tests manually, you can set the `:autorun` option to `false` and use [`run/0`](#run/0) to run tests.
programming_docs
elixir Operators Operators ========= This document covers operators in Elixir, how they are parsed, how they can be defined, and how they can be overridden. Operator precedence and associativity -------------------------------------- The following is a list of all operators that Elixir is capable of parsing, ordered from higher to lower precedence, alongside their associativity: | Operator | Associativity | | --- | --- | | `@` | Unary | | `.` | Left to right | | `+` `-` `!` `^` `not` `~~~` | Unary | | `*` `/` | Left to right | | `+` `-` | Left to right | | `++` `--` `..` `<>` | Right to left | | `^^^` | Left to right | | `in` `not in` | Left to right | | `|>` `<<<` `>>>` `<<~` `~>>` `<~` `~>` `<~>` `<|>` | Left to right | | `<` `>` `<=` `>=` | Left to right | | `==` `!=` `=~` `===` `!==` | Left to right | | `&&` `&&&` `and` | Left to right | | `||` `|||` `or` | Left to right | | `=` | Right to left | | `&` | Unary | | `=>` (valid syntax only inside `%{}`) | Right to left | | `|` | Right to left | | `::` | Right to left | | `when` | Right to left | | `<-` `\\` | Left to right | Comparison operators --------------------- Elixir provides the following built-in comparison operators: * [`==`](kernel#==/2) - equality * [`===`](kernel#===/2) - strict equality * [`!=`](kernel#!=/2) - inequality * [`!==`](kernel#!==/2) - strict inequality * [`<`](kernel#%3C/2) - less than * [`>`](kernel#%3E/2) - greater than * [`<=`](kernel#%3C=/2) - less than or equal * [`>=`](kernel#%3E=/2) - greater than or equal The only difference between [`==`](kernel#==/2) and [`===`](kernel#===/2) is that [`===`](kernel#===/2) is strict when it comes to comparing integers and floats: ``` iex> 1 == 1.0 true iex> 1 === 1.0 false ``` [`!=`](kernel#!=/2) and [`!==`](kernel#!==/2) act as the negation of [`==`](kernel#==/2) and [`===`](kernel#===/2), respectively. ### Term ordering In Elixir, different data types can be compared using comparison operators: ``` iex> 1 < :an_atom true ``` The reason we can compare different data types is pragmatism. Sorting algorithms don't need to worry about different data types in order to sort. For reference, the overall sorting order is defined below: ``` number < atom < reference < function < port < pid < tuple < map < list < bitstring ``` When comparing two numbers of different types (a number being either an integer or a float), a conversion to the type with greater precision will always occur, unless the comparison operator used is either [`===`](kernel#===/2) or [`!==`](kernel#!==/2). A float will be considered more precise than an integer, unless the float is greater/less than +/-9007199254740992.0 respectively, at which point all the significant figures of the float are to the left of the decimal point. This behavior exists so that the comparison of large numbers remains transitive. The collection types are compared using the following rules: * Tuples are compared by size, then element by element. * Maps are compared by size, then by keys in ascending term order, then by values in key order. In the specific case of maps' key ordering, integers are always considered to be less than floats. * Lists are compared element by element. * Bitstrings are compared byte by byte, incomplete bytes are compared bit by bit. Custom and overridden operators -------------------------------- ### Defining custom operators Elixir is capable of parsing a predefined set of operators; this means that it's not possible to define new operators (like one could do in Haskell, for example). However, not all operators that Elixir can parse are *used* by Elixir: for example, `+` and `||` are used by Elixir for addition and boolean *or*, but `<~>` is not used (but valid). To define an operator, you can use the usual `def*` constructs (`def`, `defp`, `defmacro`, and so on) but with a syntax similar to how the operator is used: ``` defmodule MyOperators do # We define ~> to return the maximum of the given two numbers, # and <~ to return the minimum. def a ~> b, do: max(a, b) def a <~ b, do: min(a, b) end ``` To use the newly defined operators, we **have to** import the module that defines them: ``` iex> import MyOperators iex> 1 ~> 2 2 iex> 1 <~ 2 1 ``` The following is a table of all the operators that Elixir is capable of parsing, but that are not used by default: * `|` * `|||` * `&&&` * `<<<` * `>>>` * `<<~` * `~>>` * `<~` * `~>` * `<~>` * `<|>` * `^^^` * `~~~` The following operators are used by the [`Bitwise`](bitwise) module when imported: [`&&&`](bitwise#&&&/2), [`^^^`](bitwise#%5E%5E%5E/2), [`<<<`](bitwise#%3C%3C%3C/2), [`>>>`](bitwise#%3E%3E%3E/2), [`|||`](bitwise#%7C%7C%7C/2), [`~~~`](bitwise#~~~/1). See the documentation for [`Bitwise`](bitwise) for more information. ### Redefining existing operators The operators that Elixir uses (for example, `+`) can be defined by any module and used in place of the ones defined by Elixir, provided they're specifically not imported from [`Kernel`](kernel) (which is imported everywhere by default). For example: ``` defmodule WrongMath do # Let's make math wrong by changing the meaning of +: def a + b, do: a - b end ``` Now, we will get an error if we try to use this operator "out of the box": ``` iex> import WrongMath iex> 1 + 2 ** (CompileError) iex:11: function +/2 imported from both WrongMath and Kernel, call is ambiguous ``` So, as mentioned above, we need to explicitly *not* import [`+/2`](kernel#+/2) from [`Kernel`](kernel): ``` iex> import WrongMath iex> import Kernel, except: [+: 2] iex> 1 + 2 -1 ``` ### Final note While it's possible to define unused operators (such as `<~>`) and to "override" predefined operators (such as `+`), the Elixir community generally discourages this. Custom-defined operators can be really hard to read and even more to understand, as they don't have a descriptive name like functions do. That said, some specific cases or custom domain specific languages (DSLs) may justify these practices. elixir Basic operators Getting Started Basic operators =============== In the [previous chapter](basic-types), we saw Elixir provides `+`, `-`, `*`, `/` as arithmetic operators, plus the functions `div/2` and `rem/2` for integer division and remainder. Elixir also provides `++` and `--` to manipulate lists: ``` iex> [1, 2, 3] ++ [4, 5, 6] [1, 2, 3, 4, 5, 6] iex> [1, 2, 3] -- [2] [1, 3] ``` String concatenation is done with `<>`: ``` iex> "foo" <> "bar" "foobar" ``` Elixir also provides three boolean operators: `or`, `and` and `not`. These operators are strict in the sense that they expect something that evaluates to a boolean (`true` or `false`) as their first argument: ``` iex> true and true true iex> false or is_atom(:example) true ``` Providing a non-boolean will raise an exception: ``` iex> 1 and true ** (BadBooleanError) expected a boolean on left-side of "and", got: 1 ``` `or` and `and` are short-circuit operators. They only execute the right side if the left side is not enough to determine the result: ``` iex> false and raise("This error will never be raised") false iex> true or raise("This error will never be raised") true ``` > Note: If you are an Erlang developer, `and` and `or` in Elixir actually map to the `andalso` and `orelse` operators in Erlang. > > Besides these boolean operators, Elixir also provides `||`, `&&` and `!` which accept arguments of any type. For these operators, all values except `false` and `nil` will evaluate to true: ``` # or iex> 1 || true 1 iex> false || 11 11 # and iex> nil && 13 nil iex> true && 17 17 # not iex> !true false iex> !1 false iex> !nil true ``` As a rule of thumb, use `and`, `or` and `not` when you are expecting booleans. If any of the arguments are non-boolean, use `&&`, `||` and `!`. Elixir also provides `==`, `!=`, `===`, `!==`, `<=`, `>=`, `<` and `>` as comparison operators: ``` iex> 1 == 1 true iex> 1 != 2 true iex> 1 < 2 true ``` The difference between `==` and `===` is that the latter is more strict when comparing integers and floats: ``` iex> 1 == 1.0 true iex> 1 === 1.0 false ``` In Elixir, we can compare two different data types: ``` iex> 1 < :atom true ``` The reason we can compare different data types is pragmatism. Sorting algorithms don’t need to worry about different data types in order to sort. The overall sorting order is defined below: ``` number < atom < reference < function < port < pid < tuple < map < list < bitstring ``` You don’t actually need to memorize this ordering; it’s enough to know that this ordering exists. For reference information about operators (and ordering), check the [reference page on operators](https://hexdocs.pm/elixir/operators.html). In the next chapter, we are going to discuss pattern matching through the use of `=`, the match operator. elixir String.Chars protocol String.Chars protocol ====================== The [`String.Chars`](#content) protocol is responsible for converting a structure to a binary (only if applicable). The only function required to be implemented is [`to_string/1`](#to_string/1), which does the conversion. The [`to_string/1`](#to_string/1) function automatically imported by [`Kernel`](kernel) invokes this protocol. String interpolation also invokes [`to_string/1`](#to_string/1) in its arguments. For example, `"foo#{bar}"` is the same as `"foo" <> to_string(bar)`. Summary ======== Types ------ [t()](#t:t/0) Functions ---------- [to\_string(term)](#to_string/1) Converts `term` to a string. Types ====== ### t() #### Specs ``` t() :: term() ``` Functions ========== ### to\_string(term) #### Specs ``` to_string(t()) :: String.t() ``` Converts `term` to a string. elixir Date.Range Date.Range =========== Returns an inclusive range between dates. Ranges must be created with the [`Date.range/2`](date#range/2) function. The following fields are public: * `:first` - the initial date on the range * `:last` - the last date on the range The remaining fields are private and should not be accessed. Summary ======== Types ------ [t()](#t:t/0) Types ====== ### t() #### Specs ``` t() :: %Date.Range{ first: Date.t(), first_in_iso_days: iso_days(), last: Date.t(), last_in_iso_days: iso_days() } ``` elixir Kernel.ParallelCompiler Kernel.ParallelCompiler ======================== A module responsible for compiling and requiring files in parallel. Summary ======== Functions ---------- [async(fun)](#async/1) Starts a task for parallel compilation. [compile(files, options \\ [])](#compile/2) Compiles the given files. [compile\_to\_path(files, path, options \\ [])](#compile_to_path/3) [require(files, options \\ [])](#require/2) Requires the given files in parallel. Functions ========== ### async(fun) Starts a task for parallel compilation. If you have a file that needs to compile other modules in parallel, the spawned processes need to be aware of the compiler environment. This function allows a developer to create a task that is aware of those environments. See [`Task.async/1`](task#async/1) for more information. The task spawned must be always awaited on by calling [`Task.await/1`](task#await/1) ### compile(files, options \\ []) Compiles the given files. Those files are compiled in parallel and can automatically detect dependencies between them. Once a dependency is found, the current file stops being compiled until the dependency is resolved. It returns `{:ok, modules, warnings}` or `{:error, errors, warnings}`. Both errors and warnings are a list of three-element tuples containing the file, line and the formatted error/warning. #### Options * `:each_file` - for each file compiled, invokes the callback passing the file * `:each_long_compilation` - for each file that takes more than a given timeout (see the `:long_compilation_threshold` option) to compile, invoke this callback passing the file as its argument * `:each_module` - for each module compiled, invokes the callback passing the file, module and the module bytecode * `:each_cycle` - after the given files are compiled, invokes this function that return a list with potentially more files to compile * `:long_compilation_threshold` - the timeout (in seconds) after the `:each_long_compilation` callback is invoked; defaults to `15` * `:dest` - the destination directory for the BEAM files. When using [`compile/2`](#compile/2), this information is only used to properly annotate the BEAM files before they are loaded into memory. If you want a file to actually be written to `dest`, use [`compile_to_path/3`](#compile_to_path/3) instead. ### compile\_to\_path(files, path, options \\ []) ### require(files, options \\ []) Requires the given files in parallel. Opposite to compile, dependencies are not attempted to be automatically solved between files. It returns `{:ok, modules, warnings}` or `{:error, errors, warnings}`. Both errors and warnings are a list of three-element tuples containing the file, line and the formatted error/warning. #### Options * `:each_file` - for each file compiled, invokes the callback passing the file * `:each_module` - for each module compiled, invokes the callback passing the file, module and the module bytecode elixir Code Code ===== Utilities for managing code compilation, code evaluation, and code loading. This module complements Erlang's [`:code` module](http://www.erlang.org/doc/man/code.html) to add behaviour which is specific to Elixir. Almost all of the functions in this module have global side effects on the behaviour of Elixir. Working with files ------------------- This module contains three functions for compiling and evaluating files. Here is a summary of them and their behaviour: * [`require_file/2`](#require_file/2) - compiles a file and tracks its name. It does not compile the file again if it has been previously required. * [`compile_file/2`](#compile_file/2) - compiles a file without tracking its name. Compiles the file multiple times when invoked multiple times. * [`eval_file/2`](#eval_file/2) - evaluates the file contents without tracking its name. It returns the result of the last expression in the file, instead of the modules defined in it. In a nutshell, the first must be used when you want to keep track of the files handled by the system, to avoid the same file from being compiled multiple times. This is common in scripts. [`compile_file/2`](#compile_file/2) must be used when you are interested in the modules defined in a file, without tracking. [`eval_file/2`](#eval_file/2) should be used when you are interested in the result of evaluating the file rather than the modules it defines. Summary ======== Functions ---------- [append\_path(path)](#append_path/1) Appends a path to the end of the Erlang VM code path list. [available\_compiler\_options()](#available_compiler_options/0) Returns a list with the available compiler options. [compile\_file(file, relative\_to \\ nil)](#compile_file/2) Compiles the given file. [compile\_quoted(quoted, file \\ "nofile")](#compile_quoted/2) Compiles the quoted expression. [compile\_string(string, file \\ "nofile")](#compile_string/2) Compiles the given string. [compiler\_options()](#compiler_options/0) Gets the compilation options from the code server. [compiler\_options(opts)](#compiler_options/1) Sets compilation options. [delete\_path(path)](#delete_path/1) Deletes a path from the Erlang VM code path list. This is the list of directories the Erlang VM uses for finding module code. [ensure\_compiled(module)](#ensure_compiled/1) Ensures the given module is compiled and loaded. [ensure\_compiled?(module)](#ensure_compiled?/1) Ensures the given module is compiled and loaded. [ensure\_loaded(module)](#ensure_loaded/1) Ensures the given module is loaded. [ensure\_loaded?(module)](#ensure_loaded?/1) Ensures the given module is loaded. [eval\_file(file, relative\_to \\ nil)](#eval_file/2) Evals the given file. [eval\_quoted(quoted, binding \\ [], opts \\ [])](#eval_quoted/3) Evaluates the quoted contents. [eval\_string(string, binding \\ [], opts \\ [])](#eval_string/3) Evaluates the contents given by `string`. [fetch\_docs(module\_or\_path)](#fetch_docs/1) Returns the docs for the given module or path to `.beam` file. [format\_file!(file, opts \\ [])](#format_file!/2) Formats a file. [format\_string!(string, opts \\ [])](#format_string!/2) Formats the given code `string`. [get\_docs(module, kind)](#get_docs/2) deprecated Deprecated function to retrieve old documentation format. [prepend\_path(path)](#prepend_path/1) Prepends a path to the beginning of the Erlang VM code path list. [purge\_compiler\_modules()](#purge_compiler_modules/0) Purge compiler modules. [require\_file(file, relative\_to \\ nil)](#require_file/2) Requires the given `file`. [required\_files()](#required_files/0) Lists all required files. [string\_to\_quoted(string, opts \\ [])](#string_to_quoted/2) Converts the given string to its quoted form. [string\_to\_quoted!(string, opts \\ [])](#string_to_quoted!/2) Converts the given string to its quoted form. [unrequire\_files(files)](#unrequire_files/1) Removes files from the required files list. Functions ========== ### append\_path(path) #### Specs ``` append_path(Path.t()) :: true | {:error, :bad_directory} ``` Appends a path to the end of the Erlang VM code path list. This is the list of directories the Erlang VM uses for finding module code. The path is expanded with [`Path.expand/1`](path#expand/1) before being appended. If this path does not exist, an error is returned. #### Examples ``` Code.append_path(".") #=> true Code.append_path("/does_not_exist") #=> {:error, :bad_directory} ``` ### available\_compiler\_options() #### Specs ``` available_compiler_options() :: [atom()] ``` Returns a list with the available compiler options. See [`compiler_options/1`](#compiler_options/1) for more information. #### Examples ``` Code.available_compiler_options() #=> [:docs, :debug_info, ...] ``` ### compile\_file(file, relative\_to \\ nil) #### Specs ``` compile_file(binary(), nil | binary()) :: [{module(), binary()}] ``` Compiles the given file. Accepts `relative_to` as an argument to tell where the file is located. Returns a list of tuples where the first element is the module name and the second one is its bytecode (as a binary). Opposite to [`require_file/2`](#require_file/2), it does not track the filename of the compiled file. If you would like to get the result of evaluating file rather than the modules defined in it, see [`eval_file/2`](#eval_file/2). For compiling many files concurrently, see [`Kernel.ParallelCompiler.compile/2`](kernel.parallelcompiler#compile/2). ### compile\_quoted(quoted, file \\ "nofile") #### Specs ``` compile_quoted(Macro.t(), binary()) :: [{module(), binary()}] ``` Compiles the quoted expression. Returns a list of tuples where the first element is the module name and the second one is its bytecode (as a binary). A `file` can be given as second argument which will be used for reporting warnings and errors. ### compile\_string(string, file \\ "nofile") #### Specs ``` compile_string(List.Chars.t(), binary()) :: [{module(), binary()}] ``` Compiles the given string. Returns a list of tuples where the first element is the module name and the second one is its bytecode (as a binary). A `file` can be given as second argument which will be used for reporting warnings and errors. **Warning**: `string` can be any Elixir code and code can be executed with the same privileges as the Erlang VM: this means that such code could compromise the machine (for example by executing system commands). Don't use [`compile_string/2`](#compile_string/2) with untrusted input (such as strings coming from the network). ### compiler\_options() #### Specs ``` compiler_options() :: %{optional(atom()) => boolean()} ``` Gets the compilation options from the code server. Check [`compiler_options/1`](#compiler_options/1) for more information. #### Examples ``` Code.compiler_options() #=> %{debug_info: true, docs: true, ...} ``` ### compiler\_options(opts) #### Specs ``` compiler_options(Enumerable.t()) :: %{optional(atom()) => boolean()} ``` Sets compilation options. These options are global since they are stored by Elixir's Code Server. Available options are: * `:docs` - when `true`, retain documentation in the compiled module. Defaults to `true`. * `:debug_info` - when `true`, retain debug information in the compiled module. This allows a developer to reconstruct the original source code. Defaults to `false`. * `:ignore_module_conflict` - when `true`, override modules that were already defined without raising errors. Defaults to `false`. * `:relative_paths` - when `true`, use relative paths in quoted nodes, warnings and errors generated by the compiler. Note disabling this option won't affect runtime warnings and errors. Defaults to `true`. * `:warnings_as_errors` - causes compilation to fail when warnings are generated. Defaults to `false`. It returns the new map of compiler options. #### Examples ``` Code.compiler_options(debug_info: true) #=> %{debug_info: true, docs: true, #=> warnings_as_errors: false, ignore_module_conflict: false} ``` ### delete\_path(path) #### Specs ``` delete_path(Path.t()) :: boolean() ``` Deletes a path from the Erlang VM code path list. This is the list of directories the Erlang VM uses for finding module code. The path is expanded with [`Path.expand/1`](path#expand/1) before being deleted. If the path does not exist, this function returns `false`. #### Examples ``` Code.prepend_path(".") Code.delete_path(".") #=> true Code.delete_path("/does_not_exist") #=> false ``` ### ensure\_compiled(module) #### Specs ``` ensure_compiled(module()) :: {:module, module()} | {:error, :embedded | :badfile | :nofile | :on_load_failure} ``` Ensures the given module is compiled and loaded. If the module is already loaded, it works as no-op. If the module was not loaded yet, it checks if it needs to be compiled first and then tries to load it. If it succeeds in loading the module, it returns `{:module, module}`. If not, returns `{:error, reason}` with the error reason. If the module being checked is currently in a compiler deadlock, this functions returns `{:error, :nofile}`. Check [`ensure_loaded/1`](#ensure_loaded/1) for more information on module loading and when to use [`ensure_loaded/1`](#ensure_loaded/1) or [`ensure_compiled/1`](#ensure_compiled/1). ### ensure\_compiled?(module) #### Specs ``` ensure_compiled?(module()) :: boolean() ``` Ensures the given module is compiled and loaded. Similar to [`ensure_compiled/1`](#ensure_compiled/1), but returns `true` if the module is already loaded or was successfully loaded and compiled. Returns `false` otherwise. ### ensure\_loaded(module) #### Specs ``` ensure_loaded(module()) :: {:module, module()} | {:error, :embedded | :badfile | :nofile | :on_load_failure} ``` Ensures the given module is loaded. If the module is already loaded, this works as no-op. If the module was not yet loaded, it tries to load it. If it succeeds in loading the module, it returns `{:module, module}`. If not, returns `{:error, reason}` with the error reason. #### Code loading on the Erlang VM Erlang has two modes to load code: interactive and embedded. By default, the Erlang VM runs in interactive mode, where modules are loaded as needed. In embedded mode the opposite happens, as all modules need to be loaded upfront or explicitly. Therefore, this function is used to check if a module is loaded before using it and allows one to react accordingly. For example, the [`URI`](uri) module uses this function to check if a specific parser exists for a given URI scheme. #### [`ensure_compiled/1`](#ensure_compiled/1) Elixir also contains an [`ensure_compiled/1`](#ensure_compiled/1) function that is a superset of [`ensure_loaded/1`](#ensure_loaded/1). Since Elixir's compilation happens in parallel, in some situations you may need to use a module that was not yet compiled, therefore it can't even be loaded. When invoked, [`ensure_compiled/1`](#ensure_compiled/1) halts the compilation of the caller until the module given to [`ensure_compiled/1`](#ensure_compiled/1) becomes available or all files for the current project have been compiled. If compilation finishes and the module is not available, an error tuple is returned. [`ensure_compiled/1`](#ensure_compiled/1) does not apply to dependencies, as dependencies must be compiled upfront. In most cases, [`ensure_loaded/1`](#ensure_loaded/1) is enough. [`ensure_compiled/1`](#ensure_compiled/1) must be used in rare cases, usually involving macros that need to invoke a module for callback information. #### Examples ``` iex> Code.ensure_loaded(Atom) {:module, Atom} iex> Code.ensure_loaded(DoesNotExist) {:error, :nofile} ``` ### ensure\_loaded?(module) #### Specs ``` ensure_loaded?(module()) :: boolean() ``` Ensures the given module is loaded. Similar to [`ensure_loaded/1`](#ensure_loaded/1), but returns `true` if the module is already loaded or was successfully loaded. Returns `false` otherwise. #### Examples ``` iex> Code.ensure_loaded?(Atom) true ``` ### eval\_file(file, relative\_to \\ nil) #### Specs ``` eval_file(binary(), nil | binary()) :: {term(), binding :: list()} ``` Evals the given file. Accepts `relative_to` as an argument to tell where the file is located. While [`require_file/2`](#require_file/2) and [`compile_file/2`](#compile_file/2) return the loaded modules and their bytecode, [`eval_file/2`](#eval_file/2) simply evaluates the file contents and returns the evaluation result and its bindings (exactly the same return value as [`eval_string/3`](#eval_string/3)). ### eval\_quoted(quoted, binding \\ [], opts \\ []) #### Specs ``` eval_quoted(Macro.t(), list(), Macro.Env.t() | keyword()) :: {term(), binding :: list()} ``` Evaluates the quoted contents. **Warning**: Calling this function inside a macro is considered bad practice as it will attempt to evaluate runtime values at compile time. Macro arguments are typically transformed by unquoting them into the returned quoted expressions (instead of evaluated). See [`eval_string/3`](#eval_string/3) for a description of bindings and options. #### Examples ``` iex> contents = quote(do: var!(a) + var!(b)) iex> Code.eval_quoted(contents, [a: 1, b: 2], file: __ENV__.file, line: __ENV__.line) {3, [a: 1, b: 2]} ``` For convenience, you can pass [`__ENV__/0`](kernel.specialforms#__ENV__/0) as the `opts` argument and all options will be automatically extracted from the current environment: ``` iex> contents = quote(do: var!(a) + var!(b)) iex> Code.eval_quoted(contents, [a: 1, b: 2], __ENV__) {3, [a: 1, b: 2]} ``` ### eval\_string(string, binding \\ [], opts \\ []) #### Specs ``` eval_string(List.Chars.t(), list(), Macro.Env.t() | keyword()) :: {term(), binding :: list()} ``` Evaluates the contents given by `string`. The `binding` argument is a keyword list of variable bindings. The `opts` argument is a keyword list of environment options. **Warning**: `string` can be any Elixir code and will be executed with the same privileges as the Erlang VM: this means that such code could compromise the machine (for example by executing system commands). Don't use [`eval_string/3`](#eval_string/3) with untrusted input (such as strings coming from the network). #### Options Options can be: * `:file` - the file to be considered in the evaluation * `:line` - the line on which the script starts Additionally, the following scope values can be configured: * `:aliases` - a list of tuples with the alias and its target * `:requires` - a list of modules required * `:functions` - a list of tuples where the first element is a module and the second a list of imported function names and arity; the list of function names and arity must be sorted * `:macros` - a list of tuples where the first element is a module and the second a list of imported macro names and arity; the list of function names and arity must be sorted Notice that setting any of the values above overrides Elixir's default values. For example, setting `:requires` to `[]` will no longer automatically require the [`Kernel`](kernel) module. In the same way setting `:macros` will no longer auto-import [`Kernel`](kernel) macros like [`Kernel.if/2`](kernel#if/2), [`Kernel.SpecialForms.case/2`](kernel.specialforms#case/2), and so on. Returns a tuple of the form `{value, binding}`, where `value` is the value returned from evaluating `string`. If an error occurs while evaluating `string` an exception will be raised. `binding` is a keyword list with the value of all variable bindings after evaluating `string`. The binding key is usually an atom, but it may be a tuple for variables defined in a different context. #### Examples ``` iex> Code.eval_string("a + b", [a: 1, b: 2], file: __ENV__.file, line: __ENV__.line) {3, [a: 1, b: 2]} iex> Code.eval_string("c = a + b", [a: 1, b: 2], __ENV__) {3, [a: 1, b: 2, c: 3]} iex> Code.eval_string("a = a + b", [a: 1, b: 2]) {3, [a: 3, b: 2]} ``` For convenience, you can pass [`__ENV__/0`](kernel.specialforms#__ENV__/0) as the `opts` argument and all imports, requires and aliases defined in the current environment will be automatically carried over: ``` iex> Code.eval_string("a + b", [a: 1, b: 2], __ENV__) {3, [a: 1, b: 2]} ``` ### fetch\_docs(module\_or\_path) #### Specs ``` fetch_docs(module() | String.t()) :: {:docs_v1, annotation, beam_language, format, module_doc :: doc_content, metadata, docs :: [doc_element]} | {:error, :module_not_found | :chunk_not_found | {:invalid_chunk, binary()}} when annotation: :erl_anno.anno(), beam_language: :elixir | :erlang | :lfe | :alpaca | atom(), doc_content: %{required(binary()) => binary()} | :none | :hidden, doc_element: {{kind :: atom(), function_name :: atom(), arity()}, annotation, signature, doc_content, metadata}, format: binary(), signature: [binary()], metadata: map() ``` Returns the docs for the given module or path to `.beam` file. When given a module name, it finds its BEAM code and reads the docs from it. When given a path to a `.beam` file, it will load the docs directly from that file. It returns the term stored in the documentation chunk in the format defined by [EEP 48](http://erlang.org/eep/eeps/eep-0048.html) or `{:error, reason}` if the chunk is not available. #### Examples ``` # Module documentation of an existing module iex> {:docs_v1, _, :elixir, _, %{"en" => module_doc}, _, _} = Code.fetch_docs(Atom) iex> module_doc |> String.split("\n") |> Enum.at(0) "Convenience functions for working with atoms." # A module that doesn't exist iex> Code.fetch_docs(ModuleNotGood) {:error, :module_not_found} ``` ### format\_file!(file, opts \\ []) #### Specs ``` format_file!(binary(), keyword()) :: iodata() ``` Formats a file. See [`format_string!/2`](#format_string!/2) for more information on code formatting and available options. ### format\_string!(string, opts \\ []) #### Specs ``` format_string!(binary(), keyword()) :: iodata() ``` Formats the given code `string`. The formatter receives a string representing Elixir code and returns iodata representing the formatted code according to pre-defined rules. #### Options * `:file` - the file which contains the string, used for error reporting * `:line` - the line the string starts, used for error reporting * `:line_length` - the line length to aim for when formatting the document. Defaults to 98. Note this value is used as reference but it is not enforced by the formatter as sometimes user intervention is required. See "Running the formatter" section * `:locals_without_parens` - a keyword list of name and arity pairs that should be kept without parens whenever possible. The arity may be the atom `:*`, which implies all arities of that name. The formatter already includes a list of functions and this option augments this list. * `:rename_deprecated_at` - rename all known deprecated functions at the given version to their non-deprecated equivalent. It expects a valid [`Version`](version) which is usually the minimum Elixir version supported by the project. * `:force_do_end_blocks` (since v1.9.0) - when `true`, converts all inline usages of `do: ...`, `else: ...` and friends into `do/end` blocks. Defaults to `false`. Notice this option is convergent: once you set it to `true`, all keywords will be converted. If you set it to `false` later on, `do/end` blocks won't be converted back to keywords. #### Design principles The formatter was designed under three principles. First, the formatter never changes the semantics of the code by default. This means the input AST and the output AST are equivalent. Optional behaviour, such as `:rename_deprecated_at`, is allowed to break this guarantee. The second principle is to provide as little configuration as possible. This eases the formatter adoption by removing contention points while making sure a single style is followed consistently by the community as a whole. The formatter does not hard code names. The formatter will not behave specially because a function is named `defmodule`, `def`, etc. This principle mirrors Elixir's goal of being an extensible language where developers can extend the language with new constructs as if they were part of the language. When it is absolutely necessary to change behaviour based on the name, this behaviour should be configurable, such as the `:locals_without_parens` option. #### Running the formatter The formatter attempts to fit the most it can on a single line and introduces line breaks wherever possible when it cannot. In some cases, this may lead to undesired formatting. Therefore, **some code generated by the formatter may not be aesthetically pleasing and may require explicit intervention from the developer**. That's why we do not recommend to run the formatter blindly in an existing codebase. Instead you should format and sanity check each formatted file. Let's see some examples. The code below: ``` "this is a very long string ... #{inspect(some_value)}" ``` may be formatted as: ``` "this is a very long string ... #{ inspect(some_value) }" ``` This happens because the only place the formatter can introduce a new line without changing the code semantics is in the interpolation. In those scenarios, we recommend developers to directly adjust the code. Here we can use the binary concatenation operator [`<>/2`](kernel#%3C%3E/2): ``` "this is a very long string " <> "... #{inspect(some_value)}" ``` The string concatenation makes the code fit on a single line and also gives more options to the formatter. A similar example is when the formatter breaks a function definition over multiple clauses: ``` def my_function( %User{name: name, age: age, ...}, arg1, arg2 ) do ... end ``` While the code above is completely valid, you may prefer to match on the struct variables inside the function body in order to keep the definition on a single line: ``` def my_function(%User{} = user, arg1, arg2) do %{name: name, age: age, ...} = user ... end ``` In some situations, you can use the fact the formatter does not generate elegant code as a hint for refactoring. Take this code: ``` def board?(board_id, %User{} = user, available_permissions, required_permissions) do Tracker.OrganizationMembers.user_in_organization?(user.id, board.organization_id) and required_permissions == Enum.to_list(MapSet.intersection(MapSet.new(required_permissions), MapSet.new(available_permissions))) end ``` The code above has very long lines and running the formatter is not going to address this issue. In fact, the formatter may make it more obvious that you have complex expressions: ``` def board?(board_id, %User{} = user, available_permissions, required_permissions) do Tracker.OrganizationMembers.user_in_organization?(user.id, board.organization_id) and required_permissions == Enum.to_list( MapSet.intersection( MapSet.new(required_permissions), MapSet.new(available_permissions) ) ) end ``` Take such cases as a suggestion that your code should be refactored: ``` def board?(board_id, %User{} = user, available_permissions, required_permissions) do Tracker.OrganizationMembers.user_in_organization?(user.id, board.organization_id) and matching_permissions?(required_permissions, available_permissions) end defp matching_permissions?(required_permissions, available_permissions) do intersection = required_permissions |> MapSet.new() |> MapSet.intersection(MapSet.new(available_permissions)) |> Enum.to_list() required_permissions == intersection end ``` To sum it up: since the formatter cannot change the semantics of your code, sometimes it is necessary to tweak or refactor the code to get optimal formatting. To help better understand how to control the formatter, we describe in the next sections the cases where the formatter keeps the user encoding and how to control multiline expressions. #### Keeping user's formatting The formatter respects the input format in some cases. Those are listed below: * Insignificant digits in numbers are kept as is. The formatter however always inserts underscores for decimal numbers with more than 5 digits and converts hexadecimal digits to uppercase * Strings, charlists, atoms and sigils are kept as is. No character is automatically escaped or unescaped. The choice of delimiter is also respected from the input * Newlines inside blocks are kept as in the input except for: 1) expressions that take multiple lines will always have an empty line before and after and 2) empty lines are always squeezed together into a single empty line * The choice between `:do` keyword and `do/end` blocks is left to the user * Lists, tuples, bitstrings, maps, structs and function calls will be broken into multiple lines if they are followed by a newline in the opening bracket and preceded by a new line in the closing bracket * Newlines before certain operators (such as the pipeline operators) and before other operators (such as comparison operators) The behaviours above are not guaranteed. We may remove or add new rules in the future. The goal of documenting them is to provide better understanding on what to expect from the formatter. ### Multi-line lists, maps, tuples, etc. You can force lists, tuples, bitstrings, maps, structs and function calls to have one entry per line by adding a newline after the opening bracket and a new line before the closing bracket lines. For example: ``` [ foo, bar ] ``` If there are no newlines around the brackets, then the formatter will try to fit everything on a single line, such that the snippet below ``` [foo, bar] ``` will be formatted as ``` [foo, bar] ``` You can also force function calls and keywords to be rendered on multiple lines by having each entry on its own line: ``` defstruct name: nil, age: 0 ``` The code above will be kept with one keyword entry per line by the formatter. To avoid that, just squash everything into a single line. ### Parens and no parens in function calls Elixir has two syntaxes for function calls. With parens and no parens. By default, Elixir will add parens to all calls except for: 1. calls that have do/end blocks 2. local calls without parens where the name and arity of the local call is also listed under `:locals_without_parens` (except for calls with arity 0, where the compiler always require parens) The choice of parens and no parens also affects indentation. When a function call with parens doesn't fit on the same line, the formatter introduces a newline around parens and indents the arguments with two spaces: ``` some_call( arg1, arg2, arg3 ) ``` On the other hand, function calls without parens are always indented by the function call length itself, like this: ``` some_call arg1, arg2, arg3 ``` If the last argument is a data structure, such as maps and lists, and the beginning of the data structure fits on the same line as the function call, then no indentation happens, this allows code like this: ``` Enum.reduce(some_collection, initial_value, fn element, acc -> # code end) some_function_without_parens %{ foo: :bar, baz: :bat } ``` #### Code comments The formatter also handles code comments in a way to guarantee a space is always added between the beginning of the comment (#) and the next character. The formatter also extracts all trailing comments to their previous line. For example, the code below ``` hello #world ``` will be rewritten to ``` # world hello ``` Because code comments are handled apart from the code representation (AST), there are some situations where code comments are seen as ambiguous by the code formatter. For example, the comment in the anonymous function below ``` fn arg1 -> body1 # comment arg2 -> body2 end ``` and in this one ``` fn arg1 -> body1 # comment arg2 -> body2 end ``` are considered equivalent (the nesting is discarded alongside most of user formatting). In such cases, the code formatter will always format to the latter. ### get\_docs(module, kind) This function is deprecated. Code.get\_docs/2 always returns nil as its outdated documentation is no longer stored on BEAM files. Use Code.fetch\_docs/1 instead. #### Specs ``` get_docs(module(), :moduledoc | :docs | :callback_docs | :type_docs | :all) :: nil ``` Deprecated function to retrieve old documentation format. Elixir v1.7 adopts [EEP 48](http://erlang.org/eep/eeps/eep-0048.html) which is a new documentation format meant to be shared across all BEAM languages. The old format, used by [`Code.get_docs/2`](code#get_docs/2), is no longer available, and therefore this function always returns `nil`. Use [`Code.fetch_docs/1`](code#fetch_docs/1) instead. ### prepend\_path(path) #### Specs ``` prepend_path(Path.t()) :: true | {:error, :bad_directory} ``` Prepends a path to the beginning of the Erlang VM code path list. This is the list of directories the Erlang VM uses for finding module code. The path is expanded with [`Path.expand/1`](path#expand/1) before being prepended. If this path does not exist, an error is returned. #### Examples ``` Code.prepend_path(".") #=> true Code.prepend_path("/does_not_exist") #=> {:error, :bad_directory} ``` ### purge\_compiler\_modules() #### Specs ``` purge_compiler_modules() :: {:ok, non_neg_integer()} ``` Purge compiler modules. The compiler utilizes temporary modules to compile code. For example, `elixir_compiler_1`, `elixir_compiler_2`, etc. In case the compiled code stores references to anonymous functions or similar, the Elixir compiler may be unable to reclaim those modules, keeping an unnecessary amount of code in memory and eventually leading to modules such as `elixir_compiler_12345`. This function purges all modules currently kept by the compiler, allowing old compiler module names to be reused. If there are any processes running any code from such modules, they will be terminated too. It returns `{:ok, number_of_modules_purged}`. ### require\_file(file, relative\_to \\ nil) #### Specs ``` require_file(binary(), nil | binary()) :: [{module(), binary()}] | nil ``` Requires the given `file`. Accepts `relative_to` as an argument to tell where the file is located. If the file was already required, [`require_file/2`](#require_file/2) doesn't do anything and returns `nil`. Notice that if [`require_file/2`](#require_file/2) is invoked by different processes concurrently, the first process to invoke [`require_file/2`](#require_file/2) acquires a lock and the remaining ones will block until the file is available. This means that if [`require_file/2`](#require_file/2) is called more than once with a given file, that file will be compiled only once. The first process to call [`require_file/2`](#require_file/2) will get the list of loaded modules, others will get `nil`. See [`compile_file/2`](#compile_file/2) if you would like to compile a file without tracking its filenames. Finally, if you would like to get the result of evaluating a file rather than the modules defined in it, see [`eval_file/2`](#eval_file/2). #### Examples If the file has not been required, it returns the list of modules: ``` modules = Code.require_file("eex_test.exs", "../eex/test") List.first(modules) #=> {EExTest.Compiled, <<70, 79, 82, 49, ...>>} ``` If the file has been required, it returns `nil`: ``` Code.require_file("eex_test.exs", "../eex/test") #=> nil ``` ### required\_files() #### Specs ``` required_files() :: [binary()] ``` Lists all required files. #### Examples ``` Code.require_file("../eex/test/eex_test.exs") List.first(Code.required_files()) =~ "eex_test.exs" #=> true ``` ### string\_to\_quoted(string, opts \\ []) #### Specs ``` string_to_quoted(List.Chars.t(), keyword()) :: {:ok, Macro.t()} | {:error, {line :: pos_integer(), term(), term()}} ``` Converts the given string to its quoted form. Returns `{:ok, quoted_form}` if it succeeds, `{:error, {line, error, token}}` otherwise. #### Options * `:file` - the filename to be reported in case of parsing errors. Defaults to "nofile". * `:line` - the starting line of the string being parsed. Defaults to 1. * `:columns` - when `true`, attach a `:column` key to the quoted metadata. Defaults to `false`. * `:existing_atoms_only` - when `true`, raises an error when non-existing atoms are found by the tokenizer. Defaults to `false`. * `:static_atom_encoder` - The static atom encoder function, see "The `:static_atom_encoder` function" section below. This option overrides the `:existing_atoms_only` behaviour for static atoms but `:existing_atoms_only` is still used for dynamic atoms, such as atoms with interpolations. * `:warn_on_unnecessary_quotes` - when `false`, does not warn when atoms, keywords or calls have unnecessary quotes on them. Defaults to `true`. #### [`Macro.to_string/2`](macro#to_string/2) The opposite of converting a string to its quoted form is [`Macro.to_string/2`](macro#to_string/2), which converts a quoted form to a string/binary representation. #### The `:static_atom_encoder` function When `static_atom_encoder: &my_encoder/2` is passed as an argument, `my_encoder/2` is called every time the tokenizer needs to create a "static" atom. Static atoms are atoms in the AST that function as aliases, remote calls, local calls, variable names, regular atoms and keyword lists. The encoder function will receive the atom name (as a binary) and a keyword list with the current file, line and column. It must return `{:ok, token :: term} | {:error, reason :: binary}`. The encoder function is supposed to create an atom from the given string. It is required to return either `{:ok, term}`, where term is an atom. It is possible to return something else than an atom, however, in that case the AST is no longer "valid" in that it cannot be used to compile or evaluate Elixir code. A use case for this is if you want to use the Elixir parser in a user-facing situation, but you don't want to exhaust the atom table. The atom encoder is not called for *all* atoms that are present in the AST. It won't be invoked for the following atoms: * operators (`:+`, `:-`, and so on) * syntax keywords (`fn`, `do`, `else`, and so on) * atoms containing interpolation (`:"#{1 + 1} is two"`), as these atoms are constructed at runtime. ### string\_to\_quoted!(string, opts \\ []) #### Specs ``` string_to_quoted!(List.Chars.t(), keyword()) :: Macro.t() ``` Converts the given string to its quoted form. It returns the ast if it succeeds, raises an exception otherwise. The exception is a [`TokenMissingError`](tokenmissingerror) in case a token is missing (usually because the expression is incomplete), [`SyntaxError`](syntaxerror) otherwise. Check [`string_to_quoted/2`](#string_to_quoted/2) for options information. ### unrequire\_files(files) #### Specs ``` unrequire_files([binary()]) :: :ok ``` Removes files from the required files list. The modules defined in the file are not removed; calling this function only removes them from the list, allowing them to be required again. #### Examples ``` # Require EEx test code Code.require_file("../eex/test/eex_test.exs") # Now unrequire all files Code.unrequire_files(Code.required_files()) # Notice modules are still available function_exported?(EExTest.Compiled, :before_compile, 0) #=> true ```
programming_docs
elixir Unicode Syntax Unicode Syntax ============== Elixir supports Unicode throughout the language. Quoted identifiers, such as strings (`"olá"`) and charlists (`'olá'`), support Unicode since Elixir v1.0. Strings are UTF-8 encoded. Charlists are lists of Unicode code points. In such cases, the contents are kept as written by developers, without any transformation. Elixir also supports Unicode in identifiers since Elixir v1.5, as defined in the [Unicode Annex #31](https://unicode.org/reports/tr31/). The focus of this document is to describe how Elixir implements the requirements outlined in the Unicode Annex. These requirements are referred to as R1, R6 and so on. To check the Unicode version of your current Elixir installation, run `String.Unicode.version()`. R1. Default Identifiers ------------------------ The general Elixir identifier rule is specified as: ``` <Identifier> := <Start> <Continue>* <Ending>? ``` where `<Start>` uses the same categories as the spec but restricts them to the NFC form (see R6): > > characters derived from the Unicode General Category of uppercase letters, lowercase letters, titlecase letters, modifier letters, other letters, letter numbers, plus `Other_ID_Start`, minus `Pattern_Syntax` and `Pattern_White_Space` code points > > In set notation: `[\p{L}\p{Nl}\p{Other_ID_Start}-\p{Pattern_Syntax}-\p{Pattern_White_Space}]` > > and `<Continue>` uses the same categories as the spec but restricts them to the NFC form (see R6): > > ID\_Start characters, plus characters having the Unicode General Category of nonspacing marks, spacing combining marks, decimal number, connector punctuation, plus `Other_ID_Continue`, minus `Pattern_Syntax` and `Pattern_White_Space` code points. > > In set notation: `[\p{ID_Start}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\p{Other_ID_Continue}-\p{Pattern_Syntax}-\p{Pattern_White_Space}]` > > `<Ending>` is an addition specific to Elixir that includes only the code points `?` (003F) and `!` (0021). The spec also provides a `<Medial>` set but Elixir does not include any character on this set. Therefore the identifier rule has been simplified to consider this. Elixir does not allow the use of ZWJ or ZWNJ in identifiers and therefore does not implement R1a. R1b is guaranteed for backwards compatibility purposes. ### Atoms Unicode atoms in Elixir follow the identifier rule above with the following modifications: * `<Start>` includes the code point `_` (005F) * `<Continue>` includes the code point `@` (0040) > > Note that all Elixir operators are also valid atoms. Therefore `:+`, `:@`, `:|>`, and others are all valid atoms. The full description of valid atoms is available in the Syntax Reference, this document covers only the rules for identifier-based atoms. > > ### Variables Variables in Elixir follow the identifier rule above with the following modifications: * `<Start>` includes the code point `_` (005F) * `<Start>` must not include Lu (letter uppercase) and Lt (letter titlecase) characters R3. Pattern\_White\_Space and Pattern\_Syntax Characters --------------------------------------------------------- Elixir supports only code points `\t` (0009), `\n` (000A), `\r` (000D) and `\s` (0020) as whitespace and therefore does not follow requirement R3. R3 requires a wider variety of whitespace and syntax characters to be supported. R6. Filtered Normalized Identifiers ------------------------------------ Identifiers in Elixir are case sensitive. Elixir requires all atoms and variables to be in NFC form. Any other form will fail with a relevant error message. Quoted-atoms and strings can, however, be in any form and are not verified by the parser. In other words, the atom `:josé` can only be written with the code points `006A 006F 0073 00E9`. Using another normalization form will lead to a tokenizer error. On the other hand, `:"josé"` may be written as `006A 006F 0073 00E9` or `006A 006F 0073 0065 0301`, since it is written between quotes. Choosing requirement R6 automatically excludes requirements R4, R5 and R7. elixir URI URI ==== Utilities for working with URIs. This module provides functions for working with URIs (for example, parsing URIs or encoding query strings). The functions in this module are implemented according to [RFC 3986](https://tools.ietf.org/html/rfc3986). Summary ======== Types ------ [t()](#t:t/0) Functions ---------- [char\_reserved?(character)](#char_reserved?/1) Checks if `character` is a reserved one in a URI. [char\_unescaped?(character)](#char_unescaped?/1) Checks if `character` is allowed unescaped in a URI. [char\_unreserved?(character)](#char_unreserved?/1) Checks if `character` is an unreserved one in a URI. [decode(uri)](#decode/1) Percent-unescapes a URI. [decode\_query(query, map \\ %{})](#decode_query/2) Decodes a query string into a map. [decode\_www\_form(string)](#decode_www_form/1) Decodes `string` as "x-www-form-urlencoded". [default\_port(scheme)](#default_port/1) Returns the default port for a given `scheme`. [default\_port(scheme, port)](#default_port/2) Registers the default `port` for the given `scheme`. [encode(string, predicate \\ &char\_unescaped?/1)](#encode/2) Percent-escapes all characters that require escaping in `string`. [encode\_query(enumerable)](#encode_query/1) Encodes an enumerable into a query string. [encode\_www\_form(string)](#encode_www_form/1) Encodes `string` as "x-www-form-urlencoded". [merge(uri, rel)](#merge/2) Merges two URIs. [parse(uri)](#parse/1) Parses a well-formed URI reference into its components. [query\_decoder(query)](#query_decoder/1) Returns a stream of two-element tuples representing key-value pairs in the given `query`. [to\_string(uri)](#to_string/1) Returns the string representation of the given [URI struct](#t:t/0). Types ====== ### t() #### Specs ``` t() :: %URI{ authority: nil | binary(), fragment: nil | binary(), host: nil | binary(), path: nil | binary(), port: nil | :inet.port_number(), query: nil | binary(), scheme: nil | binary(), userinfo: nil | binary() } ``` Functions ========== ### char\_reserved?(character) #### Specs ``` char_reserved?(byte()) :: boolean() ``` Checks if `character` is a reserved one in a URI. As specified in [RFC 3986, section 2.2](https://tools.ietf.org/html/rfc3986#section-2.2), the following characters are reserved: `:`, `/`, `?`, `#`, `[`, `]`, `@`, `!`, `$`, `&`, `'`, `(`, `)`, `*`, `+`, `,`, `;`, `=` #### Examples ``` iex> URI.char_reserved?(?+) true ``` ### char\_unescaped?(character) #### Specs ``` char_unescaped?(byte()) :: boolean() ``` Checks if `character` is allowed unescaped in a URI. This is the default used by [`URI.encode/2`](uri#encode/2) where both reserved and unreserved characters are kept unescaped. #### Examples ``` iex> URI.char_unescaped?(?{) false ``` ### char\_unreserved?(character) #### Specs ``` char_unreserved?(byte()) :: boolean() ``` Checks if `character` is an unreserved one in a URI. As specified in [RFC 3986, section 2.3](https://tools.ietf.org/html/rfc3986#section-2.3), the following characters are unreserved: * Alphanumeric characters: `A-Z`, `a-z`, `0-9` * `~`, `_`, `-` #### Examples ``` iex> URI.char_unreserved?(?_) true ``` ### decode(uri) #### Specs ``` decode(binary()) :: binary() ``` Percent-unescapes a URI. #### Examples ``` iex> URI.decode("https%3A%2F%2Felixir-lang.org") "https://elixir-lang.org" ``` ### decode\_query(query, map \\ %{}) #### Specs ``` decode_query(binary(), %{optional(binary()) => binary()}) :: %{ optional(binary()) => binary() } ``` Decodes a query string into a map. Given a query string in the form of `key1=value1&key2=value2...`, this function inserts each key-value pair in the query string as one entry in the given `map`. Keys and values in the resulting map will be binaries. Keys and values will be percent-unescaped. Use [`query_decoder/1`](#query_decoder/1) if you want to iterate over each value manually. #### Examples ``` iex> URI.decode_query("foo=1&bar=2") %{"bar" => "2", "foo" => "1"} iex> URI.decode_query("percent=oh+yes%21", %{"starting" => "map"}) %{"percent" => "oh yes!", "starting" => "map"} ``` ### decode\_www\_form(string) #### Specs ``` decode_www_form(binary()) :: binary() ``` Decodes `string` as "x-www-form-urlencoded". #### Examples ``` iex> URI.decode_www_form("%3Call+in%2F") "<all in/" ``` ### default\_port(scheme) #### Specs ``` default_port(binary()) :: nil | non_neg_integer() ``` Returns the default port for a given `scheme`. If the scheme is unknown to the [`URI`](#content) module, this function returns `nil`. The default port for any scheme can be configured globally via [`default_port/2`](#default_port/2). #### Examples ``` iex> URI.default_port("ftp") 21 iex> URI.default_port("ponzi") nil ``` ### default\_port(scheme, port) #### Specs ``` default_port(binary(), non_neg_integer()) :: :ok ``` Registers the default `port` for the given `scheme`. After this function is called, `port` will be returned by [`default_port/1`](#default_port/1) for the given scheme `scheme`. Note that this function changes the default port for the given `scheme` *globally*, meaning for every application. It is recommended for this function to be invoked in your application's start callback in case you want to register new URIs. ### encode(string, predicate \\ &char\_unescaped?/1) #### Specs ``` encode(binary(), (byte() -> as_boolean(term()))) :: binary() ``` Percent-escapes all characters that require escaping in `string`. This means reserved characters, such as `:` and `/`, and the so-called unreserved characters, which have the same meaning both escaped and unescaped, won't be escaped by default. See `encode_www_form` if you are interested in escaping reserved characters too. This function also accepts a `predicate` function as an optional argument. If passed, this function will be called with each byte in `string` as its argument and should return a truthy value (anything other than `false` or `nil`) if the given byte should be left as is, or return a falsy value (`false` or `nil`) if the character should be escaped. #### Examples ``` iex> URI.encode("ftp://s-ite.tld/?value=put it+й") "ftp://s-ite.tld/?value=put%20it+%D0%B9" iex> URI.encode("a string", &(&1 != ?i)) "a str%69ng" ``` ### encode\_query(enumerable) #### Specs ``` encode_query(Enum.t()) :: binary() ``` Encodes an enumerable into a query string. Takes an enumerable that enumerates as a list of two-element tuples (e.g., a map or a keyword list) and returns a string in the form of `key1=value1&key2=value2...` where keys and values are URL encoded as per [`encode_www_form/1`](#encode_www_form/1). Keys and values can be any term that implements the [`String.Chars`](string.chars) protocol with the exception of lists, which are explicitly forbidden. #### Examples ``` iex> hd = %{"foo" => 1, "bar" => 2} iex> URI.encode_query(hd) "bar=2&foo=1" iex> query = %{"key" => "value with spaces"} iex> URI.encode_query(query) "key=value+with+spaces" iex> URI.encode_query(%{key: [:a, :list]}) ** (ArgumentError) encode_query/1 values cannot be lists, got: [:a, :list] ``` ### encode\_www\_form(string) #### Specs ``` encode_www_form(binary()) :: binary() ``` Encodes `string` as "x-www-form-urlencoded". #### Example ``` iex> URI.encode_www_form("put: it+й") "put%3A+it%2B%D0%B9" ``` ### merge(uri, rel) #### Specs ``` merge(t() | binary(), t() | binary()) :: t() ``` Merges two URIs. This function merges two URIs as per [RFC 3986, section 5.2](https://tools.ietf.org/html/rfc3986#section-5.2). #### Examples ``` iex> URI.merge(URI.parse("http://google.com"), "/query") |> to_string() "http://google.com/query" iex> URI.merge("http://example.com", "http://google.com") |> to_string() "http://google.com" ``` ### parse(uri) #### Specs ``` parse(t() | binary()) :: t() ``` Parses a well-formed URI reference into its components. Note this function expects a well-formed URI and does not perform any validation. See the "Examples" section below for examples of how [`URI.parse/1`](uri#parse/1) can be used to parse a wide range of URIs. This function uses the parsing regular expression as defined in [RFC 3986, Appendix B](https://tools.ietf.org/html/rfc3986#appendix-B). When a URI is given without a port, the value returned by [`URI.default_port/1`](uri#default_port/1) for the URI's scheme is used for the `:port` field. If a `%URI{}` struct is given to this function, this function returns it unmodified. #### Examples ``` iex> URI.parse("https://elixir-lang.org/") %URI{ authority: "elixir-lang.org", fragment: nil, host: "elixir-lang.org", path: "/", port: 443, query: nil, scheme: "https", userinfo: nil } iex> URI.parse("//elixir-lang.org/") %URI{ authority: "elixir-lang.org", fragment: nil, host: "elixir-lang.org", path: "/", port: nil, query: nil, scheme: nil, userinfo: nil } iex> URI.parse("/foo/bar") %URI{ authority: nil, fragment: nil, host: nil, path: "/foo/bar", port: nil, query: nil, scheme: nil, userinfo: nil } iex> URI.parse("foo/bar") %URI{ authority: nil, fragment: nil, host: nil, path: "foo/bar", port: nil, query: nil, scheme: nil, userinfo: nil } ``` ### query\_decoder(query) #### Specs ``` query_decoder(binary()) :: Enumerable.t() ``` Returns a stream of two-element tuples representing key-value pairs in the given `query`. Key and value in each tuple will be binaries and will be percent-unescaped. #### Examples ``` iex> URI.query_decoder("foo=1&bar=2") |> Enum.to_list() [{"foo", "1"}, {"bar", "2"}] iex> URI.query_decoder("food=bread%26butter&drinks=tap%20water") |> Enum.to_list() [{"food", "bread&butter"}, {"drinks", "tap water"}] ``` ### to\_string(uri) #### Specs ``` to_string(t()) :: binary() ``` Returns the string representation of the given [URI struct](#t:t/0). #### Examples ``` iex> URI.to_string(URI.parse("http://google.com")) "http://google.com" iex> URI.to_string(%URI{scheme: "foo", host: "bar.baz"}) "foo://bar.baz" ``` Note that when creating this string representation, the `:authority` value will be used if the `:host` is `nil`. Otherwise, the `:userinfo`, `:host`, and `:port` will be used. ``` iex> URI.to_string(%URI{authority: "[email protected]:80"}) "//[email protected]:80" iex> URI.to_string(%URI{userinfo: "bar", host: "example.org", port: 81}) "//[email protected]:81" iex> URI.to_string(%URI{ ...> authority: "[email protected]:80", ...> userinfo: "bar", ...> host: "example.org", ...> port: 81 ...> }) "//[email protected]:81" ``` elixir HashSet HashSet ======== This module is deprecated. Use MapSet instead. Tuple-based HashSet implementation. This module is deprecated. Use the [`MapSet`](mapset) module instead. Summary ======== Types ------ [t()](#t:t/0) Functions ---------- [delete(set, term)](#delete/2) deprecated [difference(set1, set2)](#difference/2) deprecated [disjoint?(set1, set2)](#disjoint?/2) deprecated [equal?(set1, set2)](#equal?/2) deprecated [intersection(set1, set2)](#intersection/2) deprecated [member?(hash\_set, term)](#member?/2) deprecated [new()](#new/0) deprecated [put(hash\_set, term)](#put/2) deprecated [size(hash\_set)](#size/1) deprecated [subset?(set1, set2)](#subset?/2) deprecated [to\_list(set)](#to_list/1) deprecated [union(set1, set2)](#union/2) deprecated Types ====== ### t() #### Specs ``` t() ``` Functions ========== ### delete(set, term) This function is deprecated. Use the MapSet module instead. ### difference(set1, set2) This function is deprecated. Use the MapSet module instead. ### disjoint?(set1, set2) This function is deprecated. Use the MapSet module instead. ### equal?(set1, set2) This function is deprecated. Use the MapSet module instead. ### intersection(set1, set2) This function is deprecated. Use the MapSet module instead. ### member?(hash\_set, term) This function is deprecated. Use the MapSet module instead. ### new() This function is deprecated. Use the MapSet module instead. #### Specs ``` new() :: Set.t() ``` ### put(hash\_set, term) This function is deprecated. Use the MapSet module instead. ### size(hash\_set) This function is deprecated. Use the MapSet module instead. ### subset?(set1, set2) This function is deprecated. Use the MapSet module instead. ### to\_list(set) This function is deprecated. Use the MapSet module instead. ### union(set1, set2) This function is deprecated. Use the MapSet module instead. elixir IEx IEx ==== Elixir's interactive shell. Some of the functionalities described here will not be available depending on your terminal. In particular, if you get a message saying that the smart terminal could not be run, some of the features described here won't work. Helpers -------- IEx provides a bunch of helpers. They can be accessed by typing `h()` into the shell or as a documentation for the [`IEx.Helpers`](iex.helpers) module. Autocomplete ------------- To discover a module's public functions or other modules, type the module name followed by a dot, then press tab to trigger autocomplete. For example: ``` Enum. ``` A module may export functions that are not meant to be used directly: these functions won't be autocompleted by IEx. IEx will not autocomplete functions annotated with `@doc false`, `@impl true`, or functions that aren't explicitly documented and where the function name is in the form of `__foo__`. Autocomplete may not be available on some Windows shells. You may need to pass the `--werl` option when starting IEx, as in `iex --werl` for it to work. `--werl` may be permanently enabled by setting the `IEX_WITH_WERL` environment variable. Shell history -------------- It is possible to get shell history by passing some options that enable it in the VM. This can be done on a per-need basis when starting IEx: ``` iex --erl "-kernel shell_history enabled" ``` If you would rather enable it on your system as a whole, you can use the `ERL_AFLAGS` environment variable and make sure that it is set accordingly on your terminal/shell configuration. On Unix-like / Bash: ``` export ERL_AFLAGS="-kernel shell_history enabled" ``` On Windows: ``` set ERL_AFLAGS "-kernel shell_history enabled" ``` On Windows 10 / PowerShell: ``` $env:ERL_AFLAGS = "-kernel shell_history enabled" ``` Expressions in IEx ------------------- As an interactive shell, IEx evaluates expressions. This has some interesting consequences that are worth discussing. The first one is that the code is truly evaluated and not compiled. This means that any benchmarking done in the shell is going to have skewed results. So never run any profiling nor benchmarks in the shell. Second, IEx allows you to break an expression into many lines, since this is common in Elixir. For example: ``` iex(1)> "ab ...(1)> c" "ab\nc" ``` In the example above, the shell will be expecting more input until it finds the closing quote. Sometimes it is not obvious which character the shell is expecting, and the user may find themselves trapped in the state of incomplete expression with no ability to terminate it other than by exiting the shell. For such cases, there is a special break-trigger (`#iex:break`) that when encountered on a line by itself will force the shell to break out of any pending expression and return to its normal state: ``` iex(1)> ["ab ...(1)> c" ...(1)> " ...(1)> ] ...(1)> #iex:break ** (TokenMissingError) iex:1: incomplete expression ``` Pasting multiline expressions into IEx --------------------------------------- IEx evaluates its input line by line in an eagerly fashion which means that if at the end of a line the code seen so far is a complete expression IEx will evaluate it at that point. This behaviour may produce errors for expressions that have been formatted across multiple lines which is often the case for piped expressions. Consider the following expression using the [`|>/2`](https://hexdocs.pm/elixir/Kernel.html#%7C%3E/2) operator: ``` iex(1)> [1, [2], 3] |> List.flatten() [1, 2, 3] ``` When written in multiline form and pasted into IEx this valid expression produces a syntax error: ``` iex(1)> [1, [2], 3] [1, [2], 3] iex(2)> |> List.flatten() ** (SyntaxError) iex:2: syntax error before: '|>' ``` As IEx evaluates its input line by line, it will first encounter `[1, [2], 3]`. As a list is a valid expression, IEx will evaluate it immediately before looking at the next input line. Only then will IEx attempt to evaluate the now incomplete expression `|> List.flatten()`, which on its own is missing its left operand. The evaluation thus fails with the above syntax error. In order to help IEx understand that an expression consists of multiple lines we can wrap it into parentheses: ``` iex(1)> ( ...(1)> [1, [2], 3] ...(1)> |> List.flatten() ...(1)> ) [1, 2, 3] ``` Note that this not only works with single expressions but also with arbitrary code blocks. The BREAK menu --------------- Inside IEx, hitting `Ctrl+C` will open up the `BREAK` menu. In this menu you can quit the shell, see process and ETS tables information and much more. Exiting the shell ------------------ There are a few ways to quit the IEx shell: * via the `BREAK` menu (available via `Ctrl+C`) by typing `q`, pressing enter * by hitting `Ctrl+C`, `Ctrl+C` * by hitting `Ctrl+\` If you are connected to remote shell, it remains alive after disconnection. Prying and breakpoints ----------------------- IEx also has the ability to set breakpoints on Elixir code and "pry" into running processes. This allows the developer to have an IEx session run inside a given function. [`IEx.pry/0`](iex#pry/0) can be used when you are able to modify the source code directly and recompile it: ``` def my_fun(arg1, arg2) do require IEx; IEx.pry() ... implementation ... end ``` When the code is executed, it will ask you for permission to be introspected. Alternatively, you can use [`IEx.break!/4`](iex#break!/4) to setup a breakpoint on a given module, function and arity you have no control of. While [`IEx.break!/4`](iex#break!/4) is more flexible, it does not contain information about imports and aliases from the source code. The User switch command ------------------------ Besides the `BREAK` menu, one can type `Ctrl+G` to get to the `User switch command` menu. When reached, you can type `h` to get more information. In this menu, developers are able to start new shells and alternate between them. Let's give it a try: ``` User switch command --> s 'Elixir.IEx' --> c ``` The command above will start a new shell and connect to it. Create a new variable called `hello` and assign some value to it: ``` hello = :world ``` Now, let's roll back to the first shell: ``` User switch command --> c 1 ``` Now, try to access the `hello` variable again: ``` hello ** (UndefinedFunctionError) undefined function hello/0 ``` The command above fails because we have switched shells. Since shells are isolated from each other, you can't access the variables defined in one shell from the other one. The `User switch command` can also be used to terminate an existing session, for example when the evaluator gets stuck in an infinite loop or when you are stuck typing an expression: ``` User switch command --> i --> c ``` The `User switch command` menu also allows developers to connect to remote shells using the `r` command. A topic which we will discuss next. Remote shells -------------- IEx allows you to connect to another node in two fashions. First of all, we can only connect to a shell if we give names both to the current shell and the shell we want to connect to. Let's give it a try. First start a new shell: ``` $ iex --sname foo iex(foo@HOST)1> ``` The string between the parentheses in the prompt is the name of your node. We can retrieve it by calling the [`node/0`](https://hexdocs.pm/elixir/Kernel.html#node/0) function: ``` iex(foo@HOST)1> node() :"foo@HOST" iex(foo@HOST)2> Node.alive?() true ``` For fun, let's define a simple module in this shell too: ``` iex(foo@HOST)3> defmodule Hello do ...(foo@HOST)3> def world, do: "it works!" ...(foo@HOST)3> end ``` Now, let's start another shell, giving it a name as well: ``` $ iex --sname bar iex(bar@HOST)1> ``` If we try to dispatch to `Hello.world`, it won't be available as it was defined only in the other shell: ``` iex(bar@HOST)1> Hello.world() ** (UndefinedFunctionError) undefined function Hello.world/0 ``` However, we can connect to the other shell remotely. Open up the `User switch command` prompt (Ctrl+G) and type: ``` User switch command --> r 'foo@HOST' 'Elixir.IEx' --> c ``` Now we are connected into the remote node, as the prompt shows us, and we can access the information and modules defined over there: ``` iex(foo@HOST)1> Hello.world() "it works!" ``` In fact, connecting to remote shells is so common that we provide a shortcut via the command line as well: ``` $ iex --sname baz --remsh foo@HOST ``` Where "remsh" means "remote shell". In general, Elixir supports: * remsh from an Elixir node to an Elixir node * remsh from a plain Erlang node to an Elixir node (through the ^G menu) * remsh from an Elixir node to a plain Erlang node (and get an `erl` shell there) Connecting an Elixir shell to a remote node without Elixir is **not** supported. The .iex.exs file ------------------ When starting, IEx looks for a local `.iex.exs` file (located in the current working directory), then a global one (located at `~/.iex.exs`) and loads the first one it finds (if any). The code in the loaded `.iex.exs` file is evaluated in the shell's context. So, for instance, any modules that are loaded or variables that are bound in the `.iex.exs` file will be available in the shell after it has booted. For example, take the following `.iex.exs` file: ``` # Load another ".iex.exs" file import_file("~/.iex.exs") # Import some module from lib that may not yet have been defined import_if_available(MyApp.Mod) # Print something before the shell starts IO.puts("hello world") # Bind a variable that'll be accessible in the shell value = 13 ``` Running IEx in the directory where the above `.iex.exs` file is located results in: ``` $ iex Erlang/OTP 20 [...] hello world Interactive Elixir - press Ctrl+C to exit (type h() ENTER for help) iex(1)> value 13 ``` It is possible to load another file by supplying the `--dot-iex` option to IEx. See `iex --help`. Configuring the shell ---------------------- There are a number of customization options provided by IEx. Take a look at the docs for the [`IEx.configure/1`](iex#configure/1) function by typing `h IEx.configure/1`. Those options can be configured in your project configuration file or globally by calling [`IEx.configure/1`](iex#configure/1) from your `~/.iex.exs` file. For example: ``` # .iex.exs IEx.configure(inspect: [limit: 3]) ``` Now run the shell: ``` $ iex Erlang/OTP 20 [...] Interactive Elixir - press Ctrl+C to exit (type h() ENTER for help) iex(1)> [1, 2, 3, 4, 5] [1, 2, 3, ...] ``` Summary ======== Functions ---------- [after\_spawn()](#after_spawn/0) Returns registered `after_spawn` callbacks. [after\_spawn(fun)](#after_spawn/1) Registers a function to be invoked after the IEx process is spawned. [break!(ast, stops \\ 1)](#break!/2) Macro-based shortcut for [`IEx.break!/4`](iex#break!/4). [break!(module, function, arity, stops \\ 1)](#break!/4) Sets up a breakpoint in `module`, `function` and `arity` with the given number of `stops`. [color(color, string)](#color/2) Returns `string` escaped using the specified `color`. [configuration()](#configuration/0) Returns IEx configuration. [configure(options)](#configure/1) Configures IEx. [inspect\_opts()](#inspect_opts/0) Returns the options used for inspecting. [pry()](#pry/0) Pries into the process environment. [started?()](#started?/0) Returns `true` if IEx was started, `false` otherwise. [width()](#width/0) Returns the IEx width for printing. Functions ========== ### after\_spawn() #### Specs ``` after_spawn() :: [(... -> any())] ``` Returns registered `after_spawn` callbacks. ### after\_spawn(fun) #### Specs ``` after_spawn((... -> any())) :: :ok ``` Registers a function to be invoked after the IEx process is spawned. ### break!(ast, stops \\ 1) Macro-based shortcut for [`IEx.break!/4`](iex#break!/4). ### break!(module, function, arity, stops \\ 1) Sets up a breakpoint in `module`, `function` and `arity` with the given number of `stops`. This function will instrument the given module and load a new version in memory with breakpoints at the given function and arity. If the module is recompiled, all breakpoints are lost. When a breakpoint is reached, IEx will ask if you want to `pry` the given function and arity. In other words, this works similar to [`IEx.pry/0`](iex#pry/0) as the running process becomes the evaluator of IEx commands and is temporarily changed to have a custom group leader. However, differently from [`IEx.pry/0`](iex#pry/0), aliases and imports from the source code won't be available in the shell. IEx helpers includes many conveniences related to breakpoints. Below they are listed with the full module, such as [`IEx.Helpers.breaks/0`](iex.helpers#breaks/0), but remember it can be called directly as `breaks()` inside IEx. They are: * [`IEx.Helpers.break!/2`](iex.helpers#break!/2) - sets up a breakpoint for a given `Mod.fun/arity` * [`IEx.Helpers.break!/4`](iex.helpers#break!/4) - sets up a breakpoint for the given module, function, arity * [`IEx.Helpers.breaks/0`](iex.helpers#breaks/0) - prints all breakpoints and their IDs * [`IEx.Helpers.continue/0`](iex.helpers#continue/0) - continues until the next breakpoint in the same shell * [`IEx.Helpers.open/0`](iex.helpers#open/0) - opens editor on the current breakpoint * [`IEx.Helpers.remove_breaks/0`](iex.helpers#remove_breaks/0) - removes all breakpoints in all modules * [`IEx.Helpers.remove_breaks/1`](iex.helpers#remove_breaks/1) - removes all breakpoints in a given module * [`IEx.Helpers.reset_break/1`](iex.helpers#reset_break/1) - sets the number of stops on the given ID to zero * [`IEx.Helpers.reset_break/3`](iex.helpers#reset_break/3) - sets the number of stops on the given module, function, arity to zero * [`IEx.Helpers.respawn/0`](iex.helpers#respawn/0) - starts a new shell (breakpoints will ask for permission once more) * [`IEx.Helpers.whereami/1`](iex.helpers#whereami/1) - shows the current location By default, the number of stops in a breakpoint is 1. Any follow-up call won't stop the code execution unless another breakpoint is set. Alternatively, the number of stops can be increased by passing the `stops` argument. [`IEx.Helpers.reset_break/1`](iex.helpers#reset_break/1) and [`IEx.Helpers.reset_break/3`](iex.helpers#reset_break/3) can be used to reset the number back to zero. Note the module remains "instrumented" even after all stops on all breakpoints are consumed. You can remove the instrumentation in a given module by calling [`IEx.Helpers.remove_breaks/1`](iex.helpers#remove_breaks/1) and on all modules by calling [`IEx.Helpers.remove_breaks/0`](iex.helpers#remove_breaks/0). To exit a breakpoint, the developer can either invoke `continue()`, which will block the shell until the next breakpoint is found or the process terminates, or invoke `respawn()`, which starts a new IEx shell, freeing up the pried one. #### Examples The examples below will use `break!`, assuming that you are setting a breakpoint directly from your IEx shell. But you can set up a break from anywhere by using the fully qualified name `IEx.break!`. The following sets up a breakpoint on [`URI.decode_query/2`](https://hexdocs.pm/elixir/URI.html#decode_query/2): ``` break! URI, :decode_query, 2 ``` This call will setup a breakpoint that stops once. To set a breakpoint that will stop 10 times: ``` break! URI, :decode_query, 2, 10 ``` [`IEx.break!/2`](iex#break!/2) is a convenience macro that allows breakpoints to be given in the `Mod.fun/arity` format: ``` break! URI.decode_query/2 ``` Or to set a breakpoint that will stop 10 times: ``` break! URI.decode_query/2, 10 ``` This function returns the breakpoint ID and will raise if there is an error setting up the breakpoint. #### Patterns and guards [`IEx.break!/2`](iex#break!/2) allows patterns to be given, triggering the breakpoint only in some occasions. For example, to trigger the breakpoint only when the first argument is the "foo=bar" string: ``` break! URI.decode_query("foo=bar", _) ``` Or to trigger it whenever the second argument is a map with more than one element: ``` break! URI.decode_query(_, map) when map_size(map) > 0 ``` Only a single break point can be set per function. So if you call `IEx.break!` multiple times with different patterns, only the last pattern is kept. Notice that, while patterns may be given to macros, remember that macros receive ASTs as arguments, and not values. For example, if you try to break on a macro with the following pattern: ``` break! MyModule.some_macro(pid) when pid == self() ``` This breakpoint will never be reached, because a macro never receives a PID. Even if you call the macro as `MyModule.some_macro(self())`, the macro will receive the AST representing the `self()` call, and not the PID itself. #### Breaks and [`mix test`](https://hexdocs.pm/mix/Mix.Tasks.Test.html) To use [`IEx.break!/4`](iex#break!/4) during tests, you need to run `mix` inside the `iex` command and pass the `--trace` to [`mix test`](https://hexdocs.pm/mix/Mix.Tasks.Test.html) to avoid running into timeouts: ``` iex -S mix test --trace iex -S mix test path/to/file:line --trace ``` ### color(color, string) #### Specs ``` color(atom(), String.t()) :: String.t() ``` Returns `string` escaped using the specified `color`. ANSI escapes in `string` are not processed in any way. ### configuration() #### Specs ``` configuration() :: keyword() ``` Returns IEx configuration. ### configure(options) #### Specs ``` configure(keyword()) :: :ok ``` Configures IEx. The supported options are: * `:colors` * `:inspect` * `:width` * `:history_size` * `:default_prompt` * `:alive_prompt` They are discussed individually in the sections below. #### Colors A keyword list that encapsulates all color settings used by the shell. See documentation for the [`IO.ANSI`](https://hexdocs.pm/elixir/IO.ANSI.html) module for the list of supported colors and attributes. List of supported keys in the keyword list: * `:enabled` - boolean value that allows for switching the coloring on and off * `:eval_result` - color for an expression's resulting value * `:eval_info` - ... various informational messages * `:eval_error` - ... error messages * `:eval_interrupt` - ... interrupt messages * `:stack_info` - ... the stacktrace color * `:blame_diff` - ... when blaming source with no match * `:ls_directory` - ... for directory entries (ls helper) * `:ls_device` - ... device entries (ls helper) When printing documentation, IEx will convert the Markdown documentation to ANSI as well. Colors for this can be configured via: * `:doc_code` - the attributes for code blocks (cyan, bright) * `:doc_inline_code` - inline code (cyan) * `:doc_headings` - h1 and h2 (yellow, bright) * `:doc_title` - the overall heading for the output (reverse, yellow, bright) * `:doc_bold` - (bright) * `:doc_underline` - (underline) IEx will also color inspected expressions using the `:syntax_colors` option. Such can be disabled with: ``` IEx.configure(colors: [syntax_colors: false]) ``` You can also configure the syntax colors, however, as desired: ``` IEx.configure(colors: [syntax_colors: [atom: :red]]) ``` Configuration for most built-in data types are supported: `:atom`, `:string`, `:binary`, `:list`, `:number`, `:boolean`, `:nil`, etc. The default is: ``` [number: :magenta, atom: :cyan, string: :green, boolean: :magenta, nil: :magenta] ``` #### Inspect A keyword list containing inspect options used by the shell when printing results of expression evaluation. Default to pretty formatting with a limit of 50 entries. To show all entries, configure the limit to `:infinity`: ``` IEx.configure(inspect: [limit: :infinity]) ``` See [`Inspect.Opts`](https://hexdocs.pm/elixir/Inspect.Opts.html) for the full list of options. #### Width An integer indicating the maximum number of columns to use in output. The default value is 80 columns. The actual output width is the minimum of this number and result of `:io.columns`. This way you can configure IEx to be your largest screen size and it should always take up the full width of your current terminal screen. #### History size Number of expressions and their results to keep in the history. The value is an integer. When it is negative, the history is unlimited. #### Prompt This is an option determining the prompt displayed to the user when awaiting input. The value is a keyword list with two possible keys representing prompt types: * `:default_prompt` - used when [`Node.alive?/0`](https://hexdocs.pm/elixir/Node.html#alive?/0) returns `false` * `:alive_prompt` - used when [`Node.alive?/0`](https://hexdocs.pm/elixir/Node.html#alive?/0) returns `true` The following values in the prompt string will be replaced appropriately: * `%counter` - the index of the history * `%prefix` - a prefix given by [`IEx.Server`](iex.server) * `%node` - the name of the local node ### inspect\_opts() #### Specs ``` inspect_opts() :: keyword() ``` Returns the options used for inspecting. ### pry() Pries into the process environment. This is useful for debugging a particular chunk of code when executed by a particular process. The process becomes the evaluator of IEx commands and is temporarily changed to have a custom group leader. Those values are reverted by calling [`IEx.Helpers.respawn/0`](iex.helpers#respawn/0), which starts a new IEx shell, freeing up the pried one. When a process is pried, all code runs inside IEx and has access to all imports and aliases from the original code. However, the code is evaluated and therefore cannot access private functions of the module being pried. Module functions still need to be accessed via `Mod.fun(args)`. Alternatively, you can use [`IEx.break!/4`](iex#break!/4) to setup a breakpoint on a given module, function and arity you have no control of. While [`IEx.break!/4`](iex#break!/4) is more flexible, it does not contain information about imports and aliases from the source code. #### Examples Let's suppose you want to investigate what is happening with some particular function. By invoking [`IEx.pry/0`](iex#pry/0) from the function, IEx will allow you to access its binding (variables), verify its lexical information and access the process information. Let's see an example: ``` import Enum, only: [map: 2] defmodule Adder do def add(a, b) do c = a + b require IEx; IEx.pry() end end ``` When invoking `Adder.add(1, 2)`, you will receive a message in your shell to pry the given environment. By allowing it, the shell will be reset and you gain access to all variables and the lexical scope from above: ``` pry(1)> map([a, b, c], &IO.inspect(&1)) 1 2 3 ``` Keep in mind that [`IEx.pry/0`](iex#pry/0) runs in the caller process, blocking the caller during the evaluation cycle. The caller process can be freed by calling [`respawn/0`](iex.helpers#respawn/0), which starts a new IEx evaluation cycle, letting this one go: ``` pry(2)> respawn() true Interactive Elixir - press Ctrl+C to exit (type h() ENTER for help) ``` Setting variables or importing modules in IEx does not affect the caller's environment. However, sending and receiving messages will change the process state. #### Pry and macros When setting up Pry inside a code defined by macros, such as: ``` defmacro __using__(_) do quote do def add(a, b) do c = a + b require IEx; IEx.pry() end end end ``` The variables defined inside `quote` won't be available during prying due to the hygiene mechanism in quoted expressions. The hygiene mechanism changes the variable names in quoted expressions so they don't collide with variables defined by the users of the macros. Therefore the original names are not available. #### Pry and [`mix test`](https://hexdocs.pm/mix/Mix.Tasks.Test.html) To use [`IEx.pry/0`](iex#pry/0) during tests, you need to run `mix` inside the `iex` command and pass the `--trace` to [`mix test`](https://hexdocs.pm/mix/Mix.Tasks.Test.html) to avoid running into timeouts: ``` iex -S mix test --trace iex -S mix test path/to/file:line --trace ``` ### started?() #### Specs ``` started?() :: boolean() ``` Returns `true` if IEx was started, `false` otherwise. ### width() #### Specs ``` width() :: pos_integer() ``` Returns the IEx width for printing. Used by helpers and it has a default maximum cap of 80 chars.
programming_docs
elixir mix run mix run ======== Starts the current application and runs code. [`mix run`](#content) can be used to start the current application dependencies, the application itself, and optionally run some code in its context. For long running systems, this is typically done with the `--no-halt` option: ``` mix run --no-halt ``` Once the current application and its dependencies have been started, you can run a script in its context by passing a filename: ``` mix run my_app_script.exs arg1 arg2 arg3 ``` Code to be executed can also be passed inline with the `-e` option: ``` mix run -e "DbUtils.delete_old_records()" -- arg1 arg2 arg3 ``` In both cases, the command-line arguments for the script or expression are available in [`System.argv/0`](https://hexdocs.pm/elixir/System.html#argv/0). Before doing anything, Mix will compile the current application if needed, unless you pass `--no-compile`. If for some reason the application needs to be configured before it is started, the `--no-start` option can be used and you are then responsible for starting all applications by using functions such as [`Application.ensure_all_started/1`](https://hexdocs.pm/elixir/Application.html#ensure_all_started/1). For more information about the application life-cycle and dynamically configuring applications, see the [`Application`](https://hexdocs.pm/elixir/Application.html) module. If you need to pass options to the Elixir executable at the same time you use [`mix run`](#content), it can be done as follows: ``` elixir --sname hello -S mix run --no-halt ``` This task is automatically reenabled, so it can be called multiple times with different arguments. Command-line options --------------------- * `--eval`, `-e` - evaluates the given code * `--require`, `-r` - executes the given pattern/file * `--parallel`, `-p` - makes all requires parallel * `--preload-modules` - preloads all modules defined in applications * `--no-compile` - does not compile even if files require compilation * `--no-deps-check` - does not check dependencies * `--no-archives-check` - does not check archives * `--no-halt` - does not halt the system after running the command * `--no-mix-exs` - allows the command to run even if there is no mix.exs * `--no-start` - does not start applications after compilation * `--no-elixir-version-check` - does not check the Elixir version from mix.exs elixir EEx EEx ==== EEx stands for Embedded Elixir. It allows you to embed Elixir code inside a string in a robust way. ``` iex> EEx.eval_string("foo <%= bar %>", bar: "baz") "foo baz" ``` API ---- This module provides 3 main APIs for you to use: 1. Evaluate a string (`eval_string`) or a file (`eval_file`) directly. This is the simplest API to use but also the slowest, since the code is evaluated and not compiled before. 2. Define a function from a string (`function_from_string`) or a file (`function_from_file`). This allows you to embed the template as a function inside a module which will then be compiled. This is the preferred API if you have access to the template at compilation time. 3. Compile a string (`compile_string`) or a file (`compile_file`) into Elixir syntax tree. This is the API used by both functions above and is available to you if you want to provide your own ways of handling the compiled template. Options -------- All functions in this module accept EEx-related options. They are: * `:line` - the line to be used as the template start. Defaults to 1. * `:file` - the file to be used in the template. Defaults to the given file the template is read from or to "nofile" when compiling from a string. * `:engine` - the EEx engine to be used for compilation. * `:trim` - trims whitespace left/right of quotation tags. If a quotation tag appears on its own in a given line, line endings are also removed. Engine ------- EEx has the concept of engines which allows you to modify or transform the code extracted from the given string or file. By default, [`EEx`](#content) uses the [`EEx.SmartEngine`](eex.smartengine) that provides some conveniences on top of the simple [`EEx.Engine`](eex.engine). ### Tags [`EEx.SmartEngine`](eex.smartengine) supports the following tags: ``` <% Elixir expression - inline with output %> <%= Elixir expression - replace with result %> <%% EEx quotation - returns the contents inside %> <%# Comments - they are discarded from source %> ``` All expressions that output something to the template **must** use the equals sign (`=`). Since everything in Elixir is an expression, there are no exceptions for this rule. For example, while some template languages would special-case [`if/2`](https://hexdocs.pm/elixir/Kernel.html#if/2) clauses, they are treated the same in EEx and also require `=` in order to have their result printed: ``` <%= if true do %> It is obviously true <% else %> This will never appear <% end %> ``` Notice that different engines may have different rules for each tag. Other tags may be added in future versions. ### Macros [`EEx.SmartEngine`](eex.smartengine) also adds some macros to your template. An example is the `@` macro which allows easy data access in a template: ``` iex> EEx.eval_string("<%= @foo %>", assigns: [foo: 1]) "1" ``` In other words, `<%= @foo %>` translates to: ``` <%= {:ok, v} = Access.fetch(assigns, :foo); v %> ``` The `assigns` extension is useful when the number of variables required by the template is not specified at compilation time. Summary ======== Functions ---------- [compile\_file(filename, options \\ [])](#compile_file/2) Gets a `filename` and generate a quoted expression that can be evaluated by Elixir or compiled to a function. [compile\_string(source, options \\ [])](#compile_string/2) Gets a string `source` and generate a quoted expression that can be evaluated by Elixir or compiled to a function. [eval\_file(filename, bindings \\ [], options \\ [])](#eval_file/3) Gets a `filename` and evaluate the values using the `bindings`. [eval\_string(source, bindings \\ [], options \\ [])](#eval_string/3) Gets a string `source` and evaluate the values using the `bindings`. [function\_from\_file(kind, name, file, args \\ [], options \\ [])](#function_from_file/5) Generates a function definition from the file contents. [function\_from\_string(kind, name, source, args \\ [], options \\ [])](#function_from_string/5) Generates a function definition from the string. Functions ========== ### compile\_file(filename, options \\ []) #### Specs ``` compile_file(String.t(), keyword()) :: Macro.t() ``` Gets a `filename` and generate a quoted expression that can be evaluated by Elixir or compiled to a function. ### compile\_string(source, options \\ []) #### Specs ``` compile_string(String.t(), keyword()) :: Macro.t() ``` Gets a string `source` and generate a quoted expression that can be evaluated by Elixir or compiled to a function. ### eval\_file(filename, bindings \\ [], options \\ []) #### Specs ``` eval_file(String.t(), keyword(), keyword()) :: any() ``` Gets a `filename` and evaluate the values using the `bindings`. #### Examples ``` # sample.eex foo <%= bar %> # iex EEx.eval_file("sample.eex", bar: "baz") #=> "foo baz" ``` ### eval\_string(source, bindings \\ [], options \\ []) #### Specs ``` eval_string(String.t(), keyword(), keyword()) :: any() ``` Gets a string `source` and evaluate the values using the `bindings`. #### Examples ``` iex> EEx.eval_string("foo <%= bar %>", bar: "baz") "foo baz" ``` ### function\_from\_file(kind, name, file, args \\ [], options \\ []) Generates a function definition from the file contents. The kind (`:def` or `:defp`) must be given, the function name, its arguments and the compilation options. This function is useful in case you have templates but you want to precompile inside a module for speed. #### Examples ``` # sample.eex <%= a + b %> # sample.ex defmodule Sample do require EEx EEx.function_from_file(:def, :sample, "sample.eex", [:a, :b]) end # iex Sample.sample(1, 2) #=> "3" ``` ### function\_from\_string(kind, name, source, args \\ [], options \\ []) Generates a function definition from the string. The kind (`:def` or `:defp`) must be given, the function name, its arguments and the compilation options. #### Examples ``` iex> defmodule Sample do ...> require EEx ...> EEx.function_from_string(:def, :sample, "<%= a + b %>", [:a, :b]) ...> end iex> Sample.sample(1, 2) "3" ``` elixir Calendar.ISO Calendar.ISO ============= A calendar implementation that follows to ISO 8601. This calendar implements the proleptic Gregorian calendar and is therefore compatible with the calendar used in most countries today. The proleptic means the Gregorian rules for leap years are applied for all time, consequently the dates give different results before the year 1583 from when the Gregorian calendar was adopted. Note that while ISO 8601 allows times and datetimes to specify 24:00:00 as the zero hour of the next day, this notation is not supported by Elixir. Summary ======== Types ------ [day()](#t:day/0) [month()](#t:month/0) [year()](#t:year/0) Functions ---------- [date\_to\_string(year, month, day, format \\ :extended)](#date_to_string/4) Converts the given date into a string. [datetime\_to\_string(year, month, day, hour, minute, second, microsecond, time\_zone, zone\_abbr, utc\_offset, std\_offset, format \\ :extended)](#datetime_to_string/12) Converts the datetime (with time zone) into a string. [day\_of\_era(year, month, day)](#day_of_era/3) Calculates the day and era from the given `year`, `month`, and `day`. [day\_of\_week(year, month, day)](#day_of_week/3) Calculates the day of the week from the given `year`, `month`, and `day`. [day\_of\_year(year, month, day)](#day_of_year/3) Calculates the day of the year from the given `year`, `month`, and `day`. [day\_rollover\_relative\_to\_midnight\_utc()](#day_rollover_relative_to_midnight_utc/0) See [`Calendar.day_rollover_relative_to_midnight_utc/0`](calendar#c:day_rollover_relative_to_midnight_utc/0) for documentation. [days\_in\_month(year, month)](#days_in_month/2) Returns how many days there are in the given year-month. [leap\_year?(year)](#leap_year?/1) Returns if the given year is a leap year. [months\_in\_year(year)](#months_in_year/1) Returns how many months there are in the given year. [naive\_datetime\_from\_iso\_days(arg)](#naive_datetime_from_iso_days/1) Converts the [`Calendar.iso_days/0`](calendar#t:iso_days/0) format to the datetime format specified by this calendar. [naive\_datetime\_to\_iso\_days(year, month, day, hour, minute, second, microsecond)](#naive_datetime_to_iso_days/7) Returns the [`Calendar.iso_days/0`](calendar#t:iso_days/0) format of the specified date. [naive\_datetime\_to\_string(year, month, day, hour, minute, second, microsecond, format \\ :extended)](#naive_datetime_to_string/8) Converts the datetime (without time zone) into a string. [quarter\_of\_year(year, month, day)](#quarter_of_year/3) Calculates the quarter of the year from the given `year`, `month`, and `day`. [time\_from\_day\_fraction(arg)](#time_from_day_fraction/1) Converts a day fraction to this Calendar's representation of time. [time\_to\_day\_fraction(hour, minute, second, arg)](#time_to_day_fraction/4) Returns the normalized day fraction of the specified time. [time\_to\_string(hour, minute, second, microsecond, format \\ :extended)](#time_to_string/5) Converts the given time into a string. [valid\_date?(year, month, day)](#valid_date?/3) Determines if the date given is valid according to the proleptic Gregorian calendar. [valid\_time?(hour, minute, second, arg)](#valid_time?/4) Determines if the date given is valid according to the proleptic Gregorian calendar. [year\_of\_era(year)](#year_of_era/1) Calculates the year and era from the given `year`. Types ====== ### day() #### Specs ``` day() :: 1..31 ``` ### month() #### Specs ``` month() :: 1..12 ``` ### year() #### Specs ``` year() :: -9999..9999 ``` Functions ========== ### date\_to\_string(year, month, day, format \\ :extended) #### Specs ``` date_to_string(year(), month(), day(), :basic | :extended) :: String.t() ``` Converts the given date into a string. By default, returns dates formatted in the "extended" format, for human readability. It also supports the "basic" format by passing the `:basic` option. #### Examples ``` iex> Calendar.ISO.date_to_string(2015, 2, 28) "2015-02-28" iex> Calendar.ISO.date_to_string(2017, 8, 1) "2017-08-01" iex> Calendar.ISO.date_to_string(-99, 1, 31) "-0099-01-31" iex> Calendar.ISO.date_to_string(2015, 2, 28, :basic) "20150228" iex> Calendar.ISO.date_to_string(-99, 1, 31, :basic) "-00990131" ``` ### datetime\_to\_string(year, month, day, hour, minute, second, microsecond, time\_zone, zone\_abbr, utc\_offset, std\_offset, format \\ :extended) #### Specs ``` datetime_to_string( year(), month(), day(), Calendar.hour(), Calendar.minute(), Calendar.second(), Calendar.microsecond(), Calendar.time_zone(), Calendar.zone_abbr(), Calendar.utc_offset(), Calendar.std_offset(), :basic | :extended ) :: String.t() ``` Converts the datetime (with time zone) into a string. By default, returns datetimes formatted in the "extended" format, for human readability. It also supports the "basic" format by passing the `:basic` option. #### Examples ``` iex> time_zone = "Europe/Berlin" iex> Calendar.ISO.datetime_to_string(2017, 8, 1, 1, 2, 3, {4, 5}, time_zone, "CET", 3600, 0) "2017-08-01 01:02:03.00000+01:00 CET Europe/Berlin" iex> Calendar.ISO.datetime_to_string(2017, 8, 1, 1, 2, 3, {4, 5}, time_zone, "CDT", 3600, 3600) "2017-08-01 01:02:03.00000+02:00 CDT Europe/Berlin" iex> time_zone = "America/Los_Angeles" iex> Calendar.ISO.datetime_to_string(2015, 2, 28, 1, 2, 3, {4, 5}, time_zone, "PST", -28800, 0) "2015-02-28 01:02:03.00000-08:00 PST America/Los_Angeles" iex> Calendar.ISO.datetime_to_string(2015, 2, 28, 1, 2, 3, {4, 5}, time_zone, "PDT", -28800, 3600) "2015-02-28 01:02:03.00000-07:00 PDT America/Los_Angeles" iex> time_zone = "Europe/Berlin" iex> Calendar.ISO.datetime_to_string(2017, 8, 1, 1, 2, 3, {4, 5}, time_zone, "CET", 3600, 0, :basic) "20170801 010203.00000+0100 CET Europe/Berlin" ``` ### day\_of\_era(year, month, day) #### Specs ``` day_of_era(year(), month(), day()) :: {day :: pos_integer(), era :: 0..1} ``` Calculates the day and era from the given `year`, `month`, and `day`. #### Examples ``` iex> Calendar.ISO.day_of_era(0, 1, 1) {366, 0} iex> Calendar.ISO.day_of_era(1, 1, 1) {1, 1} iex> Calendar.ISO.day_of_era(0, 12, 31) {1, 0} iex> Calendar.ISO.day_of_era(0, 12, 30) {2, 0} iex> Calendar.ISO.day_of_era(-1, 12, 31) {367, 0} ``` ### day\_of\_week(year, month, day) #### Specs ``` day_of_week(year(), month(), day()) :: 1..7 ``` Calculates the day of the week from the given `year`, `month`, and `day`. It is an integer from 1 to 7, where 1 is Monday and 7 is Sunday. #### Examples ``` iex> Calendar.ISO.day_of_week(2016, 10, 31) 1 iex> Calendar.ISO.day_of_week(2016, 11, 1) 2 iex> Calendar.ISO.day_of_week(2016, 11, 2) 3 iex> Calendar.ISO.day_of_week(2016, 11, 3) 4 iex> Calendar.ISO.day_of_week(2016, 11, 4) 5 iex> Calendar.ISO.day_of_week(2016, 11, 5) 6 iex> Calendar.ISO.day_of_week(2016, 11, 6) 7 iex> Calendar.ISO.day_of_week(-99, 1, 31) 4 ``` ### day\_of\_year(year, month, day) #### Specs ``` day_of_year(year(), month(), day()) :: 1..366 ``` Calculates the day of the year from the given `year`, `month`, and `day`. It is an integer from 1 to 366. #### Examples ``` iex> Calendar.ISO.day_of_year(2016, 1, 31) 31 iex> Calendar.ISO.day_of_year(-99, 2, 1) 32 iex> Calendar.ISO.day_of_year(2018, 2, 28) 59 ``` ### day\_rollover\_relative\_to\_midnight\_utc() #### Specs ``` day_rollover_relative_to_midnight_utc() :: {0, 1} ``` See [`Calendar.day_rollover_relative_to_midnight_utc/0`](calendar#c:day_rollover_relative_to_midnight_utc/0) for documentation. ### days\_in\_month(year, month) #### Specs ``` days_in_month(year(), month()) :: 28..31 ``` Returns how many days there are in the given year-month. #### Examples ``` iex> Calendar.ISO.days_in_month(1900, 1) 31 iex> Calendar.ISO.days_in_month(1900, 2) 28 iex> Calendar.ISO.days_in_month(2000, 2) 29 iex> Calendar.ISO.days_in_month(2001, 2) 28 iex> Calendar.ISO.days_in_month(2004, 2) 29 iex> Calendar.ISO.days_in_month(2004, 4) 30 iex> Calendar.ISO.days_in_month(-1, 5) 31 ``` ### leap\_year?(year) #### Specs ``` leap_year?(year()) :: boolean() ``` Returns if the given year is a leap year. #### Examples ``` iex> Calendar.ISO.leap_year?(2000) true iex> Calendar.ISO.leap_year?(2001) false iex> Calendar.ISO.leap_year?(2004) true iex> Calendar.ISO.leap_year?(1900) false iex> Calendar.ISO.leap_year?(-4) true ``` ### months\_in\_year(year) #### Specs ``` months_in_year(year()) :: 12 ``` Returns how many months there are in the given year. #### Example ``` iex> Calendar.ISO.months_in_year(2004) 12 ``` ### naive\_datetime\_from\_iso\_days(arg) #### Specs ``` naive_datetime_from_iso_days(Calendar.iso_days()) :: {Calendar.year(), Calendar.month(), Calendar.day(), Calendar.hour(), Calendar.minute(), Calendar.second(), Calendar.microsecond()} ``` Converts the [`Calendar.iso_days/0`](calendar#t:iso_days/0) format to the datetime format specified by this calendar. #### Examples ``` iex> Calendar.ISO.naive_datetime_from_iso_days({0, {0, 86400}}) {0, 1, 1, 0, 0, 0, {0, 6}} iex> Calendar.ISO.naive_datetime_from_iso_days({730_485, {0, 86400}}) {2000, 1, 1, 0, 0, 0, {0, 6}} iex> Calendar.ISO.naive_datetime_from_iso_days({730_485, {43200, 86400}}) {2000, 1, 1, 12, 0, 0, {0, 6}} iex> Calendar.ISO.naive_datetime_from_iso_days({-365, {0, 86400000000}}) {-1, 1, 1, 0, 0, 0, {0, 6}} ``` ### naive\_datetime\_to\_iso\_days(year, month, day, hour, minute, second, microsecond) #### Specs ``` naive_datetime_to_iso_days( Calendar.year(), Calendar.month(), Calendar.day(), Calendar.hour(), Calendar.minute(), Calendar.second(), Calendar.microsecond() ) :: Calendar.iso_days() ``` Returns the [`Calendar.iso_days/0`](calendar#t:iso_days/0) format of the specified date. #### Examples ``` iex> Calendar.ISO.naive_datetime_to_iso_days(0, 1, 1, 0, 0, 0, {0, 6}) {0, {0, 86400000000}} iex> Calendar.ISO.naive_datetime_to_iso_days(2000, 1, 1, 12, 0, 0, {0, 6}) {730485, {43200000000, 86400000000}} iex> Calendar.ISO.naive_datetime_to_iso_days(2000, 1, 1, 13, 0, 0, {0, 6}) {730485, {46800000000, 86400000000}} iex> Calendar.ISO.naive_datetime_to_iso_days(-1, 1, 1, 0, 0, 0, {0, 6}) {-365, {0, 86400000000}} ``` ### naive\_datetime\_to\_string(year, month, day, hour, minute, second, microsecond, format \\ :extended) #### Specs ``` naive_datetime_to_string( year(), month(), day(), Calendar.hour(), Calendar.minute(), Calendar.second(), Calendar.microsecond(), :basic | :extended ) :: String.t() ``` Converts the datetime (without time zone) into a string. By default, returns datetimes formatted in the "extended" format, for human readability. It also supports the "basic" format by passing the `:basic` option. #### Examples ``` iex> Calendar.ISO.naive_datetime_to_string(2015, 2, 28, 1, 2, 3, {4, 6}) "2015-02-28 01:02:03.000004" iex> Calendar.ISO.naive_datetime_to_string(2017, 8, 1, 1, 2, 3, {4, 5}) "2017-08-01 01:02:03.00000" iex> Calendar.ISO.naive_datetime_to_string(2015, 2, 28, 1, 2, 3, {4, 6}, :basic) "20150228 010203.000004" ``` ### quarter\_of\_year(year, month, day) #### Specs ``` quarter_of_year(year(), month(), day()) :: 1..4 ``` Calculates the quarter of the year from the given `year`, `month`, and `day`. It is an integer from 1 to 4. #### Examples ``` iex> Calendar.ISO.quarter_of_year(2016, 1, 31) 1 iex> Calendar.ISO.quarter_of_year(2016, 4, 3) 2 iex> Calendar.ISO.quarter_of_year(-99, 9, 31) 3 iex> Calendar.ISO.quarter_of_year(2018, 12, 28) 4 ``` ### time\_from\_day\_fraction(arg) #### Specs ``` time_from_day_fraction(Calendar.day_fraction()) :: {Calendar.hour(), Calendar.minute(), Calendar.second(), Calendar.microsecond()} ``` Converts a day fraction to this Calendar's representation of time. #### Examples ``` iex> Calendar.ISO.time_from_day_fraction({1, 2}) {12, 0, 0, {0, 6}} iex> Calendar.ISO.time_from_day_fraction({13, 24}) {13, 0, 0, {0, 6}} ``` ### time\_to\_day\_fraction(hour, minute, second, arg) #### Specs ``` time_to_day_fraction( Calendar.hour(), Calendar.minute(), Calendar.second(), Calendar.microsecond() ) :: Calendar.day_fraction() ``` Returns the normalized day fraction of the specified time. #### Examples ``` iex> Calendar.ISO.time_to_day_fraction(0, 0, 0, {0, 6}) {0, 86400000000} iex> Calendar.ISO.time_to_day_fraction(12, 34, 56, {123, 6}) {45296000123, 86400000000} ``` ### time\_to\_string(hour, minute, second, microsecond, format \\ :extended) #### Specs ``` time_to_string( Calendar.hour(), Calendar.minute(), Calendar.second(), Calendar.microsecond(), :basic | :extended ) :: String.t() ``` Converts the given time into a string. By default, returns times formatted in the "extended" format, for human readability. It also supports the "basic" format by passing the `:basic` option. #### Examples ``` iex> Calendar.ISO.time_to_string(2, 2, 2, {2, 6}) "02:02:02.000002" iex> Calendar.ISO.time_to_string(2, 2, 2, {2, 2}) "02:02:02.00" iex> Calendar.ISO.time_to_string(2, 2, 2, {2, 0}) "02:02:02" iex> Calendar.ISO.time_to_string(2, 2, 2, {2, 6}, :basic) "020202.000002" iex> Calendar.ISO.time_to_string(2, 2, 2, {2, 6}, :extended) "02:02:02.000002" ``` ### valid\_date?(year, month, day) #### Specs ``` valid_date?(year(), month(), day()) :: boolean() ``` Determines if the date given is valid according to the proleptic Gregorian calendar. #### Examples ``` iex> Calendar.ISO.valid_date?(2015, 2, 28) true iex> Calendar.ISO.valid_date?(2015, 2, 30) false iex> Calendar.ISO.valid_date?(-1, 12, 31) true iex> Calendar.ISO.valid_date?(-1, 12, 32) false ``` ### valid\_time?(hour, minute, second, arg) #### Specs ``` valid_time?( Calendar.hour(), Calendar.minute(), Calendar.second(), Calendar.microsecond() ) :: boolean() ``` Determines if the date given is valid according to the proleptic Gregorian calendar. Note that while ISO 8601 allows times to specify 24:00:00 as the zero hour of the next day, this notation is not supported by Elixir. Leap seconds are not supported as well by the built-in Calendar.ISO. #### Examples ``` iex> Calendar.ISO.valid_time?(10, 50, 25, {3006, 6}) true iex> Calendar.ISO.valid_time?(23, 59, 60, {0, 0}) false iex> Calendar.ISO.valid_time?(24, 0, 0, {0, 0}) false ``` ### year\_of\_era(year) #### Specs ``` year_of_era(year()) :: {year(), era :: 0..1} ``` Calculates the year and era from the given `year`. The ISO calendar has two eras: the current era which starts in year 1 and is defined as era "1". And a second era for those years less than 1 defined as era "0". #### Examples ``` iex> Calendar.ISO.year_of_era(1) {1, 1} iex> Calendar.ISO.year_of_era(2018) {2018, 1} iex> Calendar.ISO.year_of_era(0) {1, 0} iex> Calendar.ISO.year_of_era(-1) {2, 0} ```
programming_docs
elixir Supervisor behaviour Supervisor behaviour ===================== A behaviour module for implementing supervisors. A supervisor is a process which supervises other processes, which we refer to as *child processes*. Supervisors are used to build a hierarchical process structure called a *supervision tree*. Supervision trees provide fault-tolerance and encapsulate how our applications start and shutdown. A supervisor may be started directly with a list of children via [`start_link/2`](#start_link/2) or you may define a module-based supervisor that implements the required callbacks. The sections below use [`start_link/2`](#start_link/2) to start supervisors in most examples, but it also includes a specific section on module-based ones. Examples --------- In order to start a supervisor, we need to first define a child process that will be supervised. As an example, we will define a GenServer that represents a stack: ``` defmodule Stack do use GenServer def start_link(state) do GenServer.start_link(__MODULE__, state, name: __MODULE__) end ## Callbacks @impl true def init(stack) do {:ok, stack} end @impl true def handle_call(:pop, _from, [head | tail]) do {:reply, head, tail} end @impl true def handle_cast({:push, head}, tail) do {:noreply, [head | tail]} end end ``` The stack is a small wrapper around lists. It allows us to put an element on the top of the stack, by prepending to the list, and to get the top of the stack by pattern matching. We can now start a supervisor that will start and supervise our stack process. The first step is to define a list of **child specifications** that control how each child behaves. Each child specification is a map, as shown below: ``` children = [ # The Stack is a child started via Stack.start_link([:hello]) %{ id: Stack, start: {Stack, :start_link, [[:hello]]} } ] # Now we start the supervisor with the children and a strategy {:ok, pid} = Supervisor.start_link(children, strategy: :one_for_one) # After started, we can query the supervisor for information Supervisor.count_children(pid) #=> %{active: 1, specs: 1, supervisors: 0, workers: 1} ``` Notice that when starting the GenServer, we are registering it with name `Stack`, which allows us to call it directly and get what is on the stack: ``` GenServer.call(Stack, :pop) #=> :hello GenServer.cast(Stack, {:push, :world}) #=> :ok GenServer.call(Stack, :pop) #=> :world ``` However, there is a bug in our stack server. If we call `:pop` and the stack is empty, it is going to crash because no clause matches: ``` GenServer.call(Stack, :pop) ** (exit) exited in: GenServer.call(Stack, :pop, 5000) ``` Luckily, since the server is being supervised by a supervisor, the supervisor will automatically start a new one, with the initial stack of `[:hello]`: ``` GenServer.call(Stack, :pop) #=> :hello ``` Supervisors support different strategies; in the example above, we have chosen `:one_for_one`. Furthermore, each supervisor can have many workers and/or supervisors as children, with each one having its own configuration (as outlined in the "Child specification" section). The rest of this document will cover how child processes are specified, how they can be started and stopped, different supervision strategies and more. Child specification -------------------- The child specification describes how the supervisor starts, shuts down, and restarts child processes. The child specification contains 6 keys. The first two are required, and the remaining ones are optional: * `:id` - any term used to identify the child specification internally by the supervisor; defaults to the given module. In the case of conflicting `:id` values, the supervisor will refuse to initialize and require explicit IDs. This key is required. * `:start` - a tuple with the module-function-args to be invoked to start the child process. This key is required. * `:restart` - an atom that defines when a terminated child process should be restarted (see the "Restart values" section below). This key is optional and defaults to `:permanent`. * `:shutdown` - an atom that defines how a child process should be terminated (see the "Shutdown values" section below). This key is optional and defaults to `5000` if the type is `:worker` or `:infinity` if the type is `:supervisor`. * `:type` - specifies that the child process is a `:worker` or a `:supervisor`. This key is optional and defaults to `:worker`. There is a sixth key, `:modules`, that is rarely changed. It is set automatically based on the value in `:start`. Let's understand what the `:shutdown` and `:restart` options control. ### Shutdown values (:shutdown) The following shutdown values are supported in the `:shutdown` option: * `:brutal_kill` - the child process is unconditionally and immediately terminated using `Process.exit(child, :kill)`. * any integer >= 0 - the amount of time in milliseconds that the supervisor will wait for its children to terminate after emitting a `Process.exit(child, :shutdown)` signal. If the child process is not trapping exits, the initial `:shutdown` signal will terminate the child process immediately. If the child process is trapping exits, it has the given amount of time to terminate. If it doesn't terminate within the specified time, the child process is unconditionally terminated by the supervisor via `Process.exit(child, :kill)`. * `:infinity` - works as an integer except the supervisor will wait indefinitely for the child to terminate. If the child process is a supervisor, the recommended value is `:infinity` to give the supervisor and its children enough time to shut down. This option can be used with regular workers but doing so is discouraged and requires extreme care. If not used carefully, the child process will never terminate, preventing your application from terminating as well. ### Restart values (:restart) The `:restart` option controls what the supervisor should consider to be a successful termination or not. If the termination is successful, the supervisor won't restart the child. If the child process crashed, the supervisor will start a new one. The following restart values are supported in the `:restart` option: * `:permanent` - the child process is always restarted. * `:temporary` - the child process is never restarted, regardless of the supervision strategy: any termination (even abnormal) is considered successful. * `:transient` - the child process is restarted only if it terminates abnormally, i.e., with an exit reason other than `:normal`, `:shutdown`, or `{:shutdown, term}`. For a more complete understanding of the exit reasons and their impact, see the "Exit reasons and restarts" section. child\_spec/1 -------------- When starting a supervisor, we pass a list of child specifications. Those specifications are maps that tell how the supervisor should start, stop and restart each of its children: ``` %{ id: Stack, start: {Stack, :start_link, [[:hello]]} } ``` The map above defines a supervisor with `:id` of `Stack` that is started by calling `Stack.start_link([:hello])`. However, specifying the child specification for each child as a map can be quite error prone, as we may change the Stack implementation and forget to update its specification. That's why Elixir allows you to pass a tuple with the module name and the `start_link` argument instead of the specification: ``` children = [ {Stack, [:hello]} ] ``` The supervisor will then invoke `Stack.child_spec([:hello])` to retrieve a child specification. Now the `Stack` module is responsible for building its own specification, for example, we could write: ``` def child_spec(arg) do %{ id: Stack, start: {Stack, :start_link, [arg]} } end ``` Luckily for us, `use GenServer` already defines a `Stack.child_spec/1` exactly like above. If you need to customize the [`GenServer`](genserver), you can pass the options directly to `use GenServer`: ``` use GenServer, restart: :transient ``` Finally, note it is also possible to simply pass the `Stack` module as a child: ``` children = [ Stack ] ``` When only the module name is given, it is equivalent to `{Stack, []}`. By replacing the map specification by `{Stack, [:hello]}` or `Stack`, we keep the child specification encapsulated in the `Stack` module, using the default implementation defined by `use GenServer`. We can now share our `Stack` worker with other developers and they can add it directly to their supervision tree without worrying about the low-level details of the worker. Overall, the child specification can be one of the following: * a map representing the child specification itself - as outlined in the "Child specification" section * a tuple with a module as first element and the start argument as second - such as `{Stack, [:hello]}`. In this case, `Stack.child_spec([:hello])` is called to retrieve the child specification * a module - such as `Stack`. In this case, `Stack.child_spec([])` is called to retrieve the child specification If you need to convert a tuple or a module child specification to a map or modify a child specification, you can use the [`Supervisor.child_spec/2`](supervisor#child_spec/2) function. For example, to run the stack with a different `:id` and a `:shutdown` value of 10 seconds (10\_000 milliseconds): ``` children = [ Supervisor.child_spec({Stack, [:hello]}, id: MyStack, shutdown: 10_000) ] ``` Module-based supervisors ------------------------- In the example above, a supervisor was started by passing the supervision structure to [`start_link/2`](#start_link/2). However, supervisors can also be created by explicitly defining a supervision module: ``` defmodule MyApp.Supervisor do # Automatically defines child_spec/1 use Supervisor def start_link(init_arg) do Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__) end @impl true def init(_init_arg) do children = [ {Stack, [:hello]} ] Supervisor.init(children, strategy: :one_for_one) end end ``` The difference between the two approaches is that a module-based supervisor gives you more direct control over how the supervisor is initialized. Instead of calling [`Supervisor.start_link/2`](supervisor#start_link/2) with a list of children that are automatically initialized, we manually initialized the children by calling [`Supervisor.init/2`](supervisor#init/2) inside its [`init/1`](#c:init/1) callback. `use Supervisor` also defines a `child_spec/1` function which allows us to run `MyApp.Supervisor` as a child of another supervisor or at the top of your supervision tree as: ``` children = [ MyApp.Supervisor ] Supervisor.start_link(children, strategy: :one_for_one) ``` A general guideline is to use the supervisor without a callback module only at the top of your supervision tree, generally in the [`Application.start/2`](application#c:start/2) callback. We recommend using module-based supervisors for any other supervisor in your application, so they can run as a child of another supervisor in the tree. The `child_spec/1` generated automatically by [`Supervisor`](#content) can be customized with the following options: * `:id` - the child specification identifier, defaults to the current module * `:restart` - when the supervisor should be restarted, defaults to `:permanent` The `@doc` annotation immediately preceding `use Supervisor` will be attached to the generated `child_spec/1` function. [`start_link/2`](#start_link/2), [`init/2`](#init/2), and strategies --------------------------------------------------------------------- So far we have started the supervisor passing a single child as a tuple as well as a strategy called `:one_for_one`: ``` children = [ {Stack, [:hello]} ] Supervisor.start_link(children, strategy: :one_for_one) ``` or from inside the [`init/1`](#c:init/1) callback: ``` children = [ {Stack, [:hello]} ] Supervisor.init(children, strategy: :one_for_one) ``` The first argument given to [`start_link/2`](#start_link/2) and [`init/2`](#init/2) is a list of child specifications as defined in the "child\_spec/1" section above. The second argument is a keyword list of options: * `:strategy` - the supervision strategy option. It can be either `:one_for_one`, `:rest_for_one` or `:one_for_all`. Required. See the "Strategies" section. * `:max_restarts` - the maximum number of restarts allowed in a time frame. Defaults to `3`. * `:max_seconds` - the time frame in which `:max_restarts` applies. Defaults to `5`. * `:name` - a name to register the supervisor process. Supported values are explained in the "Name registration" section in the documentation for [`GenServer`](genserver). Optional. ### Strategies Supervisors support different supervision strategies (through the `:strategy` option, as seen above): * `:one_for_one` - if a child process terminates, only that process is restarted. * `:one_for_all` - if a child process terminates, all other child processes are terminated and then all child processes (including the terminated one) are restarted. * `:rest_for_one` - if a child process terminates, the terminated child process and the rest of the children started after it, are terminated and restarted. In the above, process termination refers to unsuccessful termination, which is determined by the `:restart` option. There is also a deprecated strategy called `:simple_one_for_one` which has been replaced by the [`DynamicSupervisor`](dynamicsupervisor). The `:simple_one_for_one` supervisor was similar to `:one_for_one` but suits better when dynamically attaching children. Many functions in this module behaved slightly differently when this strategy was used. See the [`DynamicSupervisor`](dynamicsupervisor) module for more information and migration strategies. ### Name registration A supervisor is bound to the same name registration rules as a [`GenServer`](genserver). Read more about these rules in the documentation for [`GenServer`](genserver). Start and shutdown ------------------- When the supervisor starts, it traverses all child specifications and then starts each child in the order they are defined. This is done by calling the function defined under the `:start` key in the child specification and typically defaults to `start_link/1`. The `start_link/1` (or a custom) is then called for each child process. The `start_link/1` function must return `{:ok, pid}` where `pid` is the process identifier of a new process that is linked to the supervisor. The child process usually starts its work by executing the [`init/1`](#c:init/1) callback. Generally speaking, the `init` callback is where we initialize and configure the child process. The shutdown process happens in reverse order. When a supervisor shuts down, it terminates all children in the opposite order they are listed. The termination happens by sending a shutdown exit signal, via `Process.exit(child_pid, :shutdown)`, to the child process and then awaiting for a time interval for the child process to terminate. This interval defaults to 5000 milliseconds. If the child process does not terminate in this interval, the supervisor abruptly terminates the child with reason `:kill`. The shutdown time can be configured in the child specification which is fully detailed in the next section. If the child process is not trapping exits, it will shutdown immediately when it receives the first exit signal. If the child process is trapping exits, then the `terminate` callback is invoked, and the child process must terminate in a reasonable time interval before being abruptly terminated by the supervisor. In other words, if it is important that a process cleans after itself when your application or the supervision tree is shutting down, then this process must trap exits and its child specification should specify the proper `:shutdown` value, ensuring it terminates within a reasonable interval. Exit reasons and restarts -------------------------- A supervisor restarts a child process depending on its `:restart` configuration. For example, when `:restart` is set to `:transient`, the supervisor does not restart the child in case it exits with reason `:normal`, `:shutdown` or `{:shutdown, term}`. So one may ask: which exit reason should I choose when exiting? There are three options: * `:normal` - in such cases, the exit won't be logged, there is no restart in transient mode, and linked processes do not exit * `:shutdown` or `{:shutdown, term}` - in such cases, the exit won't be logged, there is no restart in transient mode, and linked processes exit with the same reason unless they're trapping exits * any other term - in such cases, the exit will be logged, there are restarts in transient mode, and linked processes exit with the same reason unless they're trapping exits Notice that the supervisor that reaches maximum restart intensity will exit with `:shutdown` reason. In this case the supervisor will only be restarted if its child specification was defined with the `:restart` option set to `:permanent` (the default). Summary ======== Types ------ [child()](#t:child/0) [child\_spec()](#t:child_spec/0) The supervisor specification [init\_option()](#t:init_option/0) Options given to [`start_link/2`](#start_link/2) and [`init/2`](#init/2) [name()](#t:name/0) The Supervisor name [on\_start()](#t:on_start/0) Return values of `start_link` functions [on\_start\_child()](#t:on_start_child/0) Return values of `start_child` functions [option()](#t:option/0) Option values used by the `start*` functions [options()](#t:options/0) Options used by the `start*` functions [strategy()](#t:strategy/0) Supported strategies [supervisor()](#t:supervisor/0) The supervisor reference Functions ---------- [child\_spec(module\_or\_map, overrides)](#child_spec/2) Builds and overrides a child specification. [count\_children(supervisor)](#count_children/1) Returns a map containing count values for the given supervisor. [delete\_child(supervisor, child\_id)](#delete_child/2) Deletes the child specification identified by `child_id`. [init(children, options)](#init/2) Receives a list of `children` to initialize and a set of `options`. [restart\_child(supervisor, child\_id)](#restart_child/2) Restarts a child process identified by `child_id`. [start\_child(supervisor, child\_spec)](#start_child/2) Adds a child specification to `supervisor` and starts that child. [start\_link(children, options)](#start_link/2) Starts a supervisor with the given children. [start\_link(module, init\_arg, options \\ [])](#start_link/3) Starts a module-based supervisor process with the given `module` and `init_arg`. [stop(supervisor, reason \\ :normal, timeout \\ :infinity)](#stop/3) Synchronously stops the given supervisor with the given `reason`. [terminate\_child(supervisor, child\_id)](#terminate_child/2) Terminates the given child identified by `child_id`. [which\_children(supervisor)](#which_children/1) Returns a list with information about all children of the given supervisor. Callbacks ---------- [init(init\_arg)](#c:init/1) Callback invoked to start the supervisor and during hot code upgrades. Types ====== ### child() #### Specs ``` child() :: pid() | :undefined ``` ### child\_spec() #### Specs ``` child_spec() :: %{ :id => atom() | term(), :start => {module(), atom(), [term()]}, optional(:restart) => :permanent | :transient | :temporary, optional(:shutdown) => timeout() | :brutal_kill, optional(:type) => :worker | :supervisor, optional(:modules) => [module()] | :dynamic } ``` The supervisor specification ### init\_option() #### Specs ``` init_option() :: {:strategy, strategy()} | {:max_restarts, non_neg_integer()} | {:max_seconds, pos_integer()} ``` Options given to [`start_link/2`](#start_link/2) and [`init/2`](#init/2) ### name() #### Specs ``` name() :: atom() | {:global, term()} | {:via, module(), term()} ``` The Supervisor name ### on\_start() #### Specs ``` on_start() :: {:ok, pid()} | :ignore | {:error, {:already_started, pid()} | {:shutdown, term()} | term()} ``` Return values of `start_link` functions ### on\_start\_child() #### Specs ``` on_start_child() :: {:ok, child()} | {:ok, child(), info :: term()} | {:error, {:already_started, child()} | :already_present | term()} ``` Return values of `start_child` functions ### option() #### Specs ``` option() :: {:name, name()} | init_option() ``` Option values used by the `start*` functions ### options() #### Specs ``` options() :: [option(), ...] ``` Options used by the `start*` functions ### strategy() #### Specs ``` strategy() :: :one_for_one | :one_for_all | :rest_for_one ``` Supported strategies ### supervisor() #### Specs ``` supervisor() :: pid() | name() | {atom(), node()} ``` The supervisor reference Functions ========== ### child\_spec(module\_or\_map, overrides) #### Specs ``` child_spec(child_spec() | {module(), arg :: term()} | module(), keyword()) :: child_spec() ``` Builds and overrides a child specification. Similar to [`start_link/2`](#start_link/2) and [`init/2`](#init/2), it expects a `module`, `{module, arg}` or a map as the child specification. If a module is given, the specification is retrieved by calling `module.child_spec(arg)`. After the child specification is retrieved, the fields on `overrides` are directly applied on the child spec. If `overrides` has keys that do not map to any child specification field, an error is raised. See the "Child specification" section in the module documentation for all of the available keys for overriding. #### Examples This function is often used to set an `:id` option when the same module needs to be started multiple times in the supervision tree: ``` Supervisor.child_spec({Agent, fn -> :ok end}, id: {Agent, 1}) #=> %{id: {Agent, 1}, #=> start: {Agent, :start_link, [fn -> :ok end]}} ``` ### count\_children(supervisor) #### Specs ``` count_children(supervisor()) :: %{ specs: non_neg_integer(), active: non_neg_integer(), supervisors: non_neg_integer(), workers: non_neg_integer() } ``` Returns a map containing count values for the given supervisor. The map contains the following keys: * `:specs` - the total count of children, dead or alive * `:active` - the count of all actively running child processes managed by this supervisor * `:supervisors` - the count of all supervisors whether or not these child supervisors are still alive * `:workers` - the count of all workers, whether or not these child workers are still alive ### delete\_child(supervisor, child\_id) #### Specs ``` delete_child(supervisor(), term()) :: :ok | {:error, error} when error: :not_found | :simple_one_for_one | :running | :restarting ``` Deletes the child specification identified by `child_id`. The corresponding child process must not be running; use [`terminate_child/2`](#terminate_child/2) to terminate it if it's running. If successful, this function returns `:ok`. This function may return an error with an appropriate error tuple if the `child_id` is not found, or if the current process is running or being restarted. ### init(children, options) #### Specs ``` init([:supervisor.child_spec() | {module(), term()} | module()], [init_option()]) :: {:ok, tuple()} ``` Receives a list of `children` to initialize and a set of `options`. This is typically invoked at the end of the [`init/1`](#c:init/1) callback of module-based supervisors. See the sections "Module-based supervisors" and "start\_link/2, init/2, and strategies" in the module documentation for more information. This function returns a tuple containing the supervisor flags and child specifications. #### Examples ``` def init(_init_arg) do children = [ {Stack, [:hello]} ] Supervisor.init(children, strategy: :one_for_one) end ``` #### Options * `:strategy` - the supervision strategy option. It can be either `:one_for_one`, `:rest_for_one`, `:one_for_all`, or the deprecated `:simple_one_for_one`. * `:max_restarts` - the maximum number of restarts allowed in a time frame. Defaults to `3`. * `:max_seconds` - the time frame in seconds in which `:max_restarts` applies. Defaults to `5`. The `:strategy` option is required and by default a maximum of 3 restarts is allowed within 5 seconds. Check the [`Supervisor`](#content) module for a detailed description of the available strategies. ### restart\_child(supervisor, child\_id) #### Specs ``` restart_child(supervisor(), term()) :: {:ok, child()} | {:ok, child(), term()} | {:error, error} when error: :not_found | :simple_one_for_one | :running | :restarting | term() ``` Restarts a child process identified by `child_id`. The child specification must exist and the corresponding child process must not be running. Note that for temporary children, the child specification is automatically deleted when the child terminates, and thus it is not possible to restart such children. If the child process start function returns `{:ok, child}` or `{:ok, child, info}`, the PID is added to the supervisor and this function returns the same value. If the child process start function returns `:ignore`, the PID remains set to `:undefined` and this function returns `{:ok, :undefined}`. This function may return an error with an appropriate error tuple if the `child_id` is not found, or if the current process is running or being restarted. If the child process start function returns an error tuple or an erroneous value, or if it fails, this function returns `{:error, error}`. ### start\_child(supervisor, child\_spec) #### Specs ``` start_child( supervisor(), :supervisor.child_spec() | {module(), term()} | module() | [term()] ) :: on_start_child() ``` Adds a child specification to `supervisor` and starts that child. `child_spec` should be a valid child specification. The child process will be started as defined in the child specification. If a child specification with the specified ID already exists, `child_spec` is discarded and this function returns an error with `:already_started` or `:already_present` if the corresponding child process is running or not, respectively. If the child process start function returns `{:ok, child}` or `{:ok, child, info}`, then child specification and PID are added to the supervisor and this function returns the same value. If the child process start function returns `:ignore`, the child specification is added to the supervisor, the PID is set to `:undefined` and this function returns `{:ok, :undefined}`. If the child process start function returns an error tuple or an erroneous value, or if it fails, the child specification is discarded and this function returns `{:error, error}` where `error` is a term containing information about the error and child specification. ### start\_link(children, options) #### Specs ``` start_link( [:supervisor.child_spec() | {module(), term()} | module()], options() ) :: {:ok, pid()} | {:error, {:already_started, pid()} | {:shutdown, term()} | term()} ``` ``` start_link(module(), term()) :: on_start() ``` Starts a supervisor with the given children. The children is a list of modules, two-element tuples with module and arguments or a map with the child specification. A strategy is required to be provided through the `:strategy` option. See "start\_link/2, init/2, and strategies" for examples and other options. The options can also be used to register a supervisor name. The supported values are described under the "Name registration" section in the [`GenServer`](genserver) module docs. If the supervisor and its child processes are successfully spawned (if the start function of each child process returns `{:ok, child}`, `{:ok, child, info}`, or `:ignore`) this function returns `{:ok, pid}`, where `pid` is the PID of the supervisor. If the supervisor is given a name and a process with the specified name already exists, the function returns `{:error, {:already_started, pid}}`, where `pid` is the PID of that process. If the start function of any of the child processes fails or returns an error tuple or an erroneous value, the supervisor first terminates with reason `:shutdown` all the child processes that have already been started, and then terminates itself and returns `{:error, {:shutdown, reason}}`. Note that a supervisor started with this function is linked to the parent process and exits not only on crashes but also if the parent process exits with `:normal` reason. ### start\_link(module, init\_arg, options \\ []) #### Specs ``` start_link(module(), term(), GenServer.options()) :: on_start() ``` Starts a module-based supervisor process with the given `module` and `init_arg`. To start the supervisor, the [`init/1`](#c:init/1) callback will be invoked in the given `module`, with `init_arg` as its argument. The [`init/1`](#c:init/1) callback must return a supervisor specification which can be created with the help of the [`init/2`](#init/2) function. If the [`init/1`](#c:init/1) callback returns `:ignore`, this function returns `:ignore` as well and the supervisor terminates with reason `:normal`. If it fails or returns an incorrect value, this function returns `{:error, term}` where `term` is a term with information about the error, and the supervisor terminates with reason `term`. The `:name` option can also be given in order to register a supervisor name, the supported values are described in the "Name registration" section in the [`GenServer`](genserver) module docs. ### stop(supervisor, reason \\ :normal, timeout \\ :infinity) #### Specs ``` stop(supervisor(), reason :: term(), timeout()) :: :ok ``` Synchronously stops the given supervisor with the given `reason`. It returns `:ok` if the supervisor terminates with the given reason. If it terminates with another reason, the call exits. This function keeps OTP semantics regarding error reporting. If the reason is any other than `:normal`, `:shutdown` or `{:shutdown, _}`, an error report is logged. ### terminate\_child(supervisor, child\_id) #### Specs ``` terminate_child(supervisor(), term()) :: :ok | {:error, error} when error: :not_found | :simple_one_for_one ``` Terminates the given child identified by `child_id`. The process is terminated, if there's one. The child specification is kept unless the child is temporary. A non-temporary child process may later be restarted by the supervisor. The child process can also be restarted explicitly by calling [`restart_child/2`](#restart_child/2). Use [`delete_child/2`](#delete_child/2) to remove the child specification. If successful, this function returns `:ok`. If there is no child specification for the given child ID, this function returns `{:error, :not_found}`. ### which\_children(supervisor) #### Specs ``` which_children(supervisor()) :: [ {term() | :undefined, child() | :restarting, :worker | :supervisor, :supervisor.modules()} ] ``` Returns a list with information about all children of the given supervisor. Note that calling this function when supervising a large number of children under low memory conditions can cause an out of memory exception. This function returns a list of `{id, child, type, modules}` tuples, where: * `id` - as defined in the child specification * `child` - the PID of the corresponding child process, `:restarting` if the process is about to be restarted, or `:undefined` if there is no such process * `type` - `:worker` or `:supervisor`, as specified by the child specification * `modules` - as specified by the child specification Callbacks ========== ### init(init\_arg) #### Specs ``` init(init_arg :: term()) :: {:ok, {:supervisor.sup_flags(), [:supervisor.child_spec()]}} | :ignore ``` Callback invoked to start the supervisor and during hot code upgrades. Developers typically invoke [`Supervisor.init/2`](supervisor#init/2) at the end of their init callback to return the proper supervision flags.
programming_docs
elixir Record Record ======= Module to work with, define, and import records. Records are simply tuples where the first element is an atom: ``` iex> Record.is_record({User, "john", 27}) true ``` This module provides conveniences for working with records at compilation time, where compile-time field names are used to manipulate the tuples, providing fast operations on top of the tuples' compact structure. In Elixir, records are used mostly in two situations: 1. to work with short, internal data 2. to interface with Erlang records The macros [`defrecord/3`](#defrecord/3) and [`defrecordp/3`](#defrecordp/3) can be used to create records while [`extract/2`](#extract/2) and [`extract_all/1`](#extract_all/1) can be used to extract records from Erlang files. Types ------ Types can be defined for tuples with the `record/2` macro (only available in typespecs). This macro will expand to a tuple as seen in the example below: ``` defmodule MyModule do require Record Record.defrecord(:user, name: "john", age: 25) @type user :: record(:user, name: String.t(), age: integer) # expands to: "@type user :: {:user, String.t(), integer}" end ``` Summary ======== Guards ------- [is\_record(data)](#is_record/1) Checks if the given `data` is a record. [is\_record(data, kind)](#is_record/2) Checks if the given `data` is a record of kind `kind`. Functions ---------- [defrecord(name, tag \\ nil, kv)](#defrecord/3) Defines a set of macros to create, access, and pattern match on a record. [defrecordp(name, tag \\ nil, kv)](#defrecordp/3) Same as [`defrecord/3`](#defrecord/3) but generates private macros. [extract(name, opts)](#extract/2) Extracts record information from an Erlang file. [extract\_all(opts)](#extract_all/1) Extracts all records information from an Erlang file. Guards ======= ### is\_record(data) Checks if the given `data` is a record. This is implemented as a macro so it can be used in guard clauses. #### Examples ``` iex> record = {User, "john", 27} iex> Record.is_record(record) true iex> tuple = {} iex> Record.is_record(tuple) false ``` ### is\_record(data, kind) Checks if the given `data` is a record of kind `kind`. This is implemented as a macro so it can be used in guard clauses. #### Examples ``` iex> record = {User, "john", 27} iex> Record.is_record(record, User) true ``` Functions ========== ### defrecord(name, tag \\ nil, kv) Defines a set of macros to create, access, and pattern match on a record. The name of the generated macros will be `name` (which has to be an atom). `tag` is also an atom and is used as the "tag" for the record (i.e., the first element of the record tuple); by default (if `nil`), it's the same as `name`. `kv` is a keyword list of `name: default_value` fields for the new record. The following macros are generated: * `name/0` to create a new record with default values for all fields * `name/1` to create a new record with the given fields and values, to get the zero-based index of the given field in a record or to convert the given record to a keyword list * `name/2` to update an existing record with the given fields and values or to access a given field in a given record All these macros are public macros (as defined by `defmacro`). See the "Examples" section for examples on how to use these macros. #### Examples ``` defmodule User do require Record Record.defrecord(:user, name: "meg", age: "25") end ``` In the example above, a set of macros named `user` but with different arities will be defined to manipulate the underlying record. ``` # Import the module to make the user macros locally available import User # To create records record = user() #=> {:user, "meg", 25} record = user(age: 26) #=> {:user, "meg", 26} # To get a field from the record user(record, :name) #=> "meg" # To update the record user(record, age: 26) #=> {:user, "meg", 26} # To get the zero-based index of the field in record tuple # (index 0 is occupied by the record "tag") user(:name) #=> 1 # Convert a record to a keyword list user(record) #=> [name: "meg", age: 26] ``` The generated macros can also be used in order to pattern match on records and to bind variables during the match: ``` record = user() #=> {:user, "meg", 25} user(name: name) = record name #=> "meg" ``` By default, Elixir uses the record name as the first element of the tuple (the "tag"). However, a different tag can be specified when defining a record, as in the following example, in which we use `Customer` as the second argument of [`defrecord/3`](#defrecord/3): ``` defmodule User do require Record Record.defrecord(:user, Customer, name: nil) end require User User.user() #=> {Customer, nil} ``` #### Defining extracted records with anonymous functions in the values If a record defines an anonymous function in the default values, an [`ArgumentError`](argumenterror) will be raised. This can happen unintentionally when defining a record after extracting it from an Erlang library that uses anonymous functions for defaults. ``` Record.defrecord(:my_rec, Record.extract(...)) #=> ** (ArgumentError) invalid value for record field fun_field, #=> cannot escape #Function<12.90072148/2 in :erl_eval.expr/5>. ``` To work around this error, redefine the field with your own &M.f/a function, like so: ``` defmodule MyRec do require Record Record.defrecord(:my_rec, Record.extract(...) |> Keyword.merge(fun_field: &__MODULE__.foo/2)) def foo(bar, baz), do: IO.inspect({bar, baz}) end ``` ### defrecordp(name, tag \\ nil, kv) Same as [`defrecord/3`](#defrecord/3) but generates private macros. ### extract(name, opts) #### Specs ``` extract(name :: atom(), keyword()) :: keyword() ``` Extracts record information from an Erlang file. Returns a quoted expression containing the fields as a list of tuples. `name`, which is the name of the extracted record, is expected to be an atom *at compile time*. #### Options This function accepts the following options, which are exclusive to each other (i.e., only one of them can be used in the same call): * `:from` - (binary representing a path to a file) path to the Erlang file that contains the record definition to extract; with this option, this function uses the same path lookup used by the `-include` attribute used in Erlang modules. * `:from_lib` - (binary representing a path to a file) path to the Erlang file that contains the record definition to extract; with this option, this function uses the same path lookup used by the `-include_lib` attribute used in Erlang modules. * `:includes` - (a list of directories as binaries) if the record being extracted depends on relative includes, this option allows developers to specify the directory where those relative includes exist. * `:macros` - (keyword list of macro names and values) if the record being extracted depends on the values of macros, this option allows the value of those macros to be set. These options are expected to be literals (including the binary values) at compile time. #### Examples ``` iex> Record.extract(:file_info, from_lib: "kernel/include/file.hrl") [ size: :undefined, type: :undefined, access: :undefined, atime: :undefined, mtime: :undefined, ctime: :undefined, mode: :undefined, links: :undefined, major_device: :undefined, minor_device: :undefined, inode: :undefined, uid: :undefined, gid: :undefined ] ``` ### extract\_all(opts) #### Specs ``` extract_all(keyword()) :: [{name :: atom(), keyword()}] ``` Extracts all records information from an Erlang file. Returns a keyword list of `{record_name, fields}` tuples where `record_name` is the name of an extracted record and `fields` is a list of `{field, value}` tuples representing the fields for that record. #### Options This function accepts the following options, which are exclusive to each other (i.e., only one of them can be used in the same call): * `:from` - (binary representing a path to a file) path to the Erlang file that contains the record definitions to extract; with this option, this function uses the same path lookup used by the `-include` attribute used in Erlang modules. * `:from_lib` - (binary representing a path to a file) path to the Erlang file that contains the record definitions to extract; with this option, this function uses the same path lookup used by the `-include_lib` attribute used in Erlang modules. These options are expected to be literals (including the binary values) at compile time. elixir Guards Guards ====== Guards are a way to augment pattern matching with more complex checks. They are allowed in a predefined set of constructs where pattern matching is allowed. Not all expressions are allowed in guard clauses, but only a handful of them. This is a deliberate choice. This way, Elixir (and Erlang) can make sure that nothing bad happens while executing guards and no mutations happen anywhere. It also allows the compiler to optimize the code related to guards efficiently. List of allowed expressions ---------------------------- You can find the built-in list of guards [in the `Kernel` module](kernel#guards). Here is an overview: * comparison operators ([`==`](kernel#==/2), [`!=`](kernel#!=/2), [`===`](kernel#===/2), [`!==`](kernel#!==/2), [`>`](kernel#%3E/2), [`>=`](kernel#%3E=/2), [`<`](kernel#%3C/2), [`<=`](kernel#%3C=/2)) * strictly boolean operators ([`and`](kernel#and/2), [`or`](kernel#or/2), [`not`](kernel#not/1)). Note [`&&`](kernel#&&/2), [`||`](kernel#%7C%7C/2), and [`!`](kernel#!/1) sibling operators are **not allowed** as they're not *strictly* boolean - meaning they don't require arguments to be booleans * arithmetic unary and binary operators ([`+`](kernel#+/1), [`-`](kernel#-/1), [`+`](kernel#+/2), [`-`](kernel#-/2), [`*`](kernel#*/2), [`/`](kernel#//2)) * [`in`](kernel#in/2) and [`not in`](kernel#in/2) operators (as long as the right-hand side is a list or a range) * "type-check" functions ([`is_list/1`](kernel#is_list/1), [`is_number/1`](kernel#is_number/1), etc.) * functions that work on built-in datatypes ([`abs/1`](kernel#abs/1), [`map_size/1`](kernel#map_size/1), etc.) The module [`Bitwise`](bitwise) also includes a handful of [Erlang bitwise operations as guards](bitwise#guards). Macros constructed out of any combination of the above guards are also valid guards - for example, [`Integer.is_even/1`](integer#is_even/1). For more information, see the "Defining custom guard expressions" section shown below. Why guards ----------- Let's see an example of a guard used in a function clause: ``` def empty_map?(map) when map_size(map) == 0, do: true def empty_map?(map) when is_map(map), do: false ``` Guards start with the `when` keyword, which is followed by a boolean expression (we will define the grammar of guards more formally later on). Writing the `empty_map?/1` function by only using pattern matching would not be possible (as pattern matching on `%{}` would match *every* map, not empty maps). Where guards can be used ------------------------- In the example above, we show how guards can be used in function clauses. There are several constructs that allow guards; for example: * function clauses: ``` def foo(term) when is_integer(term), do: term def foo(term) when is_float(term), do: round(term) ``` * [`case`](kernel.specialforms#case/2) expressions: ``` case x do 1 -> :one 2 -> :two n when is_integer(n) and n > 2 -> :larger_than_two end ``` * anonymous functions ([`fn`](kernel.specialforms#fn/1)s): ``` larger_than_two? = fn n when is_integer(n) and n > 2 -> true n when is_integer(n) -> false end ``` * custom guards can also be defined with [`defguard/1`](kernel#defguard/1) and [`defguardp/1`](kernel#defguardp/1). A custom guard is always defined based on existing guards. Other constructs are [`for`](kernel.specialforms#for/1), [`with`](kernel.specialforms#with/1), [`try/rescue/catch/else`](kernel.specialforms#try/1), and the [`match?/2`](kernel#match?/2). Failing guards --------------- In guards, when functions would normally raise exceptions, they cause the guard to fail instead. For example, the [`length/1`](kernel#length/1) function only works with lists. If we use it with anything else, a runtime error is raised: ``` iex> length("hello") ** (ArgumentError) argument error ``` However, when used in guards, the corresponding clause simply fails to match: ``` iex> case "hello" do ...> something when length(something) > 0 -> ...> :length_worked ...> _anything_else -> ...> :length_failed ...> end :length_failed ``` In many cases, we can take advantage of this. In the code above, we used [`length/1`](kernel#length/1) to both check that the given thing is a list *and* check some properties of its length (instead of using `is_list(something) and length(something) > 0`). Defining custom guard expressions ---------------------------------- As mentioned before, only the expressions listed in this page are allowed in guards. However, we can take advantage of macros to write custom guards that can simplify our programs or make them more domain-specific. At the end of the day, what matters is that the *output* of the macros (which is what will be compiled) boils down to a combinations of the allowed expressions. Let's look at a quick case study: we want to check that a function argument is an even or odd integer. With pattern matching, this is impossible to do since there are infinite integers, and thus we can't pattern match on the single even/odd numbers. Let's focus on checking for even numbers since checking for odd ones is almost identical. Such a guard would look like this: ``` def my_function(number) when is_integer(number) and rem(number, 2) == 0 do # do stuff end ``` This would be repetitive to write every time we need this check, so, as mentioned at the beginning of this section, we can abstract this away using a macro. Remember that defining a function that performs this check wouldn't work because we can't use custom functions in guards. Use `defguard` and `defguardp` to create guard macros. Here's an example: ``` defmodule MyInteger do defguard is_even(value) when is_integer(value) and rem(value, 2) == 0 end ``` and then: ``` import MyInteger, only: [is_even: 1] def my_function(number) when is_even(number) do # do stuff end ``` While it's possible to create custom guards with macros, it's recommended to define them using `defguard` and `defguardp` which perform additional compile-time checks. Multiple guards in the same clause ----------------------------------- There exists an additional way to simplify a chain of `or`s in guards: Elixir supports writing "multiple guards" in the same clause. This: ``` def foo(term) when is_integer(term) or is_float(term) or is_nil(term), do: :maybe_number def foo(_other), do: :something_else ``` can be alternatively written as: ``` def foo(term) when is_integer(term) when is_float(term) when is_nil(term) do :maybe_number end def foo(_other) do :something_else end ``` If each guard expression always returns a boolean, the two forms are equivalent. However, recall that if any function call in a guard raises an exception, the entire guard fails. So this function will not detect empty tuples: ``` defmodule Check do # If given a tuple, map_size/1 will raise, and tuple_size/1 will not be evaluated def empty?(val) when map_size(val) == 0 or tuple_size(val) == 0, do: true def empty?(_val), do: false end Check.empty?(%{}) #=> true Check.empty?({}) #=> false # true was expected! ``` This could be corrected by ensuring that no exception is raised, either via type checks like `is_map(val) and map_size(val) == 0`, or by checking equality instead, like `val == %{}`. It could also be corrected by using multiple guards, so that if an exception causes one guard to fail, the next one is evaluated. ``` defmodule Check do # If given a tuple, map_size/1 will raise, and the second guard will be evaluated def empty?(val) when map_size(val) == 0 when tuple_size(val) == 0, do: true def empty?(_val), do: false end Check.empty?(%{}) #=> true Check.empty?({}) #=> true ``` elixir Syntax reference Syntax reference ================ Elixir syntax was designed to have a straightforward conversion to an abstract syntax tree (AST). This means the Elixir syntax is mostly uniform with a handful of "syntax sugar" constructs to reduce the noise in common Elixir idioms. This document covers all of Elixir syntax constructs as a reference and then discuss their exact AST representation. Reserved words --------------- These are the reserved words in the Elixir language. They are detailed throughout this guide but summed up here for convenience: * `true`, `false`, `nil` - used as atoms * `when`, `and`, `or`, `not`, `in` - used as operators * `fn` - used for anonymous function definitions * `do`, `end`, `catch`, `rescue`, `after`, `else` - used in do/end blocks Data types ----------- ### Numbers Integers (`1234`) and floats (`123.4`) in Elixir are represented as a sequence of digits that may be separated by underscore for readability purposes, such as `1_000_000`. Integers never contain a dot (`.`) in their representation. Floats contain a dot and at least one other digit after the dot. Floats also support the scientific notation, such as `123.4e10` or `123.4E10`. ### Atoms Unquoted atoms start with a colon (`:`) which must be immediately followed by an underscore or a Unicode letter. The atom may continue using a sequence of Unicode letters, numbers, underscores, and `@`. Atoms may end in `!` or `?`. See [Unicode Syntax](unicode-syntax) for a formal specification. Valid unquoted atoms are: `:ok`, `:ISO8601`, and `:integer?`. If the colon is immediately followed by a pair of double- or single-quotes surrounding the atom name, the atom is considered quoted. In contrast with an unquoted atom, this one can be made of any Unicode character (not only letters), such as `:'🌢 Elixir'`, `:"++olá++"`, and `:"123"`. Quoted and unquoted atoms with the same name are considered equivalent, so `:atom`, `:"atom"`, and `:'atom'` represent the same atom. The only catch is that the compiler will warn when quotes are used in atoms that do not need to be quoted. All operators in Elixir are also valid atoms. Valid examples are `:foo`, `:FOO`, `:foo_42`, `:foo@bar`, and `:++`. Invalid examples are `:@foo` (`@` is not allowed at start), `:123` (numbers are not allowed at start), and `:(*)` (not a valid operator). `true`, `false`, and `nil` are reserved words that are represented by the atoms `:true`, `:false` and `:nil` respectively. ### Strings Single-line strings in Elixir are written between double-quotes, such as `"foo"`. Any double-quote inside the string must be escaped with `\`. Strings support Unicode characters and are stored as UTF-8 encoded binaries. Multi-line strings in Elixir are written with three double-quotes, and can have unescaped quotes within them. The resulting string will end with a newline. The indentation of the last `"""` is used to strip indentation from the inner string. For example: ``` iex> test = """ ...> this ...> is ...> a ...> test ...> """ " this\n is\n a\n test\n" iex> test = """ ...> This ...> Is ...> A ...> Test ...> """ "This\nIs\nA\nTest\n" ``` Strings are always represented as themselves in the AST. ### Charlists Charlists in Elixir are written in single-quotes, such as `'foo'`. Any single-quote inside the string must be escaped with `\`. Charlists are made of non-negative integers, where each integer represents a Unicode code point. Multi-line charlists are written with three single-quotes (`'''`), the same way multi-line strings are. Charlists are always represented as themselves in the AST. For more in-depth information, please read the "Charlists" section in the [`List`](list) module. ### Lists, tuples and binaries Data structures such as lists, tuples, and binaries are marked respectively by the delimiters `[...]`, `{...}`, and `<<...>>`. Each element is separated by comma. A trailing comma is also allowed, such as in `[1, 2, 3,]`. ### Maps and keyword lists Maps use the `%{...}` notation and each key-value is given by pairs marked with `=>`, such as `%{"hello" => 1, 2 => "world"}`. Both keyword lists (list of two-element tuples where the first element is atom) and maps with atom keys support a keyword notation where the colon character `:` is moved to the end of the atom. `%{hello: "world"}` is equivalent to `%{:hello => "world"}` and `[foo: :bar]` is equivalent to `[{:foo, :bar}]`. This notation is a syntax sugar that emits the same AST representation. It will be explained in later sections. ### Structs Structs built on the map syntax by passing the struct name between `%` and `{`. For example, `%User{...}`. Expressions ------------ ### Variables Variables in Elixir must start with an underscore or a Unicode letter that is not in uppercase or titlecase. The variable may continue using a sequence of Unicode letters, numbers, and underscores. Variables may end in `?` or `!`. See [Unicode Syntax](unicode-syntax) for a formal specification. [Elixir's naming conventions](naming-conventions) recommend variables to be in `snake_case` format. ### Non-qualified calls (local calls) Non-qualified calls, such as `add(1, 2)`, must start with an underscore or a Unicode letter that is not in uppercase or titlecase. The call may continue using a sequence of Unicode letters, numbers, and underscore. Calls may end in `?` or `!`. See [Unicode Syntax](unicode-syntax) for a formal specification. Parentheses for non-qualified calls are optional, except for zero-arity calls, which would then be ambiguous with variables. If parentheses are used, they must immediately follow the function name *without spaces*. For example, `add (1, 2)` is a syntax error, since `(1, 2)` is treated as an invalid block which is attempted to be given as a single argument to `add`. [Elixir's naming conventions](naming-conventions) recommend calls to be in `snake_case` format. ### Operators As many programming languages, Elixir also support operators as non-qualified calls with their precedence and associativity rules. Constructs such as `=`, `when`, `&` and `@` are simply treated as operators. See [the Operators page](operators) for a full reference. ### Qualified calls (remote calls) Qualified calls, such as `Math.add(1, 2)`, must start with an underscore or a Unicode letter that is not in uppercase or titlecase. The call may continue using a sequence of Unicode letters, numbers, and underscores. Calls may end in `?` or `!`. See [Unicode Syntax](unicode-syntax) for a formal specification. [Elixir's naming conventions](naming-conventions) recommend calls to be in `snake_case` format. For qualified calls, Elixir also allows the function name to be written between double- or single-quotes, allowing calls such as `Math."++add++"(1, 2)`. Operators can be used as qualified calls without a need for quote, such as `Kernel.+(1, 2)`. Parentheses for qualified calls are optional. If parentheses are used, they must immediately follow the function name *without spaces*. ### Aliases Aliases are constructs that expand to atoms at compile-time. The alias [`String`](string) expands to the atom `:"Elixir.String"`. Aliases must start with an ASCII uppercase character which may be followed by any ASCII letter, number, or underscore. Non-ASCII characters are not supported in aliases. [Elixir's naming conventions](naming-conventions) recommend aliases to be in `CamelCase` format. ### Blocks Blocks are multiple Elixir expressions separated by newlines or semi-colons. A new block may be created at any moment by using parentheses. ### Left to right arrow The left to right arrow (`->`) is used to establish a relationship between left and right, commonly referred as clauses. The left side may have zero, one, or more arguments; the right side is zero, one, or more expressions separated by new line. The `->` may appear one or more times between one of the following terminators: `do`/`end`, `fn`/`end` or `(`/`)`. When `->` is used, only other clauses are allowed between those terminators. Mixing clauses and regular expressions is invalid syntax. It is seen on `case` and `cond` constructs between `do`/`end`: ``` case 1 do 2 -> 3 4 -> 5 end cond do true -> false end ``` Seen in typespecs between `(`/`)`: ``` (integer(), boolean() -> integer()) ``` It is also used between `fn/end` for building anonymous functions: ``` fn x, y -> x + y end ``` ### Sigils Sigils start with `~` and are followed by a letter and one of the following pairs: * `(` and `)` * `{` and `}` * `[` and `]` * `<` and `>` * `"` and `"` * `'` and `'` * `|` and `|` * `/` and `/` After closing the pair, zero or more ASCII letters can be given as a modifier. Sigils are expressed as non-qualified calls prefixed with `sigil_` where the first argument is the sigil contents as a string and the second argument is a list of integers as modifiers: If the sigil letter is in uppercase, no interpolation is allowed in the sigil, otherwise its contents may be dynamic. Compare the results of the sigils below for more information: ``` ~s/f#{"o"}o/ ~S/f#{"o"}o/ ``` Sigils are useful to encode text with their own escaping rules, such as regular expressions, datetimes, etc. The Elixir AST --------------- Elixir syntax was designed to have a straightforward conversion to an abstract syntax tree (AST). Elixir's AST is a regular Elixir data structure composed of the following elements: * atoms - such as `:foo` * integers - such as `42` * floats - such as `13.1` * strings - such as `"hello"` * lists - such as `[1, 2, 3]` * tuples with two elements - such as `{"hello", :world}` * tuples with three elements, representing calls or variables, as explained next The building block of Elixir's AST is a call, such as: ``` sum(1, 2, 3) ``` which is represented as a tuple with three elements: ``` {:sum, meta, [1, 2, 3]} ``` the first element is an atom (or another tuple), the second element is a list of two-element tuples with metadata (such as line numbers) and the third is a list of arguments. We can retrieve the AST for any Elixir expression by calling `quote`: ``` quote do sum() end #=> {:sum, [], []} ``` Variables are also represented using a tuple with three elements and a combination of lists and atoms, for example: ``` quote do sum end #=> {:sum, [], Elixir} ``` You can see that variables are also represented with a tuple, except the third element is an atom expressing the variable context. Over the next section, we will explore many of Elixir syntax constructs alongside their AST representation. ### Operators Operators are treated as non-qualified calls: ``` quote do 1 + 2 end #=> {:+, [], [1, 2]} ``` Notice that `.` is also an operator. Remote calls use the dot in the AST with two arguments, where the second argument is always an atom: ``` quote do foo.bar(1, 2, 3) end #=> {{:., [], [{:foo, [], Elixir}, :bar]}, [], [1, 2, 3]} ``` Calling anonymous functions uses the dot in the AST with a single argument, mirroring the fact the function name is "missing" from right side of the dot: ``` quote do foo.(1, 2, 3) end #=> {{:., [], [{:foo, [], Elixir}]}, [], [1, 2, 3]} ``` ### Aliases Aliases are represented by an `__aliases__` call with each segment separated by dot as an argument: ``` quote do Foo.Bar.Baz end #=> {:__aliases__, [], [:Foo, :Bar, :Baz]} quote do __MODULE__.Bar.Baz end #=> {:__aliases__, [], [{:__MODULE__, [], Elixir}, :Bar, :Baz]} ``` All arguments, except the first, are guaranteed to be atoms. ### Data structures Remember lists are literals, so they are represented as themselves in the AST: ``` quote do [1, 2, 3] end #=> [1, 2, 3] ``` Tuples have their own representation, except for two-element tuples, which are represented as themselves: ``` quote do {1, 2} end #=> {1, 2} quote do {1, 2, 3} end #=> {:{}, [], [1, 2, 3]} ``` Binaries have a representation similar to tuples, except they are tagged with `:<<>>` instead of `:{}`: ``` quote do <<1, 2, 3>> end #=> {:<<>>, [], [1, 2, 3]} ``` The same applies to maps where each pair is treated as a list of tuples with two elements: ``` quote do %{1 => 2, 3 => 4} end #=> {:%{}, [], [{1, 2}, {3, 4}]} ``` ### Blocks Blocks are represented as a `__block__` call with each line as a separate argument: ``` quote do 1 2 3 end #=> {:__block__, [], [1, 2, 3]} quote do 1; 2; 3; end #=> {:__block__, [], [1, 2, 3]} ``` ### Left to right arrow The left to right arrow (`->`) is represented similar to operators except that they are always part of a list, its left side represents a list of arguments and the right side is an expression. For example, in `case` and `cond`: ``` quote do case 1 do 2 -> 3 4 -> 5 end end #=> {:case, [], [1, [do: [{:->, [], [[2], 3]}, {:->, [], [[4], 5]}]]]} quote do cond do true -> false end end #=> {:cond, [], [[do: [{:->, [], [[true], false]}]]]} ``` Between `(`/`)`: ``` quote do (1, 2 -> 3 4, 5 -> 6) end #=> [{:->, [], [[1, 2], 3]}, {:->, [], [[4, 5], 6]}] ``` Between `fn/end`: ``` quote do fn 1, 2 -> 3 4, 5 -> 6 end end #=> {:fn, [], [{:->, [], [[1, 2], 3]}, {:->, [], [[4, 5], 6]}]} ``` Syntactic sugar ---------------- All of the constructs above are part of Elixir's syntax and have their own representation as part of the Elixir AST. This section will discuss the remaining constructs that "desugar" to one of the constructs explored above. In other words, the constructs below can be represented in more than one way in your Elixir code and retain AST equivalence. ### Integers in other bases and Unicode code points Elixir allows integers to contain `_` to separate digits and provides conveniences to represent integers in other bases: ``` 1_000_000 #=> 1000000 0xABCD #=> 43981 (Hexadecimal base) 0o01234567 #=> 342391 (Octal base) 0b10101010 #=> 170 (Binary base) ?é #=> 233 (Unicode code point) ``` Those constructs exist only at the syntax level. All of the examples above are represented as their underlying integers in the AST. ### Access syntax The access syntax is represented as a call to [`Access.get/2`](access#get/2): ``` quote do opts[arg] end #=> {{:., [], [Access, :get]}, [], [{:opts, [], Elixir}, {:arg, [], Elixir}]} ``` ### Optional parentheses Elixir provides optional parentheses for non-qualified and qualified calls. ``` quote do sum 1, 2, 3 end #=> {:sum, [], [1, 2, 3]} ``` The above is treated the same as `sum(1, 2, 3)` by the parser. The same applies to qualified calls such as `Foo.bar(1, 2, 3)`, which is the same as `Foo.bar 1, 2, 3`. However, remember parentheses are not optional for non-qualified calls with no arguments, such as `sum()`. Removing the parentheses for `sum` causes it to be represented as the variable `sum`, which means they would be no longer equivalent. ### Keywords Keywords in Elixir are a list of tuples of two elements where the first element is an atom. Using the base constructs, they would be represented as: ``` [{:foo, 1}, {:bar, 2}] ``` However Elixir introduces a syntax sugar where the keywords above may be written as follows: ``` [foo: 1, bar: 2] ``` Atoms with foreign characters, such as whitespace, must be wrapped in quotes. This rule applies to keywords as well: ``` [{:"foo bar", 1}, {:"bar baz", 2}] == ["foo bar": 1, "bar baz": 2] ``` Remember that, because lists and two-element tuples are quoted literals, by definition keywords are also literals (in fact, the only reason tuples with two elements are quoted literals is to support keywords as literals). ### Keywords as last arguments Elixir also supports a syntax where if the last argument of a call is a keyword list then the square brackets can be skipped. This means that the following: ``` if(condition, do: this, else: that) ``` is the same as ``` if(condition, [do: this, else: that]) ``` which in turn is the same as ``` if(condition, [{:do, this}, {:else, that}]) ``` ### `do`/`end` blocks The last syntax convenience are `do`/`end` blocks. `do`/`end` blocks are equivalent to keywords as the last argument of a function call where the block contents are wrapped in parentheses. For example: ``` if true do this else that end ``` is the same as: ``` if(true, do: (this), else: (that)) ``` which we have explored in the previous section. Parentheses are important to support multiple expressions. This: ``` if true do this that end ``` is the same as: ``` if(true, do: ( this that )) ``` Inside `do`/`end` blocks you may introduce other keywords, such as `else` used in the `if` above. The supported keywords between `do`/`end` are static and are: * `after` * `catch` * `else` * `rescue` You can see them being used in constructs such as `receive`, `try`, and others. Summary -------- This document provides a reference to Elixir syntax, exploring its constructs and their AST equivalents. We have also discussed a handful of syntax conveniences provided by Elixir. Those conveniences are what allow us to write ``` defmodule Math do def add(a, b) do a + b end end ``` instead of ``` defmodule(Math, [ {:do, def(add(a, b), [{:do, a + b}])} ]) ``` The mapping between code and data (the underlying AST) is what allows Elixir to implement `defmodule`, `def`, `if`, and others in Elixir itself. Elixir makes the constructs available for building the language accessible to developers who want to extend the language to new domains.
programming_docs
elixir IO.ANSI IO.ANSI ======== Functionality to render ANSI escape sequences. [ANSI escape sequences](https://en.wikipedia.org/wiki/ANSI_escape_code) are characters embedded in text used to control formatting, color, and other output options on video text terminals. Summary ======== Types ------ [ansicode()](#t:ansicode/0) [ansidata()](#t:ansidata/0) [ansilist()](#t:ansilist/0) Functions ---------- [black()](#black/0) Sets foreground color to black. [black\_background()](#black_background/0) Sets background color to black. [blink\_off()](#blink_off/0) Blink: off. [blink\_rapid()](#blink_rapid/0) Blink: rapid. MS-DOS ANSI.SYS; 150 per minute or more; not widely supported. [blink\_slow()](#blink_slow/0) Blink: slow. Less than 150 per minute. [blue()](#blue/0) Sets foreground color to blue. [blue\_background()](#blue_background/0) Sets background color to blue. [bright()](#bright/0) Bright (increased intensity) or bold. [clear()](#clear/0) Clears screen. [clear\_line()](#clear_line/0) Clears line. [color(code)](#color/1) Sets foreground color. [color(r, g, b)](#color/3) Sets the foreground color from individual RGB values. [color\_background(code)](#color_background/1) Sets background color. [color\_background(r, g, b)](#color_background/3) Sets the background color from individual RGB values. [conceal()](#conceal/0) Conceal. Not widely supported. [crossed\_out()](#crossed_out/0) Crossed-out. Characters legible, but marked for deletion. Not widely supported. [cursor(line, column)](#cursor/2) Sends cursor to the absolute position specified by `line` and `column`. [cursor\_down(lines \\ 1)](#cursor_down/1) Sends cursor `lines` down. [cursor\_left(columns \\ 1)](#cursor_left/1) Sends cursor `columns` to the left. [cursor\_right(columns \\ 1)](#cursor_right/1) Sends cursor `columns` to the right. [cursor\_up(lines \\ 1)](#cursor_up/1) Sends cursor `lines` up. [cyan()](#cyan/0) Sets foreground color to cyan. [cyan\_background()](#cyan_background/0) Sets background color to cyan. [default\_background()](#default_background/0) Default background color. [default\_color()](#default_color/0) Default text color. [enabled?()](#enabled?/0) Checks if ANSI coloring is supported and enabled on this machine. [encircled()](#encircled/0) Encircled. [faint()](#faint/0) Faint (decreased intensity). Not widely supported. [font\_1()](#font_1/0) Sets alternative font 1. [font\_2()](#font_2/0) Sets alternative font 2. [font\_3()](#font_3/0) Sets alternative font 3. [font\_4()](#font_4/0) Sets alternative font 4. [font\_5()](#font_5/0) Sets alternative font 5. [font\_6()](#font_6/0) Sets alternative font 6. [font\_7()](#font_7/0) Sets alternative font 7. [font\_8()](#font_8/0) Sets alternative font 8. [font\_9()](#font_9/0) Sets alternative font 9. [format(chardata, emit? \\ enabled?())](#format/2) Formats a chardata-like argument by converting named ANSI sequences into actual ANSI codes. [format\_fragment(chardata, emit? \\ enabled?())](#format_fragment/2) Formats a chardata-like argument by converting named ANSI sequences into actual ANSI codes. [framed()](#framed/0) Framed. [green()](#green/0) Sets foreground color to green. [green\_background()](#green_background/0) Sets background color to green. [home()](#home/0) Sends cursor home. [inverse()](#inverse/0) Image: negative. Swap foreground and background. [inverse\_off()](#inverse_off/0) Image: positive. Normal foreground and background. [italic()](#italic/0) Italic: on. Not widely supported. Sometimes treated as inverse. [light\_black()](#light_black/0) Sets foreground color to light black. [light\_black\_background()](#light_black_background/0) Sets background color to light black. [light\_blue()](#light_blue/0) Sets foreground color to light blue. [light\_blue\_background()](#light_blue_background/0) Sets background color to light blue. [light\_cyan()](#light_cyan/0) Sets foreground color to light cyan. [light\_cyan\_background()](#light_cyan_background/0) Sets background color to light cyan. [light\_green()](#light_green/0) Sets foreground color to light green. [light\_green\_background()](#light_green_background/0) Sets background color to light green. [light\_magenta()](#light_magenta/0) Sets foreground color to light magenta. [light\_magenta\_background()](#light_magenta_background/0) Sets background color to light magenta. [light\_red()](#light_red/0) Sets foreground color to light red. [light\_red\_background()](#light_red_background/0) Sets background color to light red. [light\_white()](#light_white/0) Sets foreground color to light white. [light\_white\_background()](#light_white_background/0) Sets background color to light white. [light\_yellow()](#light_yellow/0) Sets foreground color to light yellow. [light\_yellow\_background()](#light_yellow_background/0) Sets background color to light yellow. [magenta()](#magenta/0) Sets foreground color to magenta. [magenta\_background()](#magenta_background/0) Sets background color to magenta. [no\_underline()](#no_underline/0) Underline: none. [normal()](#normal/0) Normal color or intensity. [not\_framed\_encircled()](#not_framed_encircled/0) Not framed or encircled. [not\_italic()](#not_italic/0) Not italic. [not\_overlined()](#not_overlined/0) Not overlined. [overlined()](#overlined/0) Overlined. [primary\_font()](#primary_font/0) Sets primary (default) font. [red()](#red/0) Sets foreground color to red. [red\_background()](#red_background/0) Sets background color to red. [reset()](#reset/0) Resets all attributes. [reverse()](#reverse/0) Image: negative. Swap foreground and background. [reverse\_off()](#reverse_off/0) Image: positive. Normal foreground and background. [underline()](#underline/0) Underline: single. [white()](#white/0) Sets foreground color to white. [white\_background()](#white_background/0) Sets background color to white. [yellow()](#yellow/0) Sets foreground color to yellow. [yellow\_background()](#yellow_background/0) Sets background color to yellow. Types ====== ### ansicode() #### Specs ``` ansicode() :: atom() ``` ### ansidata() #### Specs ``` ansidata() :: ansilist() | ansicode() | binary() ``` ### ansilist() #### Specs ``` ansilist() :: maybe_improper_list( char() | ansicode() | binary() | ansilist(), binary() | ansicode() | [] ) ``` Functions ========== ### black() Sets foreground color to black. ### black\_background() Sets background color to black. ### blink\_off() Blink: off. ### blink\_rapid() Blink: rapid. MS-DOS ANSI.SYS; 150 per minute or more; not widely supported. ### blink\_slow() Blink: slow. Less than 150 per minute. ### blue() Sets foreground color to blue. ### blue\_background() Sets background color to blue. ### bright() Bright (increased intensity) or bold. ### clear() Clears screen. ### clear\_line() Clears line. ### color(code) #### Specs ``` color(0..255) :: String.t() ``` Sets foreground color. ### color(r, g, b) #### Specs ``` color(0..5, 0..5, 0..5) :: String.t() ``` Sets the foreground color from individual RGB values. Valid values for each color are in the range 0 to 5. ### color\_background(code) #### Specs ``` color_background(0..255) :: String.t() ``` Sets background color. ### color\_background(r, g, b) #### Specs ``` color_background(0..5, 0..5, 0..5) :: String.t() ``` Sets the background color from individual RGB values. Valid values for each color are in the range 0 to 5. ### conceal() Conceal. Not widely supported. ### crossed\_out() Crossed-out. Characters legible, but marked for deletion. Not widely supported. ### cursor(line, column) #### Specs ``` cursor(non_neg_integer(), non_neg_integer()) :: String.t() ``` Sends cursor to the absolute position specified by `line` and `column`. Line `0` and column `0` would mean the top left corner. ### cursor\_down(lines \\ 1) #### Specs ``` cursor_down(pos_integer()) :: String.t() ``` Sends cursor `lines` down. ### cursor\_left(columns \\ 1) #### Specs ``` cursor_left(pos_integer()) :: String.t() ``` Sends cursor `columns` to the left. ### cursor\_right(columns \\ 1) #### Specs ``` cursor_right(pos_integer()) :: String.t() ``` Sends cursor `columns` to the right. ### cursor\_up(lines \\ 1) #### Specs ``` cursor_up(pos_integer()) :: String.t() ``` Sends cursor `lines` up. ### cyan() Sets foreground color to cyan. ### cyan\_background() Sets background color to cyan. ### default\_background() Default background color. ### default\_color() Default text color. ### enabled?() #### Specs ``` enabled?() :: boolean() ``` Checks if ANSI coloring is supported and enabled on this machine. This function simply reads the configuration value for `:ansi_enabled` in the `:elixir` application. The value is by default `false` unless Elixir can detect during startup that both `stdout` and `stderr` are terminals. ### encircled() Encircled. ### faint() Faint (decreased intensity). Not widely supported. ### font\_1() Sets alternative font 1. ### font\_2() Sets alternative font 2. ### font\_3() Sets alternative font 3. ### font\_4() Sets alternative font 4. ### font\_5() Sets alternative font 5. ### font\_6() Sets alternative font 6. ### font\_7() Sets alternative font 7. ### font\_8() Sets alternative font 8. ### font\_9() Sets alternative font 9. ### format(chardata, emit? \\ enabled?()) Formats a chardata-like argument by converting named ANSI sequences into actual ANSI codes. The named sequences are represented by atoms. It will also append an [`IO.ANSI.reset/0`](io.ansi#reset/0) to the chardata when a conversion is performed. If you don't want this behaviour, use [`format_fragment/2`](#format_fragment/2). An optional boolean parameter can be passed to enable or disable emitting actual ANSI codes. When `false`, no ANSI codes will emitted. By default checks if ANSI is enabled using the [`enabled?/0`](#enabled?/0) function. #### Examples ``` iex> IO.ANSI.format(["Hello, ", :red, :bright, "world!"], true) [[[[[[], "Hello, "] | "\e[31m"] | "\e[1m"], "world!"] | "\e[0m"] ``` ### format\_fragment(chardata, emit? \\ enabled?()) Formats a chardata-like argument by converting named ANSI sequences into actual ANSI codes. The named sequences are represented by atoms. An optional boolean parameter can be passed to enable or disable emitting actual ANSI codes. When `false`, no ANSI codes will be emitted. By default checks if ANSI is enabled using the [`enabled?/0`](#enabled?/0) function. #### Examples ``` iex> IO.ANSI.format_fragment([:bright, 'Word'], true) [[[[[[] | "\e[1m"], 87], 111], 114], 100] ``` ### framed() Framed. ### green() Sets foreground color to green. ### green\_background() Sets background color to green. ### home() Sends cursor home. ### inverse() Image: negative. Swap foreground and background. ### inverse\_off() Image: positive. Normal foreground and background. ### italic() Italic: on. Not widely supported. Sometimes treated as inverse. ### light\_black() Sets foreground color to light black. ### light\_black\_background() Sets background color to light black. ### light\_blue() Sets foreground color to light blue. ### light\_blue\_background() Sets background color to light blue. ### light\_cyan() Sets foreground color to light cyan. ### light\_cyan\_background() Sets background color to light cyan. ### light\_green() Sets foreground color to light green. ### light\_green\_background() Sets background color to light green. ### light\_magenta() Sets foreground color to light magenta. ### light\_magenta\_background() Sets background color to light magenta. ### light\_red() Sets foreground color to light red. ### light\_red\_background() Sets background color to light red. ### light\_white() Sets foreground color to light white. ### light\_white\_background() Sets background color to light white. ### light\_yellow() Sets foreground color to light yellow. ### light\_yellow\_background() Sets background color to light yellow. ### magenta() Sets foreground color to magenta. ### magenta\_background() Sets background color to magenta. ### no\_underline() Underline: none. ### normal() Normal color or intensity. ### not\_framed\_encircled() Not framed or encircled. ### not\_italic() Not italic. ### not\_overlined() Not overlined. ### overlined() Overlined. ### primary\_font() Sets primary (default) font. ### red() Sets foreground color to red. ### red\_background() Sets background color to red. ### reset() Resets all attributes. ### reverse() Image: negative. Swap foreground and background. ### reverse\_off() Image: positive. Normal foreground and background. ### underline() Underline: single. ### white() Sets foreground color to white. ### white\_background() Sets background color to white. ### yellow() Sets foreground color to yellow. ### yellow\_background() Sets background color to yellow. elixir Sigils Getting Started Sigils ====== We have already learned that Elixir provides double-quoted strings and single-quoted char lists. However, this only covers the surface of structures that have textual representation in the language. Atoms, for example, are mostly created via the `:atom` representation. One of Elixir’s goals is extensibility: developers should be able to extend the language to fit any particular domain. Computer science has become such a wide field that it is impossible for a language to tackle all aspects of it as part of its core. Instead, Elixir aims to make itself extensible so developers, companies, and communities can extend the language to their relevant domains. In this chapter, we are going to explore sigils, which are one of the mechanisms provided by the language for working with textual representations. Sigils start with the tilde (`~`) character which is followed by a letter (which identifies the sigil) and then a delimiter; optionally, modifiers can be added after the final delimiter. Regular expressions ------------------- The most common sigil in Elixir is `~r`, which is used to create [regular expressions](https://en.wikipedia.org/wiki/Regular_Expressions): ``` # A regular expression that matches strings which contain "foo" or "bar": iex> regex = ~r/foo|bar/ ~r/foo|bar/ iex> "foo" =~ regex true iex> "bat" =~ regex false ``` Elixir provides Perl-compatible regular expressions (regexes), as implemented by the [PCRE](http://www.pcre.org/) library. Regexes also support modifiers. For example, the `i` modifier makes a regular expression case insensitive: ``` iex> "HELLO" =~ ~r/hello/ false iex> "HELLO" =~ ~r/hello/i true ``` Check out the [`Regex` module](https://hexdocs.pm/elixir/Regex.html) for more information on other modifiers and the supported operations with regular expressions. So far, all examples have used `/` to delimit a regular expression. However, sigils support 8 different delimiters: ``` ~r/hello/ ~r|hello| ~r"hello" ~r'hello' ~r(hello) ~r[hello] ~r{hello} ~r<hello> ``` The reason behind supporting different delimiters is to provide a way to write literals without escaped delimiters. For example, a regular expression with forward slashes like `~r(^https?://)` reads arguably better than `~r/^https?:\/\//`. Similarly, if the regular expression has forward slashes and capturing groups (that use `()`), you may then choose double quotes instead of parentheses. Strings, char lists, and word lists sigils ------------------------------------------ Besides regular expressions, Elixir ships with three other sigils. ### Strings The `~s` sigil is used to generate strings, like double quotes are. The `~s` sigil is useful when a string contains double quotes: ``` iex> ~s(this is a string with "double" quotes, not 'single' ones) "this is a string with \"double\" quotes, not 'single' ones" ``` ### Char lists The `~c` sigil is useful for generating char lists that contain single quotes: ``` iex> ~c(this is a char list containing 'single quotes') 'this is a char list containing \'single quotes\'' ``` ### Word lists The `~w` sigil is used to generate lists of words (*words* are just regular strings). Inside the `~w` sigil, words are separated by whitespace. ``` iex> ~w(foo bar bat) ["foo", "bar", "bat"] ``` The `~w` sigil also accepts the `c`, `s` and `a` modifiers (for char lists, strings, and atoms, respectively), which specify the data type of the elements of the resulting list: ``` iex> ~w(foo bar bat)a [:foo, :bar, :bat] ``` Interpolation and escaping in string sigils ------------------------------------------- Elixir supports some sigil variants to deal with escaping characters and interpolation. In particular, uppercase letters sigils do not perform interpolation nor escaping. For example, although both `~s` and `~S` will return strings, the former allows escape codes and interpolation while the latter does not: ``` iex> ~s(String with escape codes \x26 #{"inter" <> "polation"}) "String with escape codes & interpolation" iex> ~S(String without escape codes \x26 without #{interpolation}) "String without escape codes \\x26 without \#{interpolation}" ``` The following escape codes can be used in strings and char lists: * `\\` – single backslash * `\a` – bell/alert * `\b` – backspace * `\d` - delete * `\e` - escape * `\f` - form feed * `\n` – newline * `\r` – carriage return * `\s` – space * `\t` – tab * `\v` – vertical tab * `\0` - null byte * `\xDD` - represents a single byte in hexadecimal (such as `\x13`) * `\uDDDD` and `\u{D...}` - represents a Unicode codepoint in hexadecimal (such as `\u{1F600}`) In addition to those, a double quote inside a double-quoted string needs to be escaped as `\"`, and, analogously, a single quote inside a single-quoted char list needs to be escaped as `\'`. Nevertheless, it is better style to change delimiters as seen above than to escape them. Sigils also support heredocs, that is, triple double- or single-quotes as separators: ``` iex> ~s""" ...> this is ...> a heredoc string ...> """ ``` The most common use case for heredoc sigils is when writing documentation. For example, writing escape characters in the documentation would soon become error prone because of the need to double-escape some characters: ``` @doc """ Converts double-quotes to single-quotes. ## Examples iex> convert("\\\"foo\\\"") "'foo'" """ def convert(...) ``` By using `~S`, this problem can be avoided altogether: ``` @doc ~S""" Converts double-quotes to single-quotes. ## Examples iex> convert("\"foo\"") "'foo'" """ def convert(...) ``` Calendar sigils --------------- Elixir offers several sigils to deal with various flavors of times and dates. ### Date A [%Date{}](https://hexdocs.pm/elixir/Date.html) struct contains the fields `year`, `month`, `day`, and `calendar`. You can create one using the `~D` sigil: ``` iex> d = ~D[2019-10-31] ~D[2019-10-31] iex> d.day 31 ``` ### Time The [%Time{}](https://hexdocs.pm/elixir/Time.html) struct contains the fields `hour`, `minute`, `second`, `microsecond`, and `calendar`. You can create one using the `~T` sigil: ``` iex> t = ~T[23:00:07.0] ~T[23:00:07.0] iex> t.second 7 ``` ### NaiveDateTime The [%NaiveDateTime{}](https://hexdocs.pm/elixir/NaiveDateTime.html) struct contains fields from both `Date` and `Time`. You can create one using the `~N` sigil: ``` iex> ndt = ~N[2019-10-31 23:00:07] ~N[2019-10-31 23:00:07] ``` Why is it called naive? Because it does not contain timezone information. Therefore, the given datetime may not exist at all or it may exist twice in certain timezones - for example, when we move the clock back and forward for daylight saving time. ### DateTime A [%DateTime{}](https://hexdocs.pm/elixir/DateTime.html) struct contains the same fields as a `NaiveDateTime` with the addition of fields to track timezones. The `~U` sigil allows developers to create a DateTime in the UTC timezone: ``` iex> dt = ~U[2019-10-31 19:59:03Z] ~U[2019-10-31 19:59:03Z] iex> %DateTime{minute: minute, time_zone: time_zone} = dt ~U[2019-10-31 19:59:03Z] iex> minute 59 iex> time_zone "Etc/UTC" ``` Custom sigils ------------- As hinted at the beginning of this chapter, sigils in Elixir are extensible. In fact, using the sigil `~r/foo/i` is equivalent to calling `sigil_r` with a binary and a char list as the argument: ``` iex> sigil_r(<<"foo">>, 'i') ~r"foo"i ``` We can access the documentation for the `~r` sigil via `sigil_r`: ``` iex> h sigil_r ... ``` We can also provide our own sigils by implementing functions that follow the `sigil_{identifier}` pattern. For example, let’s implement the `~i` sigil that returns an integer (with the optional `n` modifier to make it negative): ``` iex> defmodule MySigils do ...> def sigil_i(string, []), do: String.to_integer(string) ...> def sigil_i(string, [?n]), do: -String.to_integer(string) ...> end iex> import MySigils iex> ~i(13) 13 iex> ~i(42)n -42 ``` Sigils can also be used to do compile-time work with the help of macros. For example, regular expressions in Elixir are compiled into an efficient representation during compilation of the source code, therefore skipping this step at runtime. If you’re interested in the subject, we recommend you learn more about macros and check out how sigils are implemented in the `Kernel` module (where the `sigil_*` functions are defined).
programming_docs
elixir DateTime DateTime ========= A datetime implementation with a time zone. This datetime can be seen as an ephemeral snapshot of a datetime at a given time zone. For such purposes, it also includes both UTC and Standard offsets, as well as the zone abbreviation field used exclusively for formatting purposes. Remember, comparisons in Elixir using [`==/2`](kernel#==/2), [`>/2`](kernel#%3E/2), [`</2`](kernel#%3C/2) and friends are structural and based on the DateTime struct fields. For proper comparison between datetimes, use the [`compare/2`](#compare/2) function. Developers should avoid creating the [`DateTime`](#content) struct directly and instead rely on the functions provided by this module as well as the ones in third-party calendar libraries. Time zone database ------------------- Many functions in this module require a time zone database. By default, it uses the default time zone database returned by [`Calendar.get_time_zone_database/0`](calendar#get_time_zone_database/0), which defaults to [`Calendar.UTCOnlyTimeZoneDatabase`](calendar.utconlytimezonedatabase) which only handles "Etc/UTC" datetimes and returns `{:error, :utc_only_time_zone_database}` for any other time zone. Other time zone databases (including ones provided by packages) can be configure as default either via configuration: ``` config :elixir, :time_zone_database, CustomTimeZoneDatabase ``` or by calling [`Calendar.put_time_zone_database/1`](calendar#put_time_zone_database/1). Summary ======== Types ------ [t()](#t:t/0) Functions ---------- [add(datetime, amount\_to\_add, unit \\ :second, time\_zone\_database \\ Calendar.get\_time\_zone\_database())](#add/4) Adds a specified amount of time to a [`DateTime`](#content). [compare(datetime1, datetime2)](#compare/2) Compares two datetime structs. [convert(datetime, calendar)](#convert/2) Converts a given `datetime` from one calendar to another. [convert!(datetime, calendar)](#convert!/2) Converts a given `datetime` from one calendar to another. [diff(datetime1, datetime2, unit \\ :second)](#diff/3) Subtracts `datetime2` from `datetime1`. [from\_iso8601(string, calendar \\ Calendar.ISO)](#from_iso8601/2) Parses the extended "Date and time of day" format described by [ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601). [from\_naive(naive\_datetime, time\_zone, time\_zone\_database \\ Calendar.get\_time\_zone\_database())](#from_naive/3) Converts the given [`NaiveDateTime`](naivedatetime) to [`DateTime`](#content). [from\_naive!(naive\_datetime, time\_zone, time\_zone\_database \\ Calendar.get\_time\_zone\_database())](#from_naive!/3) Converts the given [`NaiveDateTime`](naivedatetime) to [`DateTime`](#content). [from\_unix(integer, unit \\ :second, calendar \\ Calendar.ISO)](#from_unix/3) Converts the given Unix time to [`DateTime`](#content). [from\_unix!(integer, unit \\ :second, calendar \\ Calendar.ISO)](#from_unix!/3) Converts the given Unix time to [`DateTime`](#content). [now(time\_zone, time\_zone\_database \\ Calendar.get\_time\_zone\_database())](#now/2) Returns the current datetime in the provided time zone. [shift\_zone(datetime, time\_zone, time\_zone\_database \\ Calendar.get\_time\_zone\_database())](#shift_zone/3) Changes the time zone of a [`DateTime`](#content). [to\_date(map)](#to_date/1) Converts a [`DateTime`](#content) into a [`Date`](date). [to\_iso8601(datetime, format \\ :extended)](#to_iso8601/2) Converts the given datetime to [ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601) format. [to\_naive(map)](#to_naive/1) Converts the given `datetime` into a [`NaiveDateTime`](naivedatetime). [to\_string(datetime)](#to_string/1) Converts the given `datetime` to a string according to its calendar. [to\_time(map)](#to_time/1) Converts a [`DateTime`](#content) into [`Time`](time). [to\_unix(datetime, unit \\ :second)](#to_unix/2) Converts the given `datetime` to Unix time. [truncate(datetime, precision)](#truncate/2) Returns the given datetime with the microsecond field truncated to the given precision (`:microsecond`, `millisecond` or `:second`). [utc\_now(calendar \\ Calendar.ISO)](#utc_now/1) Returns the current datetime in UTC. Types ====== ### t() #### Specs ``` t() :: %DateTime{ calendar: Calendar.calendar(), day: Calendar.day(), hour: Calendar.hour(), microsecond: Calendar.microsecond(), minute: Calendar.minute(), month: Calendar.month(), second: Calendar.second(), std_offset: Calendar.std_offset(), time_zone: Calendar.time_zone(), utc_offset: Calendar.utc_offset(), year: Calendar.year(), zone_abbr: Calendar.zone_abbr() } ``` Functions ========== ### add(datetime, amount\_to\_add, unit \\ :second, time\_zone\_database \\ Calendar.get\_time\_zone\_database()) #### Specs ``` add( Calendar.datetime(), integer(), System.time_unit(), Calendar.time_zone_database() ) :: t() ``` Adds a specified amount of time to a [`DateTime`](#content). Accepts an `amount_to_add` in any `unit` available from [`System.time_unit/0`](system#t:time_unit/0). Negative values will move backwards in time. Takes changes such as summer time/DST into account. This means that adding time can cause the wall time to "go backwards" during "fall back" during autumn. Adding just a few seconds to a datetime just before "spring forward" can cause wall time to increase by more than an hour. Fractional second precision stays the same in a similar way to [`NaiveDateTime.add/2`](naivedatetime#add/2). ### Examples ``` iex> dt = DateTime.from_naive!(~N[2018-11-15 10:00:00], "Europe/Copenhagen", FakeTimeZoneDatabase) iex> dt |> DateTime.add(3600, :second, FakeTimeZoneDatabase) #DateTime<2018-11-15 11:00:00+01:00 CET Europe/Copenhagen> iex> DateTime.add(~U[2018-11-15 10:00:00Z], 3600, :second) ~U[2018-11-15 11:00:00Z] ``` When adding 3 seconds just before "spring forward" we go from 1:59:59 to 3:00:02 ``` iex> dt = DateTime.from_naive!(~N[2019-03-31 01:59:59.123], "Europe/Copenhagen", FakeTimeZoneDatabase) iex> dt |> DateTime.add(3, :second, FakeTimeZoneDatabase) #DateTime<2019-03-31 03:00:02.123+02:00 CEST Europe/Copenhagen> ``` ### compare(datetime1, datetime2) #### Specs ``` compare(Calendar.datetime(), Calendar.datetime()) :: :lt | :eq | :gt ``` Compares two datetime structs. Returns `:gt` if the first datetime is later than the second and `:lt` for vice versa. If the two datetimes are equal `:eq` is returned. Note that both UTC and Standard offsets will be taken into account when comparison is done. #### Examples ``` iex> dt1 = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "AMT", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: -14400, std_offset: 0, time_zone: "America/Manaus"} iex> dt2 = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "CET", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: 3600, std_offset: 0, time_zone: "Europe/Warsaw"} iex> DateTime.compare(dt1, dt2) :gt ``` ### convert(datetime, calendar) #### Specs ``` convert(Calendar.datetime(), Calendar.calendar()) :: {:ok, t()} | {:error, :incompatible_calendars} ``` Converts a given `datetime` from one calendar to another. If it is not possible to convert unambiguously between the calendars (see [`Calendar.compatible_calendars?/2`](calendar#compatible_calendars?/2)), an `{:error, :incompatible_calendars}` tuple is returned. #### Examples Imagine someone implements `Calendar.Holocene`, a calendar based on the Gregorian calendar that adds exactly 10,000 years to the current Gregorian year: ``` iex> dt1 = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "AMT", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: -14400, std_offset: 0, time_zone: "America/Manaus"} iex> DateTime.convert(dt1, Calendar.Holocene) {:ok, %DateTime{calendar: Calendar.Holocene, day: 29, hour: 23, microsecond: {0, 0}, minute: 0, month: 2, second: 7, std_offset: 0, time_zone: "America/Manaus", utc_offset: -14400, year: 12000, zone_abbr: "AMT"}} ``` ### convert!(datetime, calendar) #### Specs ``` convert!(Calendar.datetime(), Calendar.calendar()) :: t() ``` Converts a given `datetime` from one calendar to another. If it is not possible to convert unambiguously between the calendars (see [`Calendar.compatible_calendars?/2`](calendar#compatible_calendars?/2)), an ArgumentError is raised. #### Examples Imagine someone implements `Calendar.Holocene`, a calendar based on the Gregorian calendar that adds exactly 10,000 years to the current Gregorian year: ``` iex> dt1 = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "AMT", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: -14400, std_offset: 0, time_zone: "America/Manaus"} iex> DateTime.convert!(dt1, Calendar.Holocene) %DateTime{calendar: Calendar.Holocene, day: 29, hour: 23, microsecond: {0, 0}, minute: 0, month: 2, second: 7, std_offset: 0, time_zone: "America/Manaus", utc_offset: -14400, year: 12000, zone_abbr: "AMT"} ``` ### diff(datetime1, datetime2, unit \\ :second) #### Specs ``` diff(Calendar.datetime(), Calendar.datetime(), System.time_unit()) :: integer() ``` Subtracts `datetime2` from `datetime1`. The answer can be returned in any `unit` available from [`System.time_unit/0`](system#t:time_unit/0). Leap seconds are not taken into account. This function returns the difference in seconds where seconds are measured according to [`Calendar.ISO`](calendar.iso). #### Examples ``` iex> dt1 = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "AMT", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: -14400, std_offset: 0, time_zone: "America/Manaus"} iex> dt2 = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "CET", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: 3600, std_offset: 0, time_zone: "Europe/Warsaw"} iex> DateTime.diff(dt1, dt2) 18000 iex> DateTime.diff(dt2, dt1) -18000 ``` ### from\_iso8601(string, calendar \\ Calendar.ISO) #### Specs ``` from_iso8601(String.t(), Calendar.calendar()) :: {:ok, t(), Calendar.utc_offset()} | {:error, atom()} ``` Parses the extended "Date and time of day" format described by [ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601). Since ISO 8601 does not include the proper time zone, the given string will be converted to UTC and its offset in seconds will be returned as part of this function. Therefore offset information must be present in the string. As specified in the standard, the separator "T" may be omitted if desired as there is no ambiguity within this function. The year parsed by this function is limited to four digits and, while ISO 8601 allows datetimes to specify 24:00:00 as the zero hour of the next day, this notation is not supported by Elixir. Note leap seconds are not supported by the built-in Calendar.ISO. #### Examples ``` iex> {:ok, datetime, 0} = DateTime.from_iso8601("2015-01-23T23:50:07Z") iex> datetime ~U[2015-01-23 23:50:07Z] iex> {:ok, datetime, 9000} = DateTime.from_iso8601("2015-01-23T23:50:07.123+02:30") iex> datetime ~U[2015-01-23 21:20:07.123Z] iex> {:ok, datetime, 9000} = DateTime.from_iso8601("2015-01-23T23:50:07,123+02:30") iex> datetime ~U[2015-01-23 21:20:07.123Z] iex> {:ok, datetime, 0} = DateTime.from_iso8601("-2015-01-23T23:50:07Z") iex> datetime ~U[-2015-01-23 23:50:07Z] iex> {:ok, datetime, 9000} = DateTime.from_iso8601("-2015-01-23T23:50:07,123+02:30") iex> datetime ~U[-2015-01-23 21:20:07.123Z] iex> DateTime.from_iso8601("2015-01-23P23:50:07") {:error, :invalid_format} iex> DateTime.from_iso8601("2015-01-23T23:50:07") {:error, :missing_offset} iex> DateTime.from_iso8601("2015-01-23 23:50:61") {:error, :invalid_time} iex> DateTime.from_iso8601("2015-01-32 23:50:07") {:error, :invalid_date} iex> DateTime.from_iso8601("2015-01-23T23:50:07.123-00:00") {:error, :invalid_format} ``` ### from\_naive(naive\_datetime, time\_zone, time\_zone\_database \\ Calendar.get\_time\_zone\_database()) #### Specs ``` from_naive( Calendar.naive_datetime(), Calendar.time_zone(), Calendar.time_zone_database() ) :: {:ok, t()} | {:ambiguous, t(), t()} | {:gap, t(), t()} | {:error, :incompatible_calendars | :time_zone_not_found | :utc_only_time_zone_database} ``` Converts the given [`NaiveDateTime`](naivedatetime) to [`DateTime`](#content). It expects a time zone to put the [`NaiveDateTime`](naivedatetime) in. If the time zone is "Etc/UTC", it always succeeds. Otherwise, the NaiveDateTime is checked against the time zone database given as `time_zone_database`. See the "Time zone database" section in the module documentation. #### Examples ``` iex> DateTime.from_naive(~N[2016-05-24 13:26:08.003], "Etc/UTC") {:ok, ~U[2016-05-24 13:26:08.003Z]} ``` When the datetime is ambiguous - for instance during changing from summer to winter time - the two possible valid datetimes are returned. First the one that happens first, then the one that happens after. ``` iex> {:ambiguous, first_dt, second_dt} = DateTime.from_naive(~N[2018-10-28 02:30:00], "Europe/Copenhagen", FakeTimeZoneDatabase) iex> first_dt #DateTime<2018-10-28 02:30:00+02:00 CEST Europe/Copenhagen> iex> second_dt #DateTime<2018-10-28 02:30:00+01:00 CET Europe/Copenhagen> ``` When there is a gap in wall time - for instance in spring when the clocks are turned forward - the latest valid datetime just before the gap and the first valid datetime just after the gap. ``` iex> {:gap, just_before, just_after} = DateTime.from_naive(~N[2019-03-31 02:30:00], "Europe/Copenhagen", FakeTimeZoneDatabase) iex> just_before #DateTime<2019-03-31 01:59:59.999999+01:00 CET Europe/Copenhagen> iex> just_after #DateTime<2019-03-31 03:00:00+02:00 CEST Europe/Copenhagen> ``` Most of the time there is one, and just one, valid datetime for a certain date and time in a certain time zone. ``` iex> {:ok, datetime} = DateTime.from_naive(~N[2018-07-28 12:30:00], "Europe/Copenhagen", FakeTimeZoneDatabase) iex> datetime #DateTime<2018-07-28 12:30:00+02:00 CEST Europe/Copenhagen> ``` This function accepts any map or struct that contains at least the same fields as a [`NaiveDateTime`](naivedatetime) struct. The most common example of that is a [`DateTime`](#content). In this case the information about the time zone of that [`DateTime`](#content) is completely ignored. This is the same principle as passing a [`DateTime`](#content) to [`Date.to_iso8601/2`](date#to_iso8601/2). [`Date.to_iso8601/2`](date#to_iso8601/2) extracts only the date-specific fields (calendar, year, month and day) of the given structure and ignores all others. This way if you have a [`DateTime`](#content) in one time zone, you can get the same wall time in another time zone. For instance if you have 2018-08-24 10:00:00 in Copenhagen and want a [`DateTime`](#content) for 2018-08-24 10:00:00 in UTC you can do: ``` iex> cph_datetime = DateTime.from_naive!(~N[2018-08-24 10:00:00], "Europe/Copenhagen", FakeTimeZoneDatabase) iex> {:ok, utc_datetime} = DateTime.from_naive(cph_datetime, "Etc/UTC", FakeTimeZoneDatabase) iex> utc_datetime ~U[2018-08-24 10:00:00Z] ``` If instead you want a [`DateTime`](#content) for the same point time in a different time zone see the [`DateTime.shift_zone/3`](datetime#shift_zone/3) function which would convert 2018-08-24 10:00:00 in Copenhagen to 2018-08-24 08:00:00 in UTC. ### from\_naive!(naive\_datetime, time\_zone, time\_zone\_database \\ Calendar.get\_time\_zone\_database()) #### Specs ``` from_naive!( NaiveDateTime.t(), Calendar.time_zone(), Calendar.time_zone_database() ) :: t() ``` Converts the given [`NaiveDateTime`](naivedatetime) to [`DateTime`](#content). It expects a time zone to put the NaiveDateTime in. If the time zone is "Etc/UTC", it always succeeds. Otherwise, the NaiveDateTime is checked against the time zone database given as `time_zone_database`. See the "Time zone database" section in the module documentation. #### Examples ``` iex> DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC") ~U[2016-05-24 13:26:08.003Z] iex> DateTime.from_naive!(~N[2018-05-24 13:26:08.003], "Europe/Copenhagen", FakeTimeZoneDatabase) #DateTime<2018-05-24 13:26:08.003+02:00 CEST Europe/Copenhagen> ``` ### from\_unix(integer, unit \\ :second, calendar \\ Calendar.ISO) #### Specs ``` from_unix(integer(), :native | System.time_unit(), Calendar.calendar()) :: {:ok, t()} | {:error, atom()} ``` Converts the given Unix time to [`DateTime`](#content). The integer can be given in different unit according to [`System.convert_time_unit/3`](system#convert_time_unit/3) and it will be converted to microseconds internally. Unix times are always in UTC and therefore the DateTime will be returned in UTC. #### Examples ``` iex> {:ok, datetime} = DateTime.from_unix(1_464_096_368) iex> datetime ~U[2016-05-24 13:26:08Z] iex> {:ok, datetime} = DateTime.from_unix(1_432_560_368_868_569, :microsecond) iex> datetime ~U[2015-05-25 13:26:08.868569Z] ``` The unit can also be an integer as in [`System.time_unit/0`](system#t:time_unit/0): ``` iex> {:ok, datetime} = DateTime.from_unix(143_256_036_886_856, 1024) iex> datetime ~U[6403-03-17 07:05:22.320312Z] ``` Negative Unix times are supported, up to -62167219200 seconds, which is equivalent to "0000-01-01T00:00:00Z" or 0 Gregorian seconds. ### from\_unix!(integer, unit \\ :second, calendar \\ Calendar.ISO) #### Specs ``` from_unix!(integer(), :native | System.time_unit(), Calendar.calendar()) :: t() ``` Converts the given Unix time to [`DateTime`](#content). The integer can be given in different unit according to [`System.convert_time_unit/3`](system#convert_time_unit/3) and it will be converted to microseconds internally. Unix times are always in UTC and therefore the DateTime will be returned in UTC. #### Examples ``` # An easy way to get the Unix epoch is passing 0 to this function iex> DateTime.from_unix!(0) ~U[1970-01-01 00:00:00Z] iex> DateTime.from_unix!(1_464_096_368) ~U[2016-05-24 13:26:08Z] iex> DateTime.from_unix!(1_432_560_368_868_569, :microsecond) ~U[2015-05-25 13:26:08.868569Z] iex> DateTime.from_unix!(143_256_036_886_856, 1024) ~U[6403-03-17 07:05:22.320312Z] ``` ### now(time\_zone, time\_zone\_database \\ Calendar.get\_time\_zone\_database()) #### Specs ``` now(Calendar.time_zone(), Calendar.time_zone_database()) :: {:ok, t()} | {:error, :time_zone_not_found | :utc_only_time_zone_database} ``` Returns the current datetime in the provided time zone. By default, it uses the default time\_zone returned by [`Calendar.get_time_zone_database/0`](calendar#get_time_zone_database/0), which defaults to [`Calendar.UTCOnlyTimeZoneDatabase`](calendar.utconlytimezonedatabase) which only handles "Etc/UTC" datetimes. Other time zone databases can be passed as argument or set globally. See the "Time zone database" section in the module docs. #### Examples ``` iex> {:ok, datetime} = DateTime.now("Etc/UTC") iex> datetime.time_zone "Etc/UTC" iex> DateTime.now("Europe/Copenhagen") {:error, :utc_only_time_zone_database} iex> DateTime.now("not a real time zone name", FakeTimeZoneDatabase) {:error, :time_zone_not_found} ``` ### shift\_zone(datetime, time\_zone, time\_zone\_database \\ Calendar.get\_time\_zone\_database()) #### Specs ``` shift_zone(t(), Calendar.time_zone(), Calendar.time_zone_database()) :: {:ok, t()} | {:error, :time_zone_not_found | :utc_only_time_zone_database} ``` Changes the time zone of a [`DateTime`](#content). Returns a [`DateTime`](#content) for the same point in time, but instead at the time zone provided. It assumes that [`DateTime`](#content) is valid and exists in the given time zone and calendar. By default, it uses the default time zone database returned by [`Calendar.get_time_zone_database/0`](calendar#get_time_zone_database/0), which defaults to [`Calendar.UTCOnlyTimeZoneDatabase`](calendar.utconlytimezonedatabase) which only handles "Etc/UTC" datetimes. Other time zone databases can be passed as argument or set globally. See the "Time zone database" section in the module docs. #### Examples ``` iex> cph_datetime = DateTime.from_naive!(~N[2018-07-16 12:00:00], "Europe/Copenhagen", FakeTimeZoneDatabase) iex> {:ok, pacific_datetime} = DateTime.shift_zone(cph_datetime, "America/Los_Angeles", FakeTimeZoneDatabase) iex> pacific_datetime #DateTime<2018-07-16 03:00:00-07:00 PDT America/Los_Angeles> ``` ### to\_date(map) #### Specs ``` to_date(Calendar.datetime()) :: Date.t() ``` Converts a [`DateTime`](#content) into a [`Date`](date). Because [`Date`](date) does not hold time nor time zone information, data will be lost during the conversion. #### Examples ``` iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "CET", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: 3600, std_offset: 0, time_zone: "Europe/Warsaw"} iex> DateTime.to_date(dt) ~D[2000-02-29] ``` ### to\_iso8601(datetime, format \\ :extended) #### Specs ``` to_iso8601(Calendar.datetime(), :extended | :basic) :: String.t() ``` Converts the given datetime to [ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601) format. By default, [`DateTime.to_iso8601/2`](datetime#to_iso8601/2) returns datetimes formatted in the "extended" format, for human readability. It also supports the "basic" format through passing the `:basic` option. Only supports converting datetimes which are in the ISO calendar, attempting to convert datetimes from other calendars will raise. WARNING: the ISO 8601 datetime format does not contain the time zone nor its abbreviation, which means information is lost when converting to such format. ### Examples ``` iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "CET", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: 3600, std_offset: 0, time_zone: "Europe/Warsaw"} iex> DateTime.to_iso8601(dt) "2000-02-29T23:00:07+01:00" iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "UTC", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: 0, std_offset: 0, time_zone: "Etc/UTC"} iex> DateTime.to_iso8601(dt) "2000-02-29T23:00:07Z" iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "AMT", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: -14400, std_offset: 0, time_zone: "America/Manaus"} iex> DateTime.to_iso8601(dt, :extended) "2000-02-29T23:00:07-04:00" iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "AMT", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: -14400, std_offset: 0, time_zone: "America/Manaus"} iex> DateTime.to_iso8601(dt, :basic) "20000229T230007-0400" ``` ### to\_naive(map) #### Specs ``` to_naive(Calendar.datetime()) :: NaiveDateTime.t() ``` Converts the given `datetime` into a [`NaiveDateTime`](naivedatetime). Because [`NaiveDateTime`](naivedatetime) does not hold time zone information, any time zone related data will be lost during the conversion. #### Examples ``` iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "CET", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 1}, ...> utc_offset: 3600, std_offset: 0, time_zone: "Europe/Warsaw"} iex> DateTime.to_naive(dt) ~N[2000-02-29 23:00:07.0] ``` ### to\_string(datetime) #### Specs ``` to_string(Calendar.datetime()) :: String.t() ``` Converts the given `datetime` to a string according to its calendar. ### Examples ``` iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "CET", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: 3600, std_offset: 0, time_zone: "Europe/Warsaw"} iex> DateTime.to_string(dt) "2000-02-29 23:00:07+01:00 CET Europe/Warsaw" iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "UTC", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: 0, std_offset: 0, time_zone: "Etc/UTC"} iex> DateTime.to_string(dt) "2000-02-29 23:00:07Z" iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "AMT", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 0}, ...> utc_offset: -14400, std_offset: 0, time_zone: "America/Manaus"} iex> DateTime.to_string(dt) "2000-02-29 23:00:07-04:00 AMT America/Manaus" iex> dt = %DateTime{year: -100, month: 12, day: 19, zone_abbr: "CET", ...> hour: 3, minute: 20, second: 31, microsecond: {0, 0}, ...> utc_offset: 3600, std_offset: 0, time_zone: "Europe/Stockholm"} iex> DateTime.to_string(dt) "-0100-12-19 03:20:31+01:00 CET Europe/Stockholm" ``` ### to\_time(map) #### Specs ``` to_time(Calendar.datetime()) :: Time.t() ``` Converts a [`DateTime`](#content) into [`Time`](time). Because [`Time`](time) does not hold date nor time zone information, data will be lost during the conversion. #### Examples ``` iex> dt = %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "CET", ...> hour: 23, minute: 0, second: 7, microsecond: {0, 1}, ...> utc_offset: 3600, std_offset: 0, time_zone: "Europe/Warsaw"} iex> DateTime.to_time(dt) ~T[23:00:07.0] ``` ### to\_unix(datetime, unit \\ :second) #### Specs ``` to_unix(Calendar.datetime(), System.time_unit()) :: integer() ``` Converts the given `datetime` to Unix time. The `datetime` is expected to be using the ISO calendar with a year greater than or equal to 0. It will return the integer with the given unit, according to [`System.convert_time_unit/3`](system#convert_time_unit/3). #### Examples ``` iex> 1_464_096_368 |> DateTime.from_unix!() |> DateTime.to_unix() 1464096368 iex> dt = %DateTime{calendar: Calendar.ISO, day: 20, hour: 18, microsecond: {273806, 6}, ...> minute: 58, month: 11, second: 19, time_zone: "America/Montevideo", ...> utc_offset: -10800, std_offset: 3600, year: 2014, zone_abbr: "UYST"} iex> DateTime.to_unix(dt) 1416517099 iex> flamel = %DateTime{calendar: Calendar.ISO, day: 22, hour: 8, microsecond: {527771, 6}, ...> minute: 2, month: 3, second: 25, std_offset: 0, time_zone: "Etc/UTC", ...> utc_offset: 0, year: 1418, zone_abbr: "UTC"} iex> DateTime.to_unix(flamel) -17412508655 ``` ### truncate(datetime, precision) #### Specs ``` truncate(Calendar.datetime(), :microsecond | :millisecond | :second) :: t() ``` Returns the given datetime with the microsecond field truncated to the given precision (`:microsecond`, `millisecond` or `:second`). The given datetime is returned unchanged if it already has lower precision than the given precision. #### Examples ``` iex> dt1 = %DateTime{year: 2017, month: 11, day: 7, zone_abbr: "CET", ...> hour: 11, minute: 45, second: 18, microsecond: {123456, 6}, ...> utc_offset: 3600, std_offset: 0, time_zone: "Europe/Paris"} iex> DateTime.truncate(dt1, :microsecond) #DateTime<2017-11-07 11:45:18.123456+01:00 CET Europe/Paris> iex> dt2 = %DateTime{year: 2017, month: 11, day: 7, zone_abbr: "CET", ...> hour: 11, minute: 45, second: 18, microsecond: {123456, 6}, ...> utc_offset: 3600, std_offset: 0, time_zone: "Europe/Paris"} iex> DateTime.truncate(dt2, :millisecond) #DateTime<2017-11-07 11:45:18.123+01:00 CET Europe/Paris> iex> dt3 = %DateTime{year: 2017, month: 11, day: 7, zone_abbr: "CET", ...> hour: 11, minute: 45, second: 18, microsecond: {123456, 6}, ...> utc_offset: 3600, std_offset: 0, time_zone: "Europe/Paris"} iex> DateTime.truncate(dt3, :second) #DateTime<2017-11-07 11:45:18+01:00 CET Europe/Paris> ``` ### utc\_now(calendar \\ Calendar.ISO) #### Specs ``` utc_now(Calendar.calendar()) :: t() ``` Returns the current datetime in UTC. #### Examples ``` iex> datetime = DateTime.utc_now() iex> datetime.time_zone "Etc/UTC" ```
programming_docs
elixir Set Set ==== This module is deprecated. Use MapSet instead. Generic API for sets. This module is deprecated, use the [`MapSet`](mapset) module instead. Summary ======== Types ------ [t()](#t:t/0) [value()](#t:value/0) [values()](#t:values/0) Functions ---------- [delete(set, value)](#delete/2) deprecated [difference(set1, set2)](#difference/2) deprecated [disjoint?(set1, set2)](#disjoint?/2) deprecated [empty(set)](#empty/1) deprecated [equal?(set1, set2)](#equal?/2) deprecated [intersection(set1, set2)](#intersection/2) deprecated [member?(set, value)](#member?/2) deprecated [put(set, value)](#put/2) deprecated [size(set)](#size/1) deprecated [subset?(set1, set2)](#subset?/2) deprecated [to\_list(set)](#to_list/1) deprecated [union(set1, set2)](#union/2) deprecated Types ====== ### t() #### Specs ``` t() :: map() ``` ### value() #### Specs ``` value() :: any() ``` ### values() #### Specs ``` values() :: [value()] ``` Functions ========== ### delete(set, value) This function is deprecated. Use the MapSet module for working with sets. ### difference(set1, set2) This function is deprecated. Use the MapSet module for working with sets. ### disjoint?(set1, set2) This function is deprecated. Use the MapSet module for working with sets. ### empty(set) This function is deprecated. Use the MapSet module for working with sets. ### equal?(set1, set2) This function is deprecated. Use the MapSet module for working with sets. ### intersection(set1, set2) This function is deprecated. Use the MapSet module for working with sets. ### member?(set, value) This function is deprecated. Use the MapSet module for working with sets. ### put(set, value) This function is deprecated. Use the MapSet module for working with sets. ### size(set) This function is deprecated. Use the MapSet module for working with sets. ### subset?(set1, set2) This function is deprecated. Use the MapSet module for working with sets. ### to\_list(set) This function is deprecated. Use the MapSet module for working with sets. ### union(set1, set2) This function is deprecated. Use the MapSet module for working with sets. elixir Dict Dict ===== This module is deprecated. Use Map or Keyword modules instead. Generic API for dictionaries. If you need a general dictionary, use the [`Map`](map) module. If you need to manipulate keyword lists, use [`Keyword`](keyword). To convert maps into keywords and vice-versa, use the `new` function in the respective modules. Summary ======== Types ------ [key()](#t:key/0) [t()](#t:t/0) [value()](#t:value/0) Functions ---------- [delete(dict, key)](#delete/2) deprecated [drop(dict, keys)](#drop/2) deprecated [empty(dict)](#empty/1) deprecated [equal?(dict1, dict2)](#equal?/2) deprecated [fetch(dict, key)](#fetch/2) deprecated [fetch!(dict, key)](#fetch!/2) deprecated [get(dict, key, default \\ nil)](#get/3) deprecated [get\_and\_update(dict, key, fun)](#get_and_update/3) deprecated [get\_lazy(dict, key, fun)](#get_lazy/3) deprecated [has\_key?(dict, key)](#has_key?/2) deprecated [keys(dict)](#keys/1) deprecated [merge(dict1, dict2)](#merge/2) deprecated [merge(dict1, dict2, fun)](#merge/3) deprecated [pop(dict, key, default \\ nil)](#pop/3) deprecated [pop\_lazy(dict, key, fun)](#pop_lazy/3) deprecated [put(dict, key, val)](#put/3) deprecated [put\_new(dict, key, val)](#put_new/3) deprecated [put\_new\_lazy(dict, key, fun)](#put_new_lazy/3) deprecated [size(dict)](#size/1) deprecated [split(dict, keys)](#split/2) deprecated [take(dict, keys)](#take/2) deprecated [to\_list(dict)](#to_list/1) deprecated [update(dict, key, initial, fun)](#update/4) deprecated [update!(dict, key, fun)](#update!/3) deprecated [values(dict)](#values/1) deprecated Types ====== ### key() #### Specs ``` key() :: any() ``` ### t() #### Specs ``` t() :: list() | map() ``` ### value() #### Specs ``` value() :: any() ``` Functions ========== ### delete(dict, key) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` delete(t(), key()) :: t() ``` ### drop(dict, keys) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` drop(t(), [key()]) :: t() ``` ### empty(dict) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` empty(t()) :: t() ``` ### equal?(dict1, dict2) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` equal?(t(), t()) :: boolean() ``` ### fetch(dict, key) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` fetch(t(), key()) :: value() ``` ### fetch!(dict, key) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` fetch!(t(), key()) :: value() ``` ### get(dict, key, default \\ nil) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` get(t(), key(), value()) :: value() ``` ### get\_and\_update(dict, key, fun) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` get_and_update(t(), key(), (value() -> {value(), value()})) :: {value(), t()} ``` ### get\_lazy(dict, key, fun) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` get_lazy(t(), key(), (() -> value())) :: value() ``` ### has\_key?(dict, key) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` has_key?(t(), key()) :: boolean() ``` ### keys(dict) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` keys(t()) :: [key()] ``` ### merge(dict1, dict2) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` merge(t(), t()) :: t() ``` ### merge(dict1, dict2, fun) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` merge(t(), t(), (key(), value(), value() -> value())) :: t() ``` ### pop(dict, key, default \\ nil) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` pop(t(), key(), value()) :: {value(), t()} ``` ### pop\_lazy(dict, key, fun) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` pop_lazy(t(), key(), (() -> value())) :: {value(), t()} ``` ### put(dict, key, val) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` put(t(), key(), value()) :: t() ``` ### put\_new(dict, key, val) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` put_new(t(), key(), value()) :: t() ``` ### put\_new\_lazy(dict, key, fun) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` put_new_lazy(t(), key(), (() -> value())) :: t() ``` ### size(dict) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` size(t()) :: non_neg_integer() ``` ### split(dict, keys) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` split(t(), [key()]) :: {t(), t()} ``` ### take(dict, keys) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` take(t(), [key()]) :: t() ``` ### to\_list(dict) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` to_list(t()) :: list() ``` ### update(dict, key, initial, fun) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` update(t(), key(), value(), (value() -> value())) :: t() ``` ### update!(dict, key, fun) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` update!(t(), key(), (value() -> value())) :: t() ``` ### values(dict) This function is deprecated. Use the Map module for working with maps or the Keyword module for working with keyword lists. #### Specs ``` values(t()) :: [value()] ``` elixir Registry Registry ========= A local, decentralized and scalable key-value process storage. It allows developers to lookup one or more processes with a given key. If the registry has `:unique` keys, a key points to 0 or 1 processes. If the registry allows `:duplicate` keys, a single key may point to any number of processes. In both cases, different keys could identify the same process. Each entry in the registry is associated to the process that has registered the key. If the process crashes, the keys associated to that process are automatically removed. All key comparisons in the registry are done using the match operation ([`===/2`](kernel#===/2)). The registry can be used for different purposes, such as name lookups (using the `:via` option), storing properties, custom dispatching rules, or a pubsub implementation. We explore some of those use cases below. The registry may also be transparently partitioned, which provides more scalable behaviour for running registries on highly concurrent environments with thousands or millions of entries. Using in `:via` ---------------- Once the registry is started with a given name using [`Registry.start_link/1`](registry#start_link/1), it can be used to register and access named processes using the `{:via, Registry, {registry, key}}` tuple: ``` {:ok, _} = Registry.start_link(keys: :unique, name: Registry.ViaTest) name = {:via, Registry, {Registry.ViaTest, "agent"}} {:ok, _} = Agent.start_link(fn -> 0 end, name: name) Agent.get(name, & &1) #=> 0 Agent.update(name, &(&1 + 1)) Agent.get(name, & &1) #=> 1 ``` In the previous example, we were not interested in associating a value to the process: ``` Registry.lookup(Registry.ViaTest, "agent") #=> [{self(), nil}] ``` However, in some cases it may be desired to associate a value to the process using the alternate `{:via, Registry, {registry, key, value}}` tuple: ``` {:ok, _} = Registry.start_link(keys: :unique, name: Registry.ViaTest) name = {:via, Registry, {Registry.ViaTest, "agent", :hello}} {:ok, _} = Agent.start_link(fn -> 0 end, name: name) Registry.lookup(Registry.ViaTest, "agent") #=> [{self(), :hello}] ``` To this point, we have been starting [`Registry`](#content) using [`start_link/1`](#start_link/1). Typically the registry is started as part of a supervision tree though: ``` {Registry, keys: :unique, name: Registry.ViaTest} ``` Only registries with unique keys can be used in `:via`. If the name is already taken, the case-specific `start_link` function ([`Agent.start_link/2`](agent#start_link/2) in the example above) will return `{:error, {:already_started, current_pid}}`. Using as a dispatcher ---------------------- [`Registry`](#content) has a dispatch mechanism that allows developers to implement custom dispatch logic triggered from the caller. For example, let's say we have a duplicate registry started as so: ``` {:ok, _} = Registry.start_link(keys: :duplicate, name: Registry.DispatcherTest) ``` By calling [`register/3`](#register/3), different processes can register under a given key and associate any value under that key. In this case, let's register the current process under the key `"hello"` and attach the `{IO, :inspect}` tuple to it: ``` {:ok, _} = Registry.register(Registry.DispatcherTest, "hello", {IO, :inspect}) ``` Now, an entity interested in dispatching events for a given key may call [`dispatch/3`](#dispatch/3) passing in the key and a callback. This callback will be invoked with a list of all the values registered under the requested key, alongside the PID of the process that registered each value, in the form of `{pid, value}` tuples. In our example, `value` will be the `{module, function}` tuple in the code above: ``` Registry.dispatch(Registry.DispatcherTest, "hello", fn entries -> for {pid, {module, function}} <- entries, do: apply(module, function, [pid]) end) # Prints #PID<...> where the PID is for the process that called register/3 above #=> :ok ``` Dispatching happens in the process that calls [`dispatch/3`](#dispatch/3) either serially or concurrently in case of multiple partitions (via spawned tasks). The registered processes are not involved in dispatching unless involving them is done explicitly (for example, by sending them a message in the callback). Furthermore, if there is a failure when dispatching, due to a bad registration, dispatching will always fail and the registered process will not be notified. Therefore let's make sure we at least wrap and report those errors: ``` require Logger Registry.dispatch(Registry.DispatcherTest, "hello", fn entries -> for {pid, {module, function}} <- entries do try do apply(module, function, [pid]) catch kind, reason -> formatted = Exception.format(kind, reason, __STACKTRACE__) Logger.error("Registry.dispatch/3 failed with #{formatted}") end end end) # Prints #PID<...> #=> :ok ``` You could also replace the whole `apply` system by explicitly sending messages. That's the example we will see next. Using as a PubSub ------------------ Registries can also be used to implement a local, non-distributed, scalable PubSub by relying on the [`dispatch/3`](#dispatch/3) function, similarly to the previous section: in this case, however, we will send messages to each associated process, instead of invoking a given module-function. In this example, we will also set the number of partitions to the number of schedulers online, which will make the registry more performant on highly concurrent environments: ``` {:ok, _} = Registry.start_link( keys: :duplicate, name: Registry.PubSubTest, partitions: System.schedulers_online() ) {:ok, _} = Registry.register(Registry.PubSubTest, "hello", []) Registry.dispatch(Registry.PubSubTest, "hello", fn entries -> for {pid, _} <- entries, do: send(pid, {:broadcast, "world"}) end) #=> :ok ``` The example above broadcasted the message `{:broadcast, "world"}` to all processes registered under the "topic" (or "key" as we called it until now) `"hello"`. The third argument given to [`register/3`](#register/3) is a value associated to the current process. While in the previous section we used it when dispatching, in this particular example we are not interested in it, so we have set it to an empty list. You could store a more meaningful value if necessary. Registrations -------------- Looking up, dispatching and registering are efficient and immediate at the cost of delayed unsubscription. For example, if a process crashes, its keys are automatically removed from the registry but the change may not propagate immediately. This means certain operations may return processes that are already dead. When such may happen, it will be explicitly stated in the function documentation. However, keep in mind those cases are typically not an issue. After all, a process referenced by a PID may crash at any time, including between getting the value from the registry and sending it a message. Many parts of the standard library are designed to cope with that, such as [`Process.monitor/1`](process#monitor/1) which will deliver the `:DOWN` message immediately if the monitored process is already dead and [`Kernel.send/2`](kernel#send/2) which acts as a no-op for dead processes. ETS ---- Note that the registry uses one ETS table plus two ETS tables per partition. Summary ======== Types ------ [body()](#t:body/0) A pattern used to representing the output format part of a match spec [guard()](#t:guard/0) A guard to be evaluated when matching on objects in a registry [guards()](#t:guards/0) A list of guards to be evaluated when matching on objects in a registry [key()](#t:key/0) The type of keys allowed on registration [keys()](#t:keys/0) The type of the registry [match\_pattern()](#t:match_pattern/0) A pattern to match on objects in a registry [meta\_key()](#t:meta_key/0) The type of registry metadata keys [meta\_value()](#t:meta_value/0) The type of registry metadata values [registry()](#t:registry/0) The registry identifier [spec()](#t:spec/0) A full match spec used when selecting objects in the registry [value()](#t:value/0) The type of values allowed on registration Functions ---------- [child\_spec(opts)](#child_spec/1) Returns a specification to start a registry under a supervisor. [count(registry)](#count/1) Returns the number of registered keys in a registry. It runs in constant time. [count\_match(registry, key, pattern, guards \\ [])](#count_match/4) Returns the number of `{pid, value}` pairs under the given `key` in `registry` that match `pattern`. [dispatch(registry, key, mfa\_or\_fun, opts \\ [])](#dispatch/4) Invokes the callback with all entries under `key` in each partition for the given `registry`. [keys(registry, pid)](#keys/2) Returns the known keys for the given `pid` in `registry` in no particular order. [lookup(registry, key)](#lookup/2) Finds the `{pid, value}` pair for the given `key` in `registry` in no particular order. [match(registry, key, pattern, guards \\ [])](#match/4) Returns `{pid, value}` pairs under the given `key` in `registry` that match `pattern`. [meta(registry, key)](#meta/2) Reads registry metadata given on [`start_link/1`](#start_link/1). [put\_meta(registry, key, value)](#put_meta/3) Stores registry metadata. [register(registry, key, value)](#register/3) Registers the current process under the given `key` in `registry`. [select(registry, spec)](#select/2) Select key, pid, and values registered using full match specs. [start\_link(options)](#start_link/1) Starts the registry as a supervisor process. [unregister(registry, key)](#unregister/2) Unregisters all entries for the given `key` associated to the current process in `registry`. [unregister\_match(registry, key, pattern, guards \\ [])](#unregister_match/4) Unregister entries for a given key matching a pattern. [update\_value(registry, key, callback)](#update_value/3) Updates the value for `key` for the current process in the unique `registry`. Types ====== ### body() #### Specs ``` body() :: [atom() | tuple()] ``` A pattern used to representing the output format part of a match spec ### guard() #### Specs ``` guard() :: {atom() | term()} ``` A guard to be evaluated when matching on objects in a registry ### guards() #### Specs ``` guards() :: [guard()] | [] ``` A list of guards to be evaluated when matching on objects in a registry ### key() #### Specs ``` key() :: term() ``` The type of keys allowed on registration ### keys() #### Specs ``` keys() :: :unique | :duplicate ``` The type of the registry ### match\_pattern() #### Specs ``` match_pattern() :: atom() | term() ``` A pattern to match on objects in a registry ### meta\_key() #### Specs ``` meta_key() :: atom() | tuple() ``` The type of registry metadata keys ### meta\_value() #### Specs ``` meta_value() :: term() ``` The type of registry metadata values ### registry() #### Specs ``` registry() :: atom() ``` The registry identifier ### spec() #### Specs ``` spec() :: [{match_pattern(), guards(), body()}] ``` A full match spec used when selecting objects in the registry ### value() #### Specs ``` value() :: term() ``` The type of values allowed on registration Functions ========== ### child\_spec(opts) Returns a specification to start a registry under a supervisor. See [`Supervisor`](supervisor). ### count(registry) #### Specs ``` count(registry()) :: non_neg_integer() ``` Returns the number of registered keys in a registry. It runs in constant time. #### Examples In the example below we register the current process and ask for the number of keys in the registry: ``` iex> Registry.start_link(keys: :unique, name: Registry.UniqueCountTest) iex> Registry.count(Registry.UniqueCountTest) 0 iex> {:ok, _} = Registry.register(Registry.UniqueCountTest, "hello", :world) iex> {:ok, _} = Registry.register(Registry.UniqueCountTest, "world", :world) iex> Registry.count(Registry.UniqueCountTest) 2 ``` The same applies to duplicate registries: ``` iex> Registry.start_link(keys: :duplicate, name: Registry.DuplicateCountTest) iex> Registry.count(Registry.DuplicateCountTest) 0 iex> {:ok, _} = Registry.register(Registry.DuplicateCountTest, "hello", :world) iex> {:ok, _} = Registry.register(Registry.DuplicateCountTest, "hello", :world) iex> Registry.count(Registry.DuplicateCountTest) 2 ``` ### count\_match(registry, key, pattern, guards \\ []) #### Specs ``` count_match(registry(), key(), match_pattern(), guards()) :: non_neg_integer() ``` Returns the number of `{pid, value}` pairs under the given `key` in `registry` that match `pattern`. Pattern must be an atom or a tuple that will match the structure of the value stored in the registry. The atom `:_` can be used to ignore a given value or tuple element, while the atom `:"$1"` can be used to temporarily assign part of pattern to a variable for a subsequent comparison. Optionally, it is possible to pass a list of guard conditions for more precise matching. Each guard is a tuple, which describes checks that should be passed by assigned part of pattern. For example the `$1 > 1` guard condition would be expressed as the `{:>, :"$1", 1}` tuple. Please note that guard conditions will work only for assigned variables like `:"$1"`, `:"$2"`, etc. Avoid usage of special match variables `:"$_"` and `:"$$"`, because it might not work as expected. Zero will be returned if there is no match. For unique registries, a single partition lookup is necessary. For duplicate registries, all partitions must be looked up. #### Examples In the example below we register the current process under the same key in a duplicate registry but with different values: ``` iex> Registry.start_link(keys: :duplicate, name: Registry.CountMatchTest) iex> {:ok, _} = Registry.register(Registry.CountMatchTest, "hello", {1, :atom, 1}) iex> {:ok, _} = Registry.register(Registry.CountMatchTest, "hello", {2, :atom, 2}) iex> Registry.count_match(Registry.CountMatchTest, "hello", {1, :_, :_}) 1 iex> Registry.count_match(Registry.CountMatchTest, "hello", {2, :_, :_}) 1 iex> Registry.count_match(Registry.CountMatchTest, "hello", {:_, :atom, :_}) 2 iex> Registry.count_match(Registry.CountMatchTest, "hello", {:"$1", :_, :"$1"}) 2 iex> Registry.count_match(Registry.CountMatchTest, "hello", {:_, :_, :"$1"}, [{:>, :"$1", 1}]) 1 iex> Registry.count_match(Registry.CountMatchTest, "hello", {:_, :"$1", :_}, [{:is_atom, :"$1"}]) 2 ``` ### dispatch(registry, key, mfa\_or\_fun, opts \\ []) #### Specs ``` dispatch(registry(), key(), dispatcher, keyword()) :: :ok when dispatcher: (entries :: [{pid(), value()}] -> term()) | {module(), atom(), [any()]} ``` Invokes the callback with all entries under `key` in each partition for the given `registry`. The list of `entries` is a non-empty list of two-element tuples where the first element is the PID and the second element is the value associated to the PID. If there are no entries for the given key, the callback is never invoked. If the registry is partitioned, the callback is invoked multiple times per partition. If the registry is partitioned and `parallel: true` is given as an option, the dispatching happens in parallel. In both cases, the callback is only invoked if there are entries for that partition. See the module documentation for examples of using the [`dispatch/3`](#dispatch/3) function for building custom dispatching or a pubsub system. ### keys(registry, pid) #### Specs ``` keys(registry(), pid()) :: [key()] ``` Returns the known keys for the given `pid` in `registry` in no particular order. If the registry is unique, the keys are unique. Otherwise they may contain duplicates if the process was registered under the same key multiple times. The list will be empty if the process is dead or it has no keys in this registry. #### Examples Registering under a unique registry does not allow multiple entries: ``` iex> Registry.start_link(keys: :unique, name: Registry.UniqueKeysTest) iex> Registry.keys(Registry.UniqueKeysTest, self()) [] iex> {:ok, _} = Registry.register(Registry.UniqueKeysTest, "hello", :world) iex> Registry.register(Registry.UniqueKeysTest, "hello", :later) # registry is :unique {:error, {:already_registered, self()}} iex> Registry.keys(Registry.UniqueKeysTest, self()) ["hello"] ``` Such is possible for duplicate registries though: ``` iex> Registry.start_link(keys: :duplicate, name: Registry.DuplicateKeysTest) iex> Registry.keys(Registry.DuplicateKeysTest, self()) [] iex> {:ok, _} = Registry.register(Registry.DuplicateKeysTest, "hello", :world) iex> {:ok, _} = Registry.register(Registry.DuplicateKeysTest, "hello", :world) iex> Registry.keys(Registry.DuplicateKeysTest, self()) ["hello", "hello"] ``` ### lookup(registry, key) #### Specs ``` lookup(registry(), key()) :: [{pid(), value()}] ``` Finds the `{pid, value}` pair for the given `key` in `registry` in no particular order. An empty list if there is no match. For unique registries, a single partition lookup is necessary. For duplicate registries, all partitions must be looked up. #### Examples In the example below we register the current process and look it up both from itself and other processes: ``` iex> Registry.start_link(keys: :unique, name: Registry.UniqueLookupTest) iex> Registry.lookup(Registry.UniqueLookupTest, "hello") [] iex> {:ok, _} = Registry.register(Registry.UniqueLookupTest, "hello", :world) iex> Registry.lookup(Registry.UniqueLookupTest, "hello") [{self(), :world}] iex> Task.async(fn -> Registry.lookup(Registry.UniqueLookupTest, "hello") end) |> Task.await() [{self(), :world}] ``` The same applies to duplicate registries: ``` iex> Registry.start_link(keys: :duplicate, name: Registry.DuplicateLookupTest) iex> Registry.lookup(Registry.DuplicateLookupTest, "hello") [] iex> {:ok, _} = Registry.register(Registry.DuplicateLookupTest, "hello", :world) iex> Registry.lookup(Registry.DuplicateLookupTest, "hello") [{self(), :world}] iex> {:ok, _} = Registry.register(Registry.DuplicateLookupTest, "hello", :another) iex> Enum.sort(Registry.lookup(Registry.DuplicateLookupTest, "hello")) [{self(), :another}, {self(), :world}] ``` ### match(registry, key, pattern, guards \\ []) #### Specs ``` match(registry(), key(), match_pattern(), guards()) :: [{pid(), term()}] ``` Returns `{pid, value}` pairs under the given `key` in `registry` that match `pattern`. Pattern must be an atom or a tuple that will match the structure of the value stored in the registry. The atom `:_` can be used to ignore a given value or tuple element, while the atom `:"$1"` can be used to temporarily assign part of pattern to a variable for a subsequent comparison. Optionally, it is possible to pass a list of guard conditions for more precise matching. Each guard is a tuple, which describes checks that should be passed by assigned part of pattern. For example the `$1 > 1` guard condition would be expressed as the `{:>, :"$1", 1}` tuple. Please note that guard conditions will work only for assigned variables like `:"$1"`, `:"$2"`, etc. Avoid usage of special match variables `:"$_"` and `:"$$"`, because it might not work as expected. An empty list will be returned if there is no match. For unique registries, a single partition lookup is necessary. For duplicate registries, all partitions must be looked up. #### Examples In the example below we register the current process under the same key in a duplicate registry but with different values: ``` iex> Registry.start_link(keys: :duplicate, name: Registry.MatchTest) iex> {:ok, _} = Registry.register(Registry.MatchTest, "hello", {1, :atom, 1}) iex> {:ok, _} = Registry.register(Registry.MatchTest, "hello", {2, :atom, 2}) iex> Registry.match(Registry.MatchTest, "hello", {1, :_, :_}) [{self(), {1, :atom, 1}}] iex> Registry.match(Registry.MatchTest, "hello", {2, :_, :_}) [{self(), {2, :atom, 2}}] iex> Registry.match(Registry.MatchTest, "hello", {:_, :atom, :_}) |> Enum.sort() [{self(), {1, :atom, 1}}, {self(), {2, :atom, 2}}] iex> Registry.match(Registry.MatchTest, "hello", {:"$1", :_, :"$1"}) |> Enum.sort() [{self(), {1, :atom, 1}}, {self(), {2, :atom, 2}}] iex> guards = [{:>, :"$1", 1}] iex> Registry.match(Registry.MatchTest, "hello", {:_, :_, :"$1"}, guards) [{self(), {2, :atom, 2}}] iex> guards = [{:is_atom, :"$1"}] iex> Registry.match(Registry.MatchTest, "hello", {:_, :"$1", :_}, guards) |> Enum.sort() [{self(), {1, :atom, 1}}, {self(), {2, :atom, 2}}] ``` ### meta(registry, key) #### Specs ``` meta(registry(), meta_key()) :: {:ok, meta_value()} | :error ``` Reads registry metadata given on [`start_link/1`](#start_link/1). Atoms and tuples are allowed as keys. #### Examples ``` iex> Registry.start_link(keys: :unique, name: Registry.MetaTest, meta: [custom_key: "custom_value"]) iex> Registry.meta(Registry.MetaTest, :custom_key) {:ok, "custom_value"} iex> Registry.meta(Registry.MetaTest, :unknown_key) :error ``` ### put\_meta(registry, key, value) #### Specs ``` put_meta(registry(), meta_key(), meta_value()) :: :ok ``` Stores registry metadata. Atoms and tuples are allowed as keys. #### Examples ``` iex> Registry.start_link(keys: :unique, name: Registry.PutMetaTest) iex> Registry.put_meta(Registry.PutMetaTest, :custom_key, "custom_value") :ok iex> Registry.meta(Registry.PutMetaTest, :custom_key) {:ok, "custom_value"} iex> Registry.put_meta(Registry.PutMetaTest, {:tuple, :key}, "tuple_value") :ok iex> Registry.meta(Registry.PutMetaTest, {:tuple, :key}) {:ok, "tuple_value"} ``` ### register(registry, key, value) #### Specs ``` register(registry(), key(), value()) :: {:ok, pid()} | {:error, {:already_registered, pid()}} ``` Registers the current process under the given `key` in `registry`. A value to be associated with this registration must also be given. This value will be retrieved whenever dispatching or doing a key lookup. This function returns `{:ok, owner}` or `{:error, reason}`. The `owner` is the PID in the registry partition responsible for the PID. The owner is automatically linked to the caller. If the registry has unique keys, it will return `{:ok, owner}` unless the key is already associated to a PID, in which case it returns `{:error, {:already_registered, pid}}`. If the registry has duplicate keys, multiple registrations from the current process under the same key are allowed. #### Examples Registering under a unique registry does not allow multiple entries: ``` iex> Registry.start_link(keys: :unique, name: Registry.UniqueRegisterTest) iex> {:ok, _} = Registry.register(Registry.UniqueRegisterTest, "hello", :world) iex> Registry.register(Registry.UniqueRegisterTest, "hello", :later) {:error, {:already_registered, self()}} iex> Registry.keys(Registry.UniqueRegisterTest, self()) ["hello"] ``` Such is possible for duplicate registries though: ``` iex> Registry.start_link(keys: :duplicate, name: Registry.DuplicateRegisterTest) iex> {:ok, _} = Registry.register(Registry.DuplicateRegisterTest, "hello", :world) iex> {:ok, _} = Registry.register(Registry.DuplicateRegisterTest, "hello", :world) iex> Registry.keys(Registry.DuplicateRegisterTest, self()) ["hello", "hello"] ``` ### select(registry, spec) #### Specs ``` select(registry(), spec()) :: [term()] ``` Select key, pid, and values registered using full match specs. The `spec` consists of a list of three part tuples, in the shape of `[{match_pattern, guards, body}]`. The first part, the match pattern, must be a tuple that will match the structure of the the data stored in the registry, which is `{key, pid, value}`. The atom `:_` can be used to ignore a given value or tuple element, while the atom `:"$1"` can be used to temporarily assign part of pattern to a variable for a subsequent comparison. This can be combined like `{:"$1", :_, :_}`. The second part, the guards, is a list of conditions that allow filtering the results. Each guard is a tuple, which describes checks that should be passed by assigned part of pattern. For example the `$1 > 1` guard condition would be expressed as the `{:>, :"$1", 1}` tuple. Please note that guard conditions will work only for assigned variables like `:"$1"`, `:"$2"`, etc. The third part, the body, is a list of shapes of the returned entries. Like guards, you have access to assigned variables like `:"$1"`, which you can combine with hardcoded values to freely shape entries Note that tuples have to be wrapped in an additional tuple. To get a result format like `%{key: key, pid: pid, value: value}`, assuming you bound those variables in order in the match part, you would provide a body like `[%{key: :"$1", pid: :"$2", value: :"$3"}]`. Like guards, you can use some operations like `:element` to modify the output format. Do not use special match variables `:"$_"` and `:"$$"`, because they might not work as expected. Note that for large registries with many partitions this will be costly as it builds the result by concatenating all the partitions. #### Examples This example shows how to get everything from the registry. ``` iex> Registry.start_link(keys: :unique, name: Registry.SelectAllTest) iex> {:ok, _} = Registry.register(Registry.SelectAllTest, "hello", :value) iex> {:ok, _} = Registry.register(Registry.SelectAllTest, "world", :value) iex> Registry.select(Registry.SelectAllTest, [{{:"$1", :"$2", :"$3"}, [], [{{:"$1", :"$2", :"$3"}}]}]) [{"world", self(), :value}, {"hello", self(), :value}] ``` Get all keys in the registry. ``` iex> Registry.start_link(keys: :unique, name: Registry.SelectAllTest) iex> {:ok, _} = Registry.register(Registry.SelectAllTest, "hello", :value) iex> {:ok, _} = Registry.register(Registry.SelectAllTest, "world", :value) iex> Registry.select(Registry.SelectAllTest, [{{:"$1", :_, :_}, [], [:"$1"]}]) ["world", "hello"] ``` ### start\_link(options) #### Specs ``` start_link( keys: keys(), name: registry(), partitions: pos_integer(), listeners: [atom()], meta: meta ) :: {:ok, pid()} | {:error, term()} when meta: [{meta_key(), meta_value()}] ``` Starts the registry as a supervisor process. Manually it can be started as: ``` Registry.start_link(keys: :unique, name: MyApp.Registry) ``` In your supervisor tree, you would write: ``` Supervisor.start_link([ {Registry, keys: :unique, name: MyApp.Registry} ], strategy: :one_for_one) ``` For intensive workloads, the registry may also be partitioned (by specifying the `:partitions` option). If partitioning is required then a good default is to set the number of partitions to the number of schedulers available: ``` Registry.start_link( keys: :unique, name: MyApp.Registry, partitions: System.schedulers_online() ) ``` or: ``` Supervisor.start_link([ {Registry, keys: :unique, name: MyApp.Registry, partitions: System.schedulers_online()} ], strategy: :one_for_one) ``` #### Options The registry requires the following keys: * `:keys` - choose if keys are `:unique` or `:duplicate` * `:name` - the name of the registry and its tables The following keys are optional: * `:partitions` - the number of partitions in the registry. Defaults to `1`. * `:listeners` - a list of named processes which are notified of `:register` and `:unregister` events. The registered process must be monitored by the listener if the listener wants to be notified if the registered process crashes. * `:meta` - a keyword list of metadata to be attached to the registry. ### unregister(registry, key) #### Specs ``` unregister(registry(), key()) :: :ok ``` Unregisters all entries for the given `key` associated to the current process in `registry`. Always returns `:ok` and automatically unlinks the current process from the owner if there are no more keys associated to the current process. See also [`register/3`](#register/3) to read more about the "owner". #### Examples For unique registries: ``` iex> Registry.start_link(keys: :unique, name: Registry.UniqueUnregisterTest) iex> Registry.register(Registry.UniqueUnregisterTest, "hello", :world) iex> Registry.keys(Registry.UniqueUnregisterTest, self()) ["hello"] iex> Registry.unregister(Registry.UniqueUnregisterTest, "hello") :ok iex> Registry.keys(Registry.UniqueUnregisterTest, self()) [] ``` For duplicate registries: ``` iex> Registry.start_link(keys: :duplicate, name: Registry.DuplicateUnregisterTest) iex> Registry.register(Registry.DuplicateUnregisterTest, "hello", :world) iex> Registry.register(Registry.DuplicateUnregisterTest, "hello", :world) iex> Registry.keys(Registry.DuplicateUnregisterTest, self()) ["hello", "hello"] iex> Registry.unregister(Registry.DuplicateUnregisterTest, "hello") :ok iex> Registry.keys(Registry.DuplicateUnregisterTest, self()) [] ``` ### unregister\_match(registry, key, pattern, guards \\ []) #### Specs ``` unregister_match(registry(), key(), match_pattern(), guards()) :: :ok ``` Unregister entries for a given key matching a pattern. #### Examples For unique registries it can be used to conditionally unregister a key on the basis of whether or not it matches a particular value. ``` iex> Registry.start_link(keys: :unique, name: Registry.UniqueUnregisterMatchTest) iex> Registry.register(Registry.UniqueUnregisterMatchTest, "hello", :world) iex> Registry.keys(Registry.UniqueUnregisterMatchTest, self()) ["hello"] iex> Registry.unregister_match(Registry.UniqueUnregisterMatchTest, "hello", :foo) :ok iex> Registry.keys(Registry.UniqueUnregisterMatchTest, self()) ["hello"] iex> Registry.unregister_match(Registry.UniqueUnregisterMatchTest, "hello", :world) :ok iex> Registry.keys(Registry.UniqueUnregisterMatchTest, self()) [] ``` For duplicate registries: ``` iex> Registry.start_link(keys: :duplicate, name: Registry.DuplicateUnregisterMatchTest) iex> Registry.register(Registry.DuplicateUnregisterMatchTest, "hello", :world_a) iex> Registry.register(Registry.DuplicateUnregisterMatchTest, "hello", :world_b) iex> Registry.register(Registry.DuplicateUnregisterMatchTest, "hello", :world_c) iex> Registry.keys(Registry.DuplicateUnregisterMatchTest, self()) ["hello", "hello", "hello"] iex> Registry.unregister_match(Registry.DuplicateUnregisterMatchTest, "hello", :world_a) :ok iex> Registry.keys(Registry.DuplicateUnregisterMatchTest, self()) ["hello", "hello"] iex> Registry.lookup(Registry.DuplicateUnregisterMatchTest, "hello") [{self(), :world_b}, {self(), :world_c}] ``` ### update\_value(registry, key, callback) #### Specs ``` update_value(registry(), key(), (value() -> value())) :: {new_value :: term(), old_value :: term()} | :error ``` Updates the value for `key` for the current process in the unique `registry`. Returns a `{new_value, old_value}` tuple or `:error` if there is no such key assigned to the current process. If a non-unique registry is given, an error is raised. #### Examples ``` iex> Registry.start_link(keys: :unique, name: Registry.UpdateTest) iex> {:ok, _} = Registry.register(Registry.UpdateTest, "hello", 1) iex> Registry.lookup(Registry.UpdateTest, "hello") [{self(), 1}] iex> Registry.update_value(Registry.UpdateTest, "hello", &(&1 + 1)) {2, 1} iex> Registry.lookup(Registry.UpdateTest, "hello") [{self(), 2}] ```
programming_docs
elixir Protocols Getting Started Protocols ========= Protocols are a mechanism to achieve polymorphism in Elixir when you want behavior to vary depending on the data type. We are already familiar with one way of solving this type of problem: via pattern matching and guard clauses. Consider a simple utility module that would tell us the type of input variable: ``` defmodule Utility do def type(value) when is_binary(value), do: "string" def type(value) when is_integer(value), do: "integer" # ... other implementations ... end ``` If the use of this module were confined to your own project, you would be able to keep defining new `type/1` functions for each new data type. However, this code could be problematic if it were shared as a dependency by multiple apps because there would be no easy way to extend its functionality. This is where protocols can help us: protocols allow us to extend the original behavior for as many data types as we need. That’s because **dispatching on a protocol is available to any data type that has implemented the protocol** and a protocol can be implemented by anyone, at any time. Here’s how we could write the same `Utility.type/1` functionality as a protocol: ``` defprotocol Utility do @spec type(t) :: String.t() def type(value) end defimpl Utility, for: BitString do def type(_value), do: "string" end defimpl Utility, for: Integer do def type(_value), do: "integer" end ``` We define the protocol using `defprotocol` - its functions and specs may look similar to interfaces or abstract base classes in other languages. We can add as many implementations as we like using `defimpl`. The output is exactly the same as if we had a single module with multiple functions: ``` iex> Utility.type("foo") "string" iex> Utility.type(123) "integer" ``` With protocols, however, we are no longer stuck having to continuously modify the same module to support more and more data types. For example, we could get the `defimpl` calls above and spread them over multiple files and Elixir will dispatch the execution to the appropriate implementation based on the data type. Functions defined in a protocol may have more than one input, but the **dispatching will always be based on the data type of the first input**. One of the most common protocols you may encounter is the [`String.Chars`](https://hexdocs.pm/elixir/String.Chars.html) protocol: implementing its `to_string/1` function for your custom structs will tell the Elixir kernel how to represent them as strings. We will explore all built-in protocols later. For now, let’s implement our own. Example ------- Now that you have seen an example of the type of problem protocols help solve and how they solve them, let’s look at a more in-depth example. In Elixir, we have two idioms for checking how many items there are in a data structure: `length` and `size`. `length` means the information must be computed. For example, `length(list)` needs to traverse the whole list to calculate its length. On the other hand, `tuple_size(tuple)` and `byte_size(binary)` do not depend on the tuple and binary size as the size information is pre-computed in the data structure. Even if we have type-specific functions for getting the size built into Elixir (such as `tuple_size/1`), we could implement a generic `Size` protocol that all data structures for which size is pre-computed would implement. The protocol definition would look like this: ``` defprotocol Size do @doc "Calculates the size (and not the length!) of a data structure" def size(data) end ``` The `Size` protocol expects a function called `size` that receives one argument (the data structure we want to know the size of) to be implemented. We can now implement this protocol for the data structures that would have a compliant implementation: ``` defimpl Size, for: BitString do def size(string), do: byte_size(string) end defimpl Size, for: Map do def size(map), do: map_size(map) end defimpl Size, for: Tuple do def size(tuple), do: tuple_size(tuple) end ``` We didn’t implement the `Size` protocol for lists as there is no “size” information pre-computed for lists, and the length of a list has to be computed (with `length/1`). Now with the protocol defined and implementations in hand, we can start using it: ``` iex> Size.size("foo") 3 iex> Size.size({:ok, "hello"}) 2 iex> Size.size(%{label: "some label"}) 1 ``` Passing a data type that doesn’t implement the protocol raises an error: ``` iex> Size.size([1, 2, 3]) ** (Protocol.UndefinedError) protocol Size not implemented for [1, 2, 3] ``` It’s possible to implement protocols for all Elixir data types: * `Atom` * `BitString` * `Float` * `Function` * `Integer` * `List` * `Map` * `PID` * `Port` * `Reference` * `Tuple` Protocols and structs --------------------- The power of Elixir’s extensibility comes when protocols and structs are used together. In the [previous chapter](structs), we have learned that although structs are maps, they do not share protocol implementations with maps. For example, [`MapSet`](https://hexdocs.pm/elixir/MapSet.html)s (sets based on maps) are implemented as structs. Let’s try to use the `Size` protocol with a `MapSet`: ``` iex> Size.size(%{}) 0 iex> set = %MapSet{} = MapSet.new #MapSet<[]> iex> Size.size(set) ** (Protocol.UndefinedError) protocol Size not implemented for #MapSet<[]> ``` Instead of sharing protocol implementation with maps, structs require their own protocol implementation. Since a `MapSet` has its size precomputed and accessible through `MapSet.size/1`, we can define a `Size` implementation for it: ``` defimpl Size, for: MapSet do def size(set), do: MapSet.size(set) end ``` If desired, you could come up with your own semantics for the size of your struct. Not only that, you could use structs to build more robust data types, like queues, and implement all relevant protocols, such as `Enumerable` and possibly `Size`, for this data type. ``` defmodule User do defstruct [:name, :age] end defimpl Size, for: User do def size(_user), do: 2 end ``` Implementing `Any` ------------------ Manually implementing protocols for all types can quickly become repetitive and tedious. In such cases, Elixir provides two options: we can explicitly derive the protocol implementation for our types or automatically implement the protocol for all types. In both cases, we need to implement the protocol for `Any`. ### Deriving Elixir allows us to derive a protocol implementation based on the `Any` implementation. Let’s first implement `Any` as follows: ``` defimpl Size, for: Any do def size(_), do: 0 end ``` The implementation above is arguably not a reasonable one. For example, it makes no sense to say that the size of a `PID` or an `Integer` is `0`. However, should we be fine with the implementation for `Any`, in order to use such implementation we would need to tell our struct to explicitly derive the `Size` protocol: ``` defmodule OtherUser do @derive [Size] defstruct [:name, :age] end ``` When deriving, Elixir will implement the `Size` protocol for `OtherUser` based on the implementation provided for `Any`. ### Fallback to `Any` Another alternative to `@derive` is to explicitly tell the protocol to fallback to `Any` when an implementation cannot be found. This can be achieved by setting `@fallback_to_any` to `true` in the protocol definition: ``` defprotocol Size do @fallback_to_any true def size(data) end ``` As we said in the previous section, the implementation of `Size` for `Any` is not one that can apply to any data type. That’s one of the reasons why `@fallback_to_any` is an opt-in behaviour. For the majority of protocols, raising an error when a protocol is not implemented is the proper behaviour. That said, assuming we have implemented `Any` as in the previous section: ``` defimpl Size, for: Any do def size(_), do: 0 end ``` Now all data types (including structs) that have not implemented the `Size` protocol will be considered to have a size of `0`. Which technique is best between deriving and falling back to any depends on the use case but, given Elixir developers prefer explicit over implicit, you may see many libraries pushing towards the `@derive` approach. Built-in protocols ------------------ Elixir ships with some built-in protocols. In previous chapters, we have discussed the `Enum` module which provides many functions that work with any data structure that implements the `Enumerable` protocol: ``` iex> Enum.map [1, 2, 3], fn(x) -> x * 2 end [2, 4, 6] iex> Enum.reduce 1..3, 0, fn(x, acc) -> x + acc end 6 ``` Another useful example is the `String.Chars` protocol, which specifies how to convert a data structure to its human representation as a string. It’s exposed via the `to_string` function: ``` iex> to_string :hello "hello" ``` Notice that string interpolation in Elixir calls the `to_string` function: ``` iex> "age: #{25}" "age: 25" ``` The snippet above only works because numbers implement the `String.Chars` protocol. Passing a tuple, for example, will lead to an error: ``` iex> tuple = {1, 2, 3} {1, 2, 3} iex> "tuple: #{tuple}" ** (Protocol.UndefinedError) protocol String.Chars not implemented for {1, 2, 3} ``` When there is a need to “print” a more complex data structure, one can use the `inspect` function, based on the `Inspect` protocol: ``` iex> "tuple: #{inspect tuple}" "tuple: {1, 2, 3}" ``` The `Inspect` protocol is the protocol used to transform any data structure into a readable textual representation. This is what tools like IEx use to print results: ``` iex> {1, 2, 3} {1, 2, 3} iex> %User{} %User{name: "john", age: 27} ``` Keep in mind that, by convention, whenever the inspected value starts with `#`, it is representing a data structure in non-valid Elixir syntax. This means the inspect protocol is not reversible as information may be lost along the way: ``` iex> inspect &(&1+2) "#Function<6.71889879/1 in :erl_eval.expr/5>" ``` There are other protocols in Elixir but this covers the most common ones. You can learn more about protocols and implementations in the [`Protocol`](https://hexdocs.pm/elixir/Protocol.html) module. elixir GenServer behaviour GenServer behaviour ==================== A behaviour module for implementing the server of a client-server relation. A GenServer is a process like any other Elixir process and it can be used to keep state, execute code asynchronously and so on. The advantage of using a generic server process (GenServer) implemented using this module is that it will have a standard set of interface functions and include functionality for tracing and error reporting. It will also fit into a supervision tree. Example -------- The GenServer behaviour abstracts the common client-server interaction. Developers are only required to implement the callbacks and functionality they are interested in. Let's start with a code example and then explore the available callbacks. Imagine we want a GenServer that works like a stack, allowing us to push and pop elements: ``` defmodule Stack do use GenServer # Callbacks @impl true def init(stack) do {:ok, stack} end @impl true def handle_call(:pop, _from, [head | tail]) do {:reply, head, tail} end @impl true def handle_cast({:push, element}, state) do {:noreply, [element | state]} end end # Start the server {:ok, pid} = GenServer.start_link(Stack, [:hello]) # This is the client GenServer.call(pid, :pop) #=> :hello GenServer.cast(pid, {:push, :world}) #=> :ok GenServer.call(pid, :pop) #=> :world ``` We start our `Stack` by calling [`start_link/2`](#start_link/2), passing the module with the server implementation and its initial argument (a list representing the stack containing the element `:hello`). We can primarily interact with the server by sending two types of messages. **call** messages expect a reply from the server (and are therefore synchronous) while **cast** messages do not. Every time you do a [`GenServer.call/3`](genserver#call/3), the client will send a message that must be handled by the [`handle_call/3`](#c:handle_call/3) callback in the GenServer. A [`cast/2`](#cast/2) message must be handled by [`handle_cast/2`](#c:handle_cast/2). There are 7 possible callbacks to be implemented when you use a [`GenServer`](#content). The only required callback is [`init/1`](#c:init/1). Client / Server APIs --------------------- Although in the example above we have used [`GenServer.start_link/3`](genserver#start_link/3) and friends to directly start and communicate with the server, most of the time we don't call the [`GenServer`](#content) functions directly. Instead, we wrap the calls in new functions representing the public API of the server. Here is a better implementation of our Stack module: ``` defmodule Stack do use GenServer # Client def start_link(default) when is_list(default) do GenServer.start_link(__MODULE__, default) end def push(pid, element) do GenServer.cast(pid, {:push, element}) end def pop(pid) do GenServer.call(pid, :pop) end # Server (callbacks) @impl true def init(stack) do {:ok, stack} end @impl true def handle_call(:pop, _from, [head | tail]) do {:reply, head, tail} end @impl true def handle_cast({:push, element}, state) do {:noreply, [element | state]} end end ``` In practice, it is common to have both server and client functions in the same module. If the server and/or client implementations are growing complex, you may want to have them in different modules. How to supervise ----------------- A [`GenServer`](#content) is most commonly started under a supervision tree. When we invoke `use GenServer`, it automatically defines a `child_spec/1` function that allows us to start the `Stack` directly under a supervisor. To start a default stack of `[:hello]` under a supervisor, one may do: ``` children = [ {Stack, [:hello]} ] Supervisor.start_link(children, strategy: :one_for_all) ``` Note you can also start it simply as `Stack`, which is the same as `{Stack, []}`: ``` children = [ Stack # The same as {Stack, []} ] Supervisor.start_link(children, strategy: :one_for_all) ``` In both cases, `Stack.start_link/1` is always invoked. `use GenServer` also accepts a list of options which configures the child specification and therefore how it runs under a supervisor. The generated `child_spec/1` can be customized with the following options: * `:id` - the child specification identifier, defaults to the current module * `:restart` - when the child should be restarted, defaults to `:permanent` * `:shutdown` - how to shut down the child, either immediately or by giving it time to shut down For example: ``` use GenServer, restart: :transient, shutdown: 10_000 ``` See the "Child specification" section in the [`Supervisor`](supervisor) module for more detailed information. The `@doc` annotation immediately preceding `use GenServer` will be attached to the generated `child_spec/1` function. Name registration ------------------ Both [`start_link/3`](#start_link/3) and [`start/3`](#start/3) support the [`GenServer`](#content) to register a name on start via the `:name` option. Registered names are also automatically cleaned up on termination. The supported values are: * an atom - the GenServer is registered locally with the given name using [`Process.register/2`](process#register/2). * `{:global, term}` - the GenServer is registered globally with the given term using the functions in the [`:global` module](http://www.erlang.org/doc/man/global.html). * `{:via, module, term}` - the GenServer is registered with the given mechanism and name. The `:via` option expects a module that exports `register_name/2`, `unregister_name/1`, `whereis_name/1` and [`send/2`](kernel#send/2). One such example is the [`:global` module](http://www.erlang.org/doc/man/global.html) which uses these functions for keeping the list of names of processes and their associated PIDs that are available globally for a network of Elixir nodes. Elixir also ships with a local, decentralized and scalable registry called [`Registry`](registry) for locally storing names that are generated dynamically. For example, we could start and register our `Stack` server locally as follows: ``` # Start the server and register it locally with name MyStack {:ok, _} = GenServer.start_link(Stack, [:hello], name: MyStack) # Now messages can be sent directly to MyStack GenServer.call(MyStack, :pop) #=> :hello ``` Once the server is started, the remaining functions in this module ([`call/3`](#call/3), [`cast/2`](#cast/2), and friends) will also accept an atom, or any `{:global, ...}` or `{:via, ...}` tuples. In general, the following formats are supported: * a PID * an atom if the server is locally registered * `{atom, node}` if the server is locally registered at another node * `{:global, term}` if the server is globally registered * `{:via, module, name}` if the server is registered through an alternative registry If there is an interest to register dynamic names locally, do not use atoms, as atoms are never garbage-collected and therefore dynamically generated atoms won't be garbage-collected. For such cases, you can set up your own local registry by using the [`Registry`](registry) module. Receiving "regular" messages ----------------------------- The goal of a [`GenServer`](#content) is to abstract the "receive" loop for developers, automatically handling system messages, supporting code change, synchronous calls and more. Therefore, you should never call your own "receive" inside the GenServer callbacks as doing so will cause the GenServer to misbehave. Besides the synchronous and asynchronous communication provided by [`call/3`](#call/3) and [`cast/2`](#cast/2), "regular" messages sent by functions such as [`Kernel.send/2`](kernel#send/2), [`Process.send_after/4`](process#send_after/4) and similar, can be handled inside the [`handle_info/2`](#c:handle_info/2) callback. [`handle_info/2`](#c:handle_info/2) can be used in many situations, such as handling monitor DOWN messages sent by [`Process.monitor/1`](process#monitor/1). Another use case for [`handle_info/2`](#c:handle_info/2) is to perform periodic work, with the help of [`Process.send_after/4`](process#send_after/4): ``` defmodule MyApp.Periodically do use GenServer def start_link(_) do GenServer.start_link(__MODULE__, %{}) end @impl true def init(state) do # Schedule work to be performed on start schedule_work() {:ok, state} end @impl true def handle_info(:work, state) do # Do the desired work here # ... # Reschedule once more schedule_work() {:noreply, state} end defp schedule_work do # In 2 hours Process.send_after(self(), :work, 2 * 60 * 60 * 1000) end end ``` Timeouts --------- The return value of [`init/1`](#c:init/1) or any of the `handle_*` callbacks may include a timeout value in milliseconds; if not, `:infinity` is assumed. The timeout can be used to detect a lull in incoming messages. If the process has no messages waiting when the timeout is set and the number of given milliseconds pass without any message arriving, then `handle_info/2` will be called with `:timeout` as the first argument. The timeout is cleared if any message is waiting or arrives before the given timeout. Because a message may arrive before the timeout is set, even a timeout of `0` milliseconds is not guaranteed to execute. To take another action immediately and unconditionally, use a `:continue` instruction. When (not) to use a GenServer ------------------------------ So far, we have learned that a [`GenServer`](#content) can be used as a supervised process that handles sync and async calls. It can also handle system messages, such as periodic messages and monitoring events. GenServer processes may also be named. A GenServer, or a process in general, must be used to model runtime characteristics of your system. A GenServer must never be used for code organization purposes. In Elixir, code organization is done by modules and functions, processes are not necessary. For example, imagine you are implementing a calculator and you decide to put all the calculator operations behind a GenServer: ``` def add(a, b) do GenServer.call(__MODULE__, {:add, a, b}) end def handle_call({:add, a, b}, _from, state) do {:reply, a + b, state} end def handle_call({:subtract, a, b}, _from, state) do {:reply, a - b, state} end ``` This is an anti-pattern not only because it convolutes the calculator logic but also because you put the calculator logic behind a single process that will potentially become a bottleneck in your system, especially as the number of calls grow. Instead just define the functions directly: ``` def add(a, b) do a + b end def subtract(a, b) do a - b end ``` If you don't need a process, then you don't need a process. Use processes only to model runtime properties, such as mutable state, concurrency and failures, never for code organization. Debugging with the :sys module ------------------------------- GenServers, as [special processes](http://erlang.org/doc/design_principles/spec_proc.html), can be debugged using the [`:sys` module](http://www.erlang.org/doc/man/sys.html). Through various hooks, this module allows developers to introspect the state of the process and trace system events that happen during its execution, such as received messages, sent replies and state changes. Let's explore the basic functions from the [`:sys` module](http://www.erlang.org/doc/man/sys.html) used for debugging: * [`:sys.get_state/2`](http://www.erlang.org/doc/man/sys.html#get_state-2) - allows retrieval of the state of the process. In the case of a GenServer process, it will be the callback module state, as passed into the callback functions as last argument. * [`:sys.get_status/2`](http://www.erlang.org/doc/man/sys.html#get_status-2) - allows retrieval of the status of the process. This status includes the process dictionary, if the process is running or is suspended, the parent PID, the debugger state, and the state of the behaviour module, which includes the callback module state (as returned by [`:sys.get_state/2`](http://www.erlang.org/doc/man/sys.html#get_state-2)). It's possible to change how this status is represented by defining the optional [`GenServer.format_status/2`](genserver#c:format_status/2) callback. * [`:sys.trace/3`](http://www.erlang.org/doc/man/sys.html#trace-3) - prints all the system events to `:stdio`. * [`:sys.statistics/3`](http://www.erlang.org/doc/man/sys.html#statistics-3) - manages collection of process statistics. * [`:sys.no_debug/2`](http://www.erlang.org/doc/man/sys.html#no_debug-2) - turns off all debug handlers for the given process. It is very important to switch off debugging once we're done. Excessive debug handlers or those that should be turned off, but weren't, can seriously damage the performance of the system. * [`:sys.suspend/2`](http://www.erlang.org/doc/man/sys.html#suspend-2) - allows to suspend a process so that it only replies to system messages but no other messages. A suspended process can be reactivated via [`:sys.resume/2`](http://www.erlang.org/doc/man/sys.html#resume-2). Let's see how we could use those functions for debugging the stack server we defined earlier. ``` iex> {:ok, pid} = Stack.start_link([]) iex> :sys.statistics(pid, true) # turn on collecting process statistics iex> :sys.trace(pid, true) # turn on event printing iex> Stack.push(pid, 1) *DBG* <0.122.0> got cast {push,1} *DBG* <0.122.0> new state [1] :ok iex> :sys.get_state(pid) [1] iex> Stack.pop(pid) *DBG* <0.122.0> got call pop from <0.80.0> *DBG* <0.122.0> sent 1 to <0.80.0>, new state [] 1 iex> :sys.statistics(pid, :get) {:ok, [ start_time: {{2016, 7, 16}, {12, 29, 41}}, current_time: {{2016, 7, 16}, {12, 29, 50}}, reductions: 117, messages_in: 2, messages_out: 0 ]} iex> :sys.no_debug(pid) # turn off all debug handlers :ok iex> :sys.get_status(pid) {:status, #PID<0.122.0>, {:module, :gen_server}, [ [ "$initial_call": {Stack, :init, 1}, # process dictionary "$ancestors": [#PID<0.80.0>, #PID<0.51.0>] ], :running, # :running | :suspended #PID<0.80.0>, # parent [], # debugger state [ header: 'Status for generic server <0.122.0>', # module status data: [ {'Status', :running}, {'Parent', #PID<0.80.0>}, {'Logged events', []} ], data: [{'State', [1]}] ] ]} ``` Learn more ----------- If you wish to find out more about GenServers, the Elixir Getting Started guide provides a tutorial-like introduction. The documentation and links in Erlang can also provide extra insight. * [GenServer - Elixir's Getting Started Guide](https://elixir-lang.org/getting-started/mix-otp/genserver.html) * [`:gen_server` module documentation](http://www.erlang.org/doc/man/gen_server.html) * [gen\_server Behaviour - OTP Design Principles](http://www.erlang.org/doc/design_principles/gen_server_concepts.html) * [Clients and Servers - Learn You Some Erlang for Great Good!](http://learnyousomeerlang.com/clients-and-servers) Summary ======== Types ------ [debug()](#t:debug/0) Debug options supported by the `start*` functions [from()](#t:from/0) Tuple describing the client of a call request. [name()](#t:name/0) The GenServer name [on\_start()](#t:on_start/0) Return values of `start*` functions [option()](#t:option/0) Option values used by the `start*` functions [options()](#t:options/0) Options used by the `start*` functions [server()](#t:server/0) The server reference. Functions ---------- [abcast(nodes \\ [node() | Node.list()], name, request)](#abcast/3) Casts all servers locally registered as `name` at the specified nodes. [call(server, request, timeout \\ 5000)](#call/3) Makes a synchronous call to the `server` and waits for its reply. [cast(server, request)](#cast/2) Sends an asynchronous request to the `server`. [multi\_call(nodes \\ [node() | Node.list()], name, request, timeout \\ :infinity)](#multi_call/4) Calls all servers locally registered as `name` at the specified `nodes`. [reply(client, reply)](#reply/2) Replies to a client. [start(module, init\_arg, options \\ [])](#start/3) Starts a [`GenServer`](#content) process without links (outside of a supervision tree). [start\_link(module, init\_arg, options \\ [])](#start_link/3) Starts a [`GenServer`](#content) process linked to the current process. [stop(server, reason \\ :normal, timeout \\ :infinity)](#stop/3) Synchronously stops the server with the given `reason`. [whereis(server)](#whereis/1) Returns the `pid` or `{name, node}` of a GenServer process, or `nil` if no process is associated with the given `server`. Callbacks ---------- [code\_change(old\_vsn, state, extra)](#c:code_change/3) Invoked to change the state of the [`GenServer`](#content) when a different version of a module is loaded (hot code swapping) and the state's term structure should be changed. [format\_status(reason, pdict\_and\_state)](#c:format_status/2) Invoked in some cases to retrieve a formatted version of the [`GenServer`](#content) status. [handle\_call(request, from, state)](#c:handle_call/3) Invoked to handle synchronous [`call/3`](#call/3) messages. [`call/3`](#call/3) will block until a reply is received (unless the call times out or nodes are disconnected). [handle\_cast(request, state)](#c:handle_cast/2) Invoked to handle asynchronous [`cast/2`](#cast/2) messages. [handle\_continue(continue, state)](#c:handle_continue/2) Invoked to handle `continue` instructions. [handle\_info(msg, state)](#c:handle_info/2) Invoked to handle all other messages. [init(init\_arg)](#c:init/1) Invoked when the server is started. [`start_link/3`](#start_link/3) or [`start/3`](#start/3) will block until it returns. [terminate(reason, state)](#c:terminate/2) Invoked when the server is about to exit. It should do any cleanup required. Types ====== ### debug() #### Specs ``` debug() :: [:trace | :log | :statistics | {:log_to_file, Path.t()}] ``` Debug options supported by the `start*` functions ### from() #### Specs ``` from() :: {pid(), tag :: term()} ``` Tuple describing the client of a call request. `pid` is the PID of the caller and `tag` is a unique term used to identify the call. ### name() #### Specs ``` name() :: atom() | {:global, term()} | {:via, module(), term()} ``` The GenServer name ### on\_start() #### Specs ``` on_start() :: {:ok, pid()} | :ignore | {:error, {:already_started, pid()} | term()} ``` Return values of `start*` functions ### option() #### Specs ``` option() :: {:debug, debug()} | {:name, name()} | {:timeout, timeout()} | {:spawn_opt, Process.spawn_opt()} | {:hibernate_after, timeout()} ``` Option values used by the `start*` functions ### options() #### Specs ``` options() :: [option()] ``` Options used by the `start*` functions ### server() #### Specs ``` server() :: pid() | name() | {atom(), node()} ``` The server reference. This is either a plain PID or a value representing a registered name. See the "Name registration" section of this document for more information. Functions ========== ### abcast(nodes \\ [node() | Node.list()], name, request) #### Specs ``` abcast([node()], name :: atom(), term()) :: :abcast ``` Casts all servers locally registered as `name` at the specified nodes. This function returns immediately and ignores nodes that do not exist, or where the server name does not exist. See [`multi_call/4`](#multi_call/4) for more information. ### call(server, request, timeout \\ 5000) #### Specs ``` call(server(), term(), timeout()) :: term() ``` Makes a synchronous call to the `server` and waits for its reply. The client sends the given `request` to the server and waits until a reply arrives or a timeout occurs. [`handle_call/3`](#c:handle_call/3) will be called on the server to handle the request. `server` can be any of the values described in the "Name registration" section of the documentation for this module. #### Timeouts `timeout` is an integer greater than zero which specifies how many milliseconds to wait for a reply, or the atom `:infinity` to wait indefinitely. The default value is `5000`. If no reply is received within the specified time, the function call fails and the caller exits. If the caller catches the failure and continues running, and the server is just late with the reply, it may arrive at any time later into the caller's message queue. The caller must in this case be prepared for this and discard any such garbage messages that are two-element tuples with a reference as the first element. ### cast(server, request) #### Specs ``` cast(server(), term()) :: :ok ``` Sends an asynchronous request to the `server`. This function always returns `:ok` regardless of whether the destination `server` (or node) exists. Therefore it is unknown whether the destination `server` successfully handled the message. [`handle_cast/2`](#c:handle_cast/2) will be called on the server to handle the request. In case the `server` is on a node which is not yet connected to the caller one, the semantics differ depending on the used Erlang/OTP version. `server` can be any of the values described in the "Name registration" section of the documentation for this module. Before Erlang/OTP 21, the call is going to block until a connection happens. This was done to guarantee ordering. Starting with Erlang/OTP 21, both Erlang and Elixir do not block the call. ### multi\_call(nodes \\ [node() | Node.list()], name, request, timeout \\ :infinity) #### Specs ``` multi_call([node()], name :: atom(), term(), timeout()) :: {replies :: [{node(), term()}], bad_nodes :: [node()]} ``` Calls all servers locally registered as `name` at the specified `nodes`. First, the `request` is sent to every node in `nodes`; then, the caller waits for the replies. This function returns a two-element tuple `{replies, bad_nodes}` where: * `replies` - is a list of `{node, reply}` tuples where `node` is the node that replied and `reply` is its reply * `bad_nodes` - is a list of nodes that either did not exist or where a server with the given `name` did not exist or did not reply `nodes` is a list of node names to which the request is sent. The default value is the list of all known nodes (including this node). To avoid that late answers (after the timeout) pollute the caller's message queue, a middleman process is used to do the actual calls. Late answers will then be discarded when they arrive to a terminated process. #### Examples Assuming the `Stack` GenServer mentioned in the docs for the [`GenServer`](#content) module is registered as `Stack` in the `:"foo@my-machine"` and `:"bar@my-machine"` nodes: ``` GenServer.multi_call(Stack, :pop) #=> {[{:"foo@my-machine", :hello}, {:"bar@my-machine", :world}], []} ``` ### reply(client, reply) #### Specs ``` reply(from(), term()) :: :ok ``` Replies to a client. This function can be used to explicitly send a reply to a client that called [`call/3`](#call/3) or [`multi_call/4`](#multi_call/4) when the reply cannot be specified in the return value of [`handle_call/3`](#c:handle_call/3). `client` must be the `from` argument (the second argument) accepted by [`handle_call/3`](#c:handle_call/3) callbacks. `reply` is an arbitrary term which will be given back to the client as the return value of the call. Note that [`reply/2`](#reply/2) can be called from any process, not just the GenServer that originally received the call (as long as that GenServer communicated the `from` argument somehow). This function always returns `:ok`. #### Examples ``` def handle_call(:reply_in_one_second, from, state) do Process.send_after(self(), {:reply, from}, 1_000) {:noreply, state} end def handle_info({:reply, from}, state) do GenServer.reply(from, :one_second_has_passed) {:noreply, state} end ``` ### start(module, init\_arg, options \\ []) #### Specs ``` start(module(), any(), options()) :: on_start() ``` Starts a [`GenServer`](#content) process without links (outside of a supervision tree). See [`start_link/3`](#start_link/3) for more information. ### start\_link(module, init\_arg, options \\ []) #### Specs ``` start_link(module(), any(), options()) :: on_start() ``` Starts a [`GenServer`](#content) process linked to the current process. This is often used to start the [`GenServer`](#content) as part of a supervision tree. Once the server is started, the [`init/1`](#c:init/1) function of the given `module` is called with `init_arg` as its argument to initialize the server. To ensure a synchronized start-up procedure, this function does not return until [`init/1`](#c:init/1) has returned. Note that a [`GenServer`](#content) started with [`start_link/3`](#start_link/3) is linked to the parent process and will exit in case of crashes from the parent. The GenServer will also exit due to the `:normal` reasons in case it is configured to trap exits in the [`init/1`](#c:init/1) callback. #### Options * `:name` - used for name registration as described in the "Name registration" section in the documentation for [`GenServer`](#content) * `:timeout` - if present, the server is allowed to spend the given number of milliseconds initializing or it will be terminated and the start function will return `{:error, :timeout}` * `:debug` - if present, the corresponding function in the [`:sys` module](http://www.erlang.org/doc/man/sys.html) is invoked * `:spawn_opt` - if present, its value is passed as options to the underlying process as in [`Process.spawn/4`](process#spawn/4) * `:hibernate_after` - if present, the GenServer process awaits any message for the given number of milliseconds and if no message is received, the process goes into hibernation automatically (by calling [`:proc_lib.hibernate/3`](http://www.erlang.org/doc/man/proc_lib.html#hibernate-3)). #### Return values If the server is successfully created and initialized, this function returns `{:ok, pid}`, where `pid` is the PID of the server. If a process with the specified server name already exists, this function returns `{:error, {:already_started, pid}}` with the PID of that process. If the [`init/1`](#c:init/1) callback fails with `reason`, this function returns `{:error, reason}`. Otherwise, if it returns `{:stop, reason}` or `:ignore`, the process is terminated and this function returns `{:error, reason}` or `:ignore`, respectively. ### stop(server, reason \\ :normal, timeout \\ :infinity) #### Specs ``` stop(server(), reason :: term(), timeout()) :: :ok ``` Synchronously stops the server with the given `reason`. The [`terminate/2`](#c:terminate/2) callback of the given `server` will be invoked before exiting. This function returns `:ok` if the server terminates with the given reason; if it terminates with another reason, the call exits. This function keeps OTP semantics regarding error reporting. If the reason is any other than `:normal`, `:shutdown` or `{:shutdown, _}`, an error report is logged. ### whereis(server) #### Specs ``` whereis(server()) :: pid() | {atom(), node()} | nil ``` Returns the `pid` or `{name, node}` of a GenServer process, or `nil` if no process is associated with the given `server`. #### Examples For example, to lookup a server process, monitor it and send a cast to it: ``` process = GenServer.whereis(server) monitor = Process.monitor(process) GenServer.cast(process, :hello) ``` Callbacks ========== ### code\_change(old\_vsn, state, extra) #### Specs ``` code_change(old_vsn, state :: term(), extra :: term()) :: {:ok, new_state :: term()} | {:error, reason :: term()} when old_vsn: term() | {:down, term()} ``` Invoked to change the state of the [`GenServer`](#content) when a different version of a module is loaded (hot code swapping) and the state's term structure should be changed. `old_vsn` is the previous version of the module (defined by the `@vsn` attribute) when upgrading. When downgrading the previous version is wrapped in a 2-tuple with first element `:down`. `state` is the current state of the [`GenServer`](#content) and `extra` is any extra data required to change the state. Returning `{:ok, new_state}` changes the state to `new_state` and the code change is successful. Returning `{:error, reason}` fails the code change with reason `reason` and the state remains as the previous state. If [`code_change/3`](#c:code_change/3) raises the code change fails and the loop will continue with its previous state. Therefore this callback does not usually contain side effects. This callback is optional. ### format\_status(reason, pdict\_and\_state) #### Specs ``` format_status(reason, pdict_and_state :: list()) :: term() when reason: :normal | :terminate ``` Invoked in some cases to retrieve a formatted version of the [`GenServer`](#content) status. This callback can be useful to control the *appearance* of the status of the [`GenServer`](#content). For example, it can be used to return a compact representation of the [`GenServer`](#content)'s state to avoid having large state terms printed. * one of [`:sys.get_status/1`](http://www.erlang.org/doc/man/sys.html#get_status-1) or [`:sys.get_status/2`](http://www.erlang.org/doc/man/sys.html#get_status-2) is invoked to get the status of the [`GenServer`](#content); in such cases, `reason` is `:normal` * the [`GenServer`](#content) terminates abnormally and logs an error; in such cases, `reason` is `:terminate` `pdict_and_state` is a two-elements list `[pdict, state]` where `pdict` is a list of `{key, value}` tuples representing the current process dictionary of the [`GenServer`](#content) and `state` is the current state of the [`GenServer`](#content). ### handle\_call(request, from, state) #### Specs ``` handle_call(request :: term(), from(), state :: term()) :: {:reply, reply, new_state} | {:reply, reply, new_state, timeout() | :hibernate | {:continue, term()}} | {:noreply, new_state} | {:noreply, new_state, timeout() | :hibernate | {:continue, term()}} | {:stop, reason, reply, new_state} | {:stop, reason, new_state} when reply: term(), new_state: term(), reason: term() ``` Invoked to handle synchronous [`call/3`](#call/3) messages. [`call/3`](#call/3) will block until a reply is received (unless the call times out or nodes are disconnected). `request` is the request message sent by a [`call/3`](#call/3), `from` is a 2-tuple containing the caller's PID and a term that uniquely identifies the call, and `state` is the current state of the [`GenServer`](#content). Returning `{:reply, reply, new_state}` sends the response `reply` to the caller and continues the loop with new state `new_state`. Returning `{:reply, reply, new_state, timeout}` is similar to `{:reply, reply, new_state}` except that it also sets a timeout. See the "Timeouts" section in the module documentation for more information. Returning `{:reply, reply, new_state, :hibernate}` is similar to `{:reply, reply, new_state}` except the process is hibernated and will continue the loop once a message is in its message queue. If a message is already in the message queue this will be immediately. Hibernating a [`GenServer`](#content) causes garbage collection and leaves a continuous heap that minimises the memory used by the process. Returning `{:reply, reply, new_state, {:continue, continue}}` is similar to `{:reply, reply, new_state}` except [`handle_continue/2`](#c:handle_continue/2) will be invoked immediately after with the value `continue` as first argument. Hibernating should not be used aggressively as too much time could be spent garbage collecting. Normally it should only be used when a message is not expected soon and minimising the memory of the process is shown to be beneficial. Returning `{:noreply, new_state}` does not send a response to the caller and continues the loop with new state `new_state`. The response must be sent with [`reply/2`](#reply/2). There are three main use cases for not replying using the return value: * To reply before returning from the callback because the response is known before calling a slow function. * To reply after returning from the callback because the response is not yet available. * To reply from another process, such as a task. When replying from another process the [`GenServer`](#content) should exit if the other process exits without replying as the caller will be blocking awaiting a reply. Returning `{:noreply, new_state, timeout | :hibernate | {:continue, continue}}` is similar to `{:noreply, new_state}` except a timeout, hibernation or continue occurs as with a `:reply` tuple. Returning `{:stop, reason, reply, new_state}` stops the loop and [`terminate/2`](#c:terminate/2) is called with reason `reason` and state `new_state`. Then the `reply` is sent as the response to call and the process exits with reason `reason`. Returning `{:stop, reason, new_state}` is similar to `{:stop, reason, reply, new_state}` except a reply is not sent. This callback is optional. If one is not implemented, the server will fail if a call is performed against it. ### handle\_cast(request, state) #### Specs ``` handle_cast(request :: term(), state :: term()) :: {:noreply, new_state} | {:noreply, new_state, timeout() | :hibernate | {:continue, term()}} | {:stop, reason :: term(), new_state} when new_state: term() ``` Invoked to handle asynchronous [`cast/2`](#cast/2) messages. `request` is the request message sent by a [`cast/2`](#cast/2) and `state` is the current state of the [`GenServer`](#content). Returning `{:noreply, new_state}` continues the loop with new state `new_state`. Returning `{:noreply, new_state, timeout}` is similar to `{:noreply, new_state}` except that it also sets a timeout. See the "Timeouts" section in the module documentation for more information. Returning `{:noreply, new_state, :hibernate}` is similar to `{:noreply, new_state}` except the process is hibernated before continuing the loop. See [`handle_call/3`](#c:handle_call/3) for more information. Returning `{:noreply, new_state, {:continue, continue}}` is similar to `{:noreply, new_state}` except [`handle_continue/2`](#c:handle_continue/2) will be invoked immediately after with the value `continue` as first argument. Returning `{:stop, reason, new_state}` stops the loop and [`terminate/2`](#c:terminate/2) is called with the reason `reason` and state `new_state`. The process exits with reason `reason`. This callback is optional. If one is not implemented, the server will fail if a cast is performed against it. ### handle\_continue(continue, state) #### Specs ``` handle_continue(continue :: term(), state :: term()) :: {:noreply, new_state} | {:noreply, new_state, timeout() | :hibernate | {:continue, term()}} | {:stop, reason :: term(), new_state} when new_state: term() ``` Invoked to handle `continue` instructions. It is useful for performing work after initialization or for splitting the work in a callback in multiple steps, updating the process state along the way. Return values are the same as [`handle_cast/2`](#c:handle_cast/2). This callback is optional. If one is not implemented, the server will fail if a continue instruction is used. This callback is only supported on Erlang/OTP 21+. ### handle\_info(msg, state) #### Specs ``` handle_info(msg :: :timeout | term(), state :: term()) :: {:noreply, new_state} | {:noreply, new_state, timeout() | :hibernate | {:continue, term()}} | {:stop, reason :: term(), new_state} when new_state: term() ``` Invoked to handle all other messages. `msg` is the message and `state` is the current state of the [`GenServer`](#content). When a timeout occurs the message is `:timeout`. Return values are the same as [`handle_cast/2`](#c:handle_cast/2). This callback is optional. If one is not implemented, the received message will be logged. ### init(init\_arg) #### Specs ``` init(init_arg :: term()) :: {:ok, state} | {:ok, state, timeout() | :hibernate | {:continue, term()}} | :ignore | {:stop, reason :: any()} when state: any() ``` Invoked when the server is started. [`start_link/3`](#start_link/3) or [`start/3`](#start/3) will block until it returns. `init_arg` is the argument term (second argument) passed to [`start_link/3`](#start_link/3). Returning `{:ok, state}` will cause [`start_link/3`](#start_link/3) to return `{:ok, pid}` and the process to enter its loop. Returning `{:ok, state, timeout}` is similar to `{:ok, state}`, except that it also sets a timeout. See the "Timeouts" section in the module documentation for more information. Returning `{:ok, state, :hibernate}` is similar to `{:ok, state}` except the process is hibernated before entering the loop. See [`handle_call/3`](#c:handle_call/3) for more information on hibernation. Returning `{:ok, state, {:continue, continue}}` is similar to `{:ok, state}` except that immediately after entering the loop the [`handle_continue/2`](#c:handle_continue/2) callback will be invoked with the value `continue` as first argument. Returning `:ignore` will cause [`start_link/3`](#start_link/3) to return `:ignore` and the process will exit normally without entering the loop or calling [`terminate/2`](#c:terminate/2). If used when part of a supervision tree the parent supervisor will not fail to start nor immediately try to restart the [`GenServer`](#content). The remainder of the supervision tree will be started and so the [`GenServer`](#content) should not be required by other processes. It can be started later with [`Supervisor.restart_child/2`](supervisor#restart_child/2) as the child specification is saved in the parent supervisor. The main use cases for this are: * The [`GenServer`](#content) is disabled by configuration but might be enabled later. * An error occurred and it will be handled by a different mechanism than the [`Supervisor`](supervisor). Likely this approach involves calling [`Supervisor.restart_child/2`](supervisor#restart_child/2) after a delay to attempt a restart. Returning `{:stop, reason}` will cause [`start_link/3`](#start_link/3) to return `{:error, reason}` and the process to exit with reason `reason` without entering the loop or calling [`terminate/2`](#c:terminate/2). ### terminate(reason, state) #### Specs ``` terminate(reason, state :: term()) :: term() when reason: :normal | :shutdown | {:shutdown, term()} ``` Invoked when the server is about to exit. It should do any cleanup required. `reason` is exit reason and `state` is the current state of the [`GenServer`](#content). The return value is ignored. [`terminate/2`](#c:terminate/2) is called if a callback (except [`init/1`](#c:init/1)) does one of the following: * returns a `:stop` tuple * raises * calls [`Kernel.exit/1`](kernel#exit/1) * returns an invalid value * the [`GenServer`](#content) traps exits (using [`Process.flag/2`](process#flag/2)) *and* the parent process sends an exit signal If part of a supervision tree, a [`GenServer`](#content) will receive an exit signal when the tree is shutting down. The exit signal is based on the shutdown strategy in the child's specification, where this value can be: * `:brutal_kill`: the [`GenServer`](#content) is killed and so [`terminate/2`](#c:terminate/2) is not called. * a timeout value, where the supervisor will send the exit signal `:shutdown` and the [`GenServer`](#content) will have the duration of the timeout to terminate. If after duration of this timeout the process is still alive, it will be killed immediately. For a more in-depth explanation, please read the "Shutdown values (:shutdown)" section in the [`Supervisor`](supervisor) module. If the [`GenServer`](#content) receives an exit signal (that is not `:normal`) from any process when it is not trapping exits it will exit abruptly with the same reason and so not call [`terminate/2`](#c:terminate/2). Note that a process does *NOT* trap exits by default and an exit signal is sent when a linked process exits or its node is disconnected. Therefore it is not guaranteed that [`terminate/2`](#c:terminate/2) is called when a [`GenServer`](#content) exits. For such reasons, we usually recommend important clean-up rules to happen in separated processes either by use of monitoring or by links themselves. There is no cleanup needed when the [`GenServer`](#content) controls a `port` (e.g. `:gen_tcp.socket`) or [`File.io_device/0`](file#t:io_device/0), because these will be closed on receiving a [`GenServer`](#content)'s exit signal and do not need to be closed manually in [`terminate/2`](#c:terminate/2). If `reason` is neither `:normal`, `:shutdown`, nor `{:shutdown, term}` an error is logged. This callback is optional.
programming_docs
elixir Introduction Getting Started Introduction ============ Welcome! In this tutorial, we are going to teach you about Elixir fundamentals - the language syntax, how to define modules, how to manipulate the characteristics of common data structures, and more. This chapter will focus on ensuring that Elixir is installed and that you can successfully run Elixir’s Interactive Shell, called IEx. Our requirements are (see `elixir -v`): * Elixir 1.5.0 onwards * Erlang/OTP 19 onwards Let’s get started! > If you find any errors in the tutorial or on the website, [please report a bug or send a pull request to our issue tracker](https://github.com/elixir-lang/elixir-lang.github.com). > > > The Elixir guides are also available in EPUB format: > > * [Getting started guide](https://repo.hex.pm/guides/elixir/elixir-getting-started-guide.epub) > * [Mix and OTP guide](https://repo.hex.pm/guides/elixir/mix-and-otp.epub) > * [Meta-programming guide](https://repo.hex.pm/guides/elixir/meta-programming-in-elixir.epub) > > Installation ------------ If you haven’t yet installed Elixir, visit our [installation page](https://elixir-lang.org/install.html). Once you are done, you can run `elixir --version` to get the current Elixir version. Interactive mode ---------------- When you install Elixir, you will have three new executables: `iex`, `elixir` and `elixirc`. If you compiled Elixir from source or are using a packaged version, you can find these inside the `bin` directory. For now, let’s start by running `iex` (or `iex.bat` if you are on Windows PowerShell, where `iex` is a PowerShell command) which stands for Interactive Elixir. In interactive mode, we can type any Elixir expression and get its result. Let’s warm up with some basic expressions. Open up `iex` and type the following expressions: ``` Erlang/OTP 21.0 [64-bit] [smp:2:2] [...] Interactive Elixir (1.11.2) - press Ctrl+C to exit iex(1)> 40 + 2 42 iex(2)> "hello" <> " world" "hello world" ``` Please note that some details like version numbers may differ a bit in your session; that’s not important. From now on `iex` sessions will be stripped down to focus on the code. To exit `iex` press `Ctrl+C` twice. It seems we are ready to go! We will use the interactive shell quite a lot in the next chapters to get a bit more familiar with the language constructs and basic types, starting in the next chapter. > Note: if you are on Windows, you can also try `iex --werl` (`iex.bat --werl` on PowerShell) which may provide a better experience depending on which console you are using. > > Running scripts --------------- After getting familiar with the basics of the language you may want to try writing simple programs. This can be accomplished by putting the following Elixir code into a file: ``` IO.puts "Hello world from Elixir" ``` Save it as `simple.exs` and execute it with `elixir`: ``` $ elixir simple.exs Hello world from Elixir ``` Later on we will learn how to compile Elixir code (in [Chapter 8](modules-and-functions)) and how to use the Mix build tool (in the [Mix & OTP guide](mix-otp/introduction-to-mix)). For now, let’s move on to [Chapter 2](basic-types). Asking questions ---------------- When going through this getting started guide, it is common to have questions; after all, that is part of the learning process! There are many places where you can ask questions, here are some of them: * [Official #elixir-lang on freenode IRC](irc://irc.freenode.net/elixir-lang) * [Elixir Forum](http://elixirforum.com) * [Elixir on Slack](https://elixir-slackin.herokuapp.com/) * [Elixir on Discord](https://discord.gg/elixir) * [elixir tag on StackOverflow](https://stackoverflow.com/questions/tagged/elixir) When asking questions, remember these two tips: * Instead of asking “how to do X in Elixir”, ask “how to solve Y in Elixir”. In other words, don’t ask how to implement a particular solution, instead describe the problem at hand. Stating the problem gives more context and less bias for a correct answer. * In case things are not working as expected, please include as much information as you can in your report, for example: your Elixir version, the code snippet and the error message alongside the error stacktrace. Use sites like [Gist](https://gist.github.com/) to paste this information. elixir Date Date ===== A Date struct and functions. The Date struct contains the fields year, month, day and calendar. New dates can be built with the [`new/3`](#new/3) function or using the `~D` (see [`Kernel.sigil_D/2`](kernel#sigil_D/2)) sigil: ``` iex> ~D[2000-01-01] ~D[2000-01-01] ``` Both [`new/3`](#new/3) and sigil return a struct where the date fields can be accessed directly: ``` iex> date = ~D[2000-01-01] iex> date.year 2000 iex> date.month 1 ``` The functions on this module work with the [`Date`](#content) struct as well as any struct that contains the same fields as the [`Date`](#content) struct, such as [`NaiveDateTime`](naivedatetime) and [`DateTime`](datetime). Such functions expect [`Calendar.date/0`](calendar#t:date/0) in their typespecs (instead of [`t/0`](#t:t/0)). Developers should avoid creating the Date structs directly and instead rely on the functions provided by this module as well as the ones in third-party calendar libraries. Comparing dates ---------------- Comparisons in Elixir using [`==/2`](kernel#==/2), [`>/2`](kernel#%3E/2), [`</2`](kernel#%3C/2) and similar are structural and based on the [`Date`](#content) struct fields. For proper comparison between dates, use the [`compare/2`](#compare/2) function. Using epochs ------------- The [`add/2`](#add/2) and [`diff/2`](#diff/2) functions can be used for computing dates or retrieving the number of days between instants. For example, if there is an interest in computing the number of days from the Unix epoch (1970-01-01): ``` iex> Date.diff(~D[2010-04-17], ~D[1970-01-01]) 14716 iex> Date.add(~D[1970-01-01], 14716) ~D[2010-04-17] ``` Those functions are optimized to deal with common epochs, such as the Unix Epoch above or the Gregorian Epoch (0000-01-01). Summary ======== Types ------ [t()](#t:t/0) Functions ---------- [add(date, days)](#add/2) Adds the number of days to the given `date`. [compare(date1, date2)](#compare/2) Compares two date structs. [convert(date, calendar)](#convert/2) Converts the given `date` from its calendar to the given `calendar`. [convert!(date, calendar)](#convert!/2) Similar to [`Date.convert/2`](date#convert/2), but raises an [`ArgumentError`](argumenterror) if the conversion between the two calendars is not possible. [day\_of\_era(date)](#day_of_era/1) Calculates the day-of-era and era for a given calendar `date`. [day\_of\_week(date)](#day_of_week/1) Calculates the day of the week of a given `date`. [day\_of\_year(date)](#day_of_year/1) Calculates the day of the year of a given `date`. [days\_in\_month(date)](#days_in_month/1) Returns the number of days in the given `date` month. [diff(date1, date2)](#diff/2) Calculates the difference between two dates, in a full number of days. [from\_erl(tuple, calendar \\ Calendar.ISO)](#from_erl/2) Converts an Erlang date tuple to a [`Date`](#content) struct. [from\_erl!(tuple, calendar \\ Calendar.ISO)](#from_erl!/2) Converts an Erlang date tuple but raises for invalid dates. [from\_iso8601(string, calendar \\ Calendar.ISO)](#from_iso8601/2) Parses the extended "Dates" format described by [ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601). [from\_iso8601!(string, calendar \\ Calendar.ISO)](#from_iso8601!/2) Parses the extended "Dates" format described by [ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601). [leap\_year?(date)](#leap_year?/1) Returns `true` if the year in the given `date` is a leap year. [months\_in\_year(date)](#months_in_year/1) Returns the number of months in the given `date` year. [new(year, month, day, calendar \\ Calendar.ISO)](#new/4) Builds a new ISO date. [quarter\_of\_year(date)](#quarter_of_year/1) Calculates the quarter of the year of a given `date`. [range(first, last)](#range/2) Returns a range of dates. [to\_erl(date)](#to_erl/1) Converts the given `date` to an Erlang date tuple. [to\_iso8601(date, format \\ :extended)](#to_iso8601/2) Converts the given `date` to [ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601). [to\_string(date)](#to_string/1) Converts the given date to a string according to its calendar. [utc\_today(calendar \\ Calendar.ISO)](#utc_today/1) Returns the current date in UTC. [year\_of\_era(date)](#year_of_era/1) Calculates the year-of-era and era for a given calendar year. Types ====== ### t() #### Specs ``` t() :: %Date{ calendar: Calendar.calendar(), day: Calendar.day(), month: Calendar.month(), year: Calendar.year() } ``` Functions ========== ### add(date, days) #### Specs ``` add(Calendar.date(), integer()) :: t() ``` Adds the number of days to the given `date`. The days are counted as Gregorian days. The date is returned in the same calendar as it was given in. #### Examples ``` iex> Date.add(~D[2000-01-03], -2) ~D[2000-01-01] iex> Date.add(~D[2000-01-01], 2) ~D[2000-01-03] iex> Date.add(~N[2000-01-01 09:00:00], 2) ~D[2000-01-03] iex> Date.add(~D[-0010-01-01], -2) ~D[-0011-12-30] ``` ### compare(date1, date2) #### Specs ``` compare(Calendar.date(), Calendar.date()) :: :lt | :eq | :gt ``` Compares two date structs. Returns `:gt` if first date is later than the second and `:lt` for vice versa. If the two dates are equal `:eq` is returned. #### Examples ``` iex> Date.compare(~D[2016-04-16], ~D[2016-04-28]) :lt ``` This function can also be used to compare across more complex calendar types by considering only the date fields: ``` iex> Date.compare(~D[2016-04-16], ~N[2016-04-28 01:23:45]) :lt iex> Date.compare(~D[2016-04-16], ~N[2016-04-16 01:23:45]) :eq iex> Date.compare(~N[2016-04-16 12:34:56], ~N[2016-04-16 01:23:45]) :eq ``` ### convert(date, calendar) #### Specs ``` convert(Calendar.date(), Calendar.calendar()) :: {:ok, t()} | {:error, :incompatible_calendars} ``` Converts the given `date` from its calendar to the given `calendar`. Returns `{:ok, date}` if the calendars are compatible, or `{:error, :incompatible_calendars}` if they are not. See also [`Calendar.compatible_calendars?/2`](calendar#compatible_calendars?/2). #### Examples Imagine someone implements `Calendar.Holocene`, a calendar based on the Gregorian calendar that adds exactly 10,000 years to the current Gregorian year: ``` iex> Date.convert(~D[2000-01-01], Calendar.Holocene) {:ok, %Date{calendar: Calendar.Holocene, year: 12000, month: 1, day: 1}} ``` ### convert!(date, calendar) #### Specs ``` convert!(Calendar.date(), Calendar.calendar()) :: t() ``` Similar to [`Date.convert/2`](date#convert/2), but raises an [`ArgumentError`](argumenterror) if the conversion between the two calendars is not possible. #### Examples Imagine someone implements `Calendar.Holocene`, a calendar based on the Gregorian calendar that adds exactly 10,000 years to the current Gregorian year: ``` iex> Date.convert!(~D[2000-01-01], Calendar.Holocene) %Date{calendar: Calendar.Holocene, year: 12000, month: 1, day: 1} ``` ### day\_of\_era(date) #### Specs ``` day_of_era(Calendar.date()) :: {Calendar.day(), non_neg_integer()} ``` Calculates the day-of-era and era for a given calendar `date`. Returns a tuple `{day, era}` representing the day within the era and the era number. #### Examples ``` iex> Date.day_of_era(~D[0001-01-01]) {1, 1} iex> Date.day_of_era(~D[0000-12-31]) {1, 0} ``` ### day\_of\_week(date) #### Specs ``` day_of_week(Calendar.date()) :: Calendar.day() ``` Calculates the day of the week of a given `date`. Returns the day of the week as an integer. For the ISO 8601 calendar (the default), it is an integer from 1 to 7, where 1 is Monday and 7 is Sunday. #### Examples ``` iex> Date.day_of_week(~D[2016-10-31]) 1 iex> Date.day_of_week(~D[2016-11-01]) 2 iex> Date.day_of_week(~N[2016-11-01 01:23:45]) 2 iex> Date.day_of_week(~D[-0015-10-30]) 3 ``` ### day\_of\_year(date) #### Specs ``` day_of_year(Calendar.date()) :: Calendar.day() ``` Calculates the day of the year of a given `date`. Returns the day of the year as an integer. For the ISO 8601 calendar (the default), it is an integer from 1 to 366. #### Examples ``` iex> Date.day_of_year(~D[2016-01-01]) 1 iex> Date.day_of_year(~D[2016-11-01]) 306 iex> Date.day_of_year(~D[-0015-10-30]) 303 iex> Date.day_of_year(~D[2004-12-31]) 366 ``` ### days\_in\_month(date) #### Specs ``` days_in_month(Calendar.date()) :: Calendar.day() ``` Returns the number of days in the given `date` month. #### Examples ``` iex> Date.days_in_month(~D[1900-01-13]) 31 iex> Date.days_in_month(~D[1900-02-09]) 28 iex> Date.days_in_month(~N[2000-02-20 01:23:45]) 29 ``` ### diff(date1, date2) #### Specs ``` diff(Calendar.date(), Calendar.date()) :: integer() ``` Calculates the difference between two dates, in a full number of days. It returns the number of Gregorian days between the dates. Only [`Date`](#content) structs that follow the same or compatible calendars can be compared this way. If two calendars are not compatible, it will raise. #### Examples ``` iex> Date.diff(~D[2000-01-03], ~D[2000-01-01]) 2 iex> Date.diff(~D[2000-01-01], ~D[2000-01-03]) -2 iex> Date.diff(~D[0000-01-02], ~D[-0001-12-30]) 3 iex> Date.diff(~D[2000-01-01], ~N[2000-01-03 09:00:00]) -2 ``` ### from\_erl(tuple, calendar \\ Calendar.ISO) #### Specs ``` from_erl(:calendar.date(), Calendar.calendar()) :: {:ok, t()} | {:error, atom()} ``` Converts an Erlang date tuple to a [`Date`](#content) struct. Only supports converting dates which are in the ISO calendar, or other calendars in which the days also start at midnight. Attempting to convert dates from other calendars will return an error tuple. #### Examples ``` iex> Date.from_erl({2000, 1, 1}) {:ok, ~D[2000-01-01]} iex> Date.from_erl({2000, 13, 1}) {:error, :invalid_date} ``` ### from\_erl!(tuple, calendar \\ Calendar.ISO) #### Specs ``` from_erl!(:calendar.date(), Calendar.calendar()) :: t() ``` Converts an Erlang date tuple but raises for invalid dates. #### Examples ``` iex> Date.from_erl!({2000, 1, 1}) ~D[2000-01-01] iex> Date.from_erl!({2000, 13, 1}) ** (ArgumentError) cannot convert {2000, 13, 1} to date, reason: :invalid_date ``` ### from\_iso8601(string, calendar \\ Calendar.ISO) #### Specs ``` from_iso8601(String.t(), Calendar.calendar()) :: {:ok, t()} | {:error, atom()} ``` Parses the extended "Dates" format described by [ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601). The year parsed by this function is limited to four digits. #### Examples ``` iex> Date.from_iso8601("2015-01-23") {:ok, ~D[2015-01-23]} iex> Date.from_iso8601("2015:01:23") {:error, :invalid_format} iex> Date.from_iso8601("2015-01-32") {:error, :invalid_date} ``` ### from\_iso8601!(string, calendar \\ Calendar.ISO) #### Specs ``` from_iso8601!(String.t(), Calendar.calendar()) :: t() ``` Parses the extended "Dates" format described by [ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601). Raises if the format is invalid. #### Examples ``` iex> Date.from_iso8601!("2015-01-23") ~D[2015-01-23] iex> Date.from_iso8601!("2015:01:23") ** (ArgumentError) cannot parse "2015:01:23" as date, reason: :invalid_format ``` ### leap\_year?(date) #### Specs ``` leap_year?(Calendar.date()) :: boolean() ``` Returns `true` if the year in the given `date` is a leap year. #### Examples ``` iex> Date.leap_year?(~D[2000-01-01]) true iex> Date.leap_year?(~D[2001-01-01]) false iex> Date.leap_year?(~D[2004-01-01]) true iex> Date.leap_year?(~D[1900-01-01]) false iex> Date.leap_year?(~N[2004-01-01 01:23:45]) true ``` ### months\_in\_year(date) #### Specs ``` months_in_year(Calendar.date()) :: Calendar.month() ``` Returns the number of months in the given `date` year. #### Example ``` iex> Date.months_in_year(~D[1900-01-13]) 12 ``` ### new(year, month, day, calendar \\ Calendar.ISO) #### Specs ``` new(Calendar.year(), Calendar.month(), Calendar.day(), Calendar.calendar()) :: {:ok, t()} | {:error, atom()} ``` Builds a new ISO date. Expects all values to be integers. Returns `{:ok, date}` if each entry fits its appropriate range, returns `{:error, reason}` otherwise. #### Examples ``` iex> Date.new(2000, 1, 1) {:ok, ~D[2000-01-01]} iex> Date.new(2000, 13, 1) {:error, :invalid_date} iex> Date.new(2000, 2, 29) {:ok, ~D[2000-02-29]} iex> Date.new(2000, 2, 30) {:error, :invalid_date} iex> Date.new(2001, 2, 29) {:error, :invalid_date} ``` ### quarter\_of\_year(date) #### Specs ``` quarter_of_year(Calendar.date()) :: non_neg_integer() ``` Calculates the quarter of the year of a given `date`. Returns the day of the year as an integer. For the ISO 8601 calendar (the default), it is an integer from 1 to 4. #### Examples ``` iex> Date.quarter_of_year(~D[2016-10-31]) 4 iex> Date.quarter_of_year(~D[2016-01-01]) 1 iex> Date.quarter_of_year(~N[2016-04-01 01:23:45]) 2 iex> Date.quarter_of_year(~D[-0015-09-30]) 3 ``` ### range(first, last) #### Specs ``` range(Date.t(), Date.t()) :: Date.Range.t() ``` Returns a range of dates. A range of dates represents a discrete number of dates where the first and last values are dates with matching calendars. Ranges of dates can be either increasing (`first <= last`) or decreasing (`first > last`). They are also always inclusive. #### Examples ``` iex> Date.range(~D[1999-01-01], ~D[2000-01-01]) #DateRange<~D[1999-01-01], ~D[2000-01-01]> ``` A range of dates implements the [`Enumerable`](enumerable) protocol, which means functions in the [`Enum`](enum) module can be used to work with ranges: ``` iex> range = Date.range(~D[2001-01-01], ~D[2002-01-01]) iex> Enum.count(range) 366 iex> Enum.member?(range, ~D[2001-02-01]) true iex> Enum.reduce(range, 0, fn _date, acc -> acc - 1 end) -366 ``` ### to\_erl(date) #### Specs ``` to_erl(Calendar.date()) :: :calendar.date() ``` Converts the given `date` to an Erlang date tuple. Only supports converting dates which are in the ISO calendar, or other calendars in which the days also start at midnight. Attempting to convert dates from other calendars will raise. #### Examples ``` iex> Date.to_erl(~D[2000-01-01]) {2000, 1, 1} iex> Date.to_erl(~N[2000-01-01 00:00:00]) {2000, 1, 1} ``` ### to\_iso8601(date, format \\ :extended) #### Specs ``` to_iso8601(Calendar.date(), :extended | :basic) :: String.t() ``` Converts the given `date` to [ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601). By default, [`Date.to_iso8601/2`](date#to_iso8601/2) returns dates formatted in the "extended" format, for human readability. It also supports the "basic" format through passing the `:basic` option. Only supports converting dates which are in the ISO calendar, or other calendars in which the days also start at midnight. Attempting to convert dates from other calendars will raise an [`ArgumentError`](argumenterror). ### Examples ``` iex> Date.to_iso8601(~D[2000-02-28]) "2000-02-28" iex> Date.to_iso8601(~D[2000-02-28], :basic) "20000228" iex> Date.to_iso8601(~N[2000-02-28 00:00:00]) "2000-02-28" ``` ### to\_string(date) #### Specs ``` to_string(Calendar.date()) :: String.t() ``` Converts the given date to a string according to its calendar. ### Examples ``` iex> Date.to_string(~D[2000-02-28]) "2000-02-28" iex> Date.to_string(~N[2000-02-28 01:23:45]) "2000-02-28" iex> Date.to_string(~D[-0100-12-15]) "-0100-12-15" ``` ### utc\_today(calendar \\ Calendar.ISO) #### Specs ``` utc_today(Calendar.calendar()) :: t() ``` Returns the current date in UTC. #### Examples ``` iex> date = Date.utc_today() iex> date.year >= 2016 true ``` ### year\_of\_era(date) #### Specs ``` year_of_era(Calendar.date()) :: {Calendar.year(), non_neg_integer()} ``` Calculates the year-of-era and era for a given calendar year. Returns a tuple `{year, era}` representing the year within the era and the era number. #### Examples ``` iex> Date.year_of_era(~D[0001-01-01]) {1, 1} iex> Date.year_of_era(~D[0000-12-31]) {1, 0} iex> Date.year_of_era(~D[-0001-01-01]) {2, 0} ```
programming_docs
elixir ExUnit.Assertions ExUnit.Assertions ================== This module contains a set of assertion functions that are imported by default into your test cases. In general, a developer will want to use the general `assert` macro in tests. This macro introspects your code and provides good reporting whenever there is a failure. For example, `assert some_fun() == 10` will fail (assuming `some_fun()` returns `13`): ``` Comparison (using ==) failed in: code: assert some_fun() == 10 left: 13 right: 10 ``` This module also provides other convenience functions like `assert_in_delta` and `assert_raise` to easily handle other common cases such as checking a floating-point number or handling exceptions. Summary ======== Functions ---------- [assert(assertion)](#assert/1) Asserts its argument is a truthy value. [assert(value, message)](#assert/2) Asserts `value` is truthy, displaying the given `message` otherwise. [assert\_in\_delta(value1, value2, delta, message \\ nil)](#assert_in_delta/4) Asserts that `value1` and `value2` differ by no more than `delta`. [assert\_raise(exception, function)](#assert_raise/2) Asserts the `exception` is raised during `function` execution. Returns the rescued exception, fails otherwise. [assert\_raise(exception, message, function)](#assert_raise/3) Asserts the `exception` is raised during `function` execution with the expected `message`, which can be a [`Regex`](https://hexdocs.pm/elixir/Regex.html) or an exact [`String`](https://hexdocs.pm/elixir/String.html). Returns the rescued exception, fails otherwise. [assert\_receive(pattern, timeout \\ Application.fetch\_env!(:ex\_unit, :assert\_receive\_timeout), failure\_message \\ nil)](#assert_receive/3) Asserts that a message matching `pattern` was or is going to be received within the `timeout` period, specified in milliseconds. [assert\_received(pattern, failure\_message \\ nil)](#assert_received/2) Asserts that a message matching `pattern` was received and is in the current process' mailbox. [catch\_error(expression)](#catch_error/1) Asserts `expression` will cause an error. [catch\_exit(expression)](#catch_exit/1) Asserts `expression` will exit. [catch\_throw(expression)](#catch_throw/1) Asserts `expression` will throw a value. [flunk(message \\ "Flunked!")](#flunk/1) Fails with a message. [refute(assertion)](#refute/1) A negative assertion, expects the expression to be `false` or `nil`. [refute(value, message)](#refute/2) Asserts `value` is `nil` or `false` (that is, `value` is not truthy). [refute\_in\_delta(value1, value2, delta, message \\ nil)](#refute_in_delta/4) Asserts `value1` and `value2` are not within `delta`. [refute\_receive(pattern, timeout \\ Application.fetch\_env!(:ex\_unit, :refute\_receive\_timeout), failure\_message \\ nil)](#refute_receive/3) Asserts that a message matching `pattern` was not received (and won't be received) within the `timeout` period, specified in milliseconds. [refute\_received(pattern, failure\_message \\ nil)](#refute_received/2) Asserts a message matching `pattern` was not received (i.e. it is not in the current process' mailbox). Functions ========== ### assert(assertion) Asserts its argument is a truthy value. `assert` introspects the underlying expression and provides good reporting whenever there is a failure. For example, if the expression uses the comparison operator, the message will show the values of the two sides. The assertion ``` assert 1 + 2 + 3 + 4 > 15 ``` will fail with the message: ``` Assertion with > failed code: assert 1 + 2 + 3 + 4 > 15 left: 10 right: 15 ``` Similarly, if a match expression is given, it will report any failure in terms of that match. Given ``` assert [1] = [2] ``` you'll see: ``` match (=) failed code: assert [1] = [2] right: [2] ``` Keep in mind that `assert` does not change its semantics based on the expression. In other words, the expression is still required to return a truthy value. For example, the following will fail: ``` assert nil = some_function_that_returns_nil() ``` Even though the match works, `assert` still expects a truth value. In such cases, simply use [`Kernel.==/2`](https://hexdocs.pm/elixir/Kernel.html#==/2) or [`Kernel.match?/2`](https://hexdocs.pm/elixir/Kernel.html#match?/2). ### assert(value, message) Asserts `value` is truthy, displaying the given `message` otherwise. #### Examples ``` assert false, "it will never be true" ``` ### assert\_in\_delta(value1, value2, delta, message \\ nil) Asserts that `value1` and `value2` differ by no more than `delta`. This difference is inclusive, so the test will pass if the difference and the `delta` are equal. #### Examples ``` assert_in_delta 1.1, 1.5, 0.2 assert_in_delta 10, 15, 2 assert_in_delta 10, 15, 5 ``` ### assert\_raise(exception, function) Asserts the `exception` is raised during `function` execution. Returns the rescued exception, fails otherwise. #### Examples ``` assert_raise ArithmeticError, fn -> 1 + "test" end ``` ### assert\_raise(exception, message, function) Asserts the `exception` is raised during `function` execution with the expected `message`, which can be a [`Regex`](https://hexdocs.pm/elixir/Regex.html) or an exact [`String`](https://hexdocs.pm/elixir/String.html). Returns the rescued exception, fails otherwise. #### Examples ``` assert_raise ArithmeticError, "bad argument in arithmetic expression", fn -> 1 + "test" end assert_raise RuntimeError, ~r/^today's lucky number is 0\.\d+!$/, fn -> raise "today's lucky number is #{:rand.uniform()}!" end ``` ### assert\_receive(pattern, timeout \\ Application.fetch\_env!(:ex\_unit, :assert\_receive\_timeout), failure\_message \\ nil) Asserts that a message matching `pattern` was or is going to be received within the `timeout` period, specified in milliseconds. Unlike `assert_received`, it has a default `timeout` of 100 milliseconds. The `pattern` argument must be a match pattern. Flunks with `failure_message` if a message matching `pattern` is not received. #### Examples ``` assert_receive :hello ``` Asserts against a larger timeout: ``` assert_receive :hello, 20_000 ``` You can also match against specific patterns: ``` assert_receive {:hello, _} x = 5 assert_receive {:count, ^x} ``` ### assert\_received(pattern, failure\_message \\ nil) Asserts that a message matching `pattern` was received and is in the current process' mailbox. The `pattern` argument must be a match pattern. Flunks with `failure_message` if a message matching `pattern` was not received. Timeout is set to 0, so there is no waiting time. #### Examples ``` send(self(), :hello) assert_received :hello send(self(), :bye) assert_received :hello, "Oh No!" ** (ExUnit.AssertionError) Oh No! Process mailbox: :bye ``` You can also match against specific patterns: ``` send(self(), {:hello, "world"}) assert_received {:hello, _} ``` ### catch\_error(expression) Asserts `expression` will cause an error. Returns the error or fails otherwise. #### Examples ``` assert catch_error(error(1)) == 1 ``` ### catch\_exit(expression) Asserts `expression` will exit. Returns the exit status/message of the current process or fails otherwise. #### Examples ``` assert catch_exit(exit(1)) == 1 ``` To assert exits from linked processes started from the test, trap exits with [`Process.flag/2`](https://hexdocs.pm/elixir/Process.html#flag/2) and assert the exit message with [`assert_received/2`](#assert_received/2). ``` Process.flag(:trap_exit, true) pid = spawn_link(fn -> Process.exit(self(), :normal) end) assert_receive {:EXIT, ^pid, :normal} ``` ### catch\_throw(expression) Asserts `expression` will throw a value. Returns the thrown value or fails otherwise. #### Examples ``` assert catch_throw(throw(1)) == 1 ``` ### flunk(message \\ "Flunked!") #### Specs ``` flunk(String.t()) :: no_return() ``` Fails with a message. #### Examples ``` flunk("This should raise an error") ``` ### refute(assertion) A negative assertion, expects the expression to be `false` or `nil`. Keep in mind that `refute` does not change the semantics of the given expression. In other words, the following will fail: ``` refute {:ok, _} = some_function_that_returns_error_tuple() ``` The code above will fail because the `=` operator always fails when the sides do not match and [`refute/2`](#refute/2) does not change it. The correct way to write the refutation above is to use [`Kernel.match?/2`](https://hexdocs.pm/elixir/Kernel.html#match?/2): ``` refute match?({:ok, _}, some_function_that_returns_error_tuple()) ``` #### Examples ``` refute age < 0 ``` ### refute(value, message) Asserts `value` is `nil` or `false` (that is, `value` is not truthy). #### Examples ``` refute true, "This will obviously fail" ``` ### refute\_in\_delta(value1, value2, delta, message \\ nil) Asserts `value1` and `value2` are not within `delta`. This difference is exclusive, so the test will fail if the difference and the delta are equal. If you supply `message`, information about the values will automatically be appended to it. #### Examples ``` refute_in_delta 1.1, 1.2, 0.2 refute_in_delta 10, 11, 2 ``` ### refute\_receive(pattern, timeout \\ Application.fetch\_env!(:ex\_unit, :refute\_receive\_timeout), failure\_message \\ nil) Asserts that a message matching `pattern` was not received (and won't be received) within the `timeout` period, specified in milliseconds. The `pattern` argument must be a match pattern. Flunks with `failure_message` if a message matching `pattern` is received. #### Examples ``` refute_receive :bye ``` Refute received with an explicit timeout: ``` refute_receive :bye, 1000 ``` ### refute\_received(pattern, failure\_message \\ nil) Asserts a message matching `pattern` was not received (i.e. it is not in the current process' mailbox). The `pattern` argument must be a match pattern. Flunks with `failure_message` if a message matching `pattern` was received. Timeout is set to 0, so there is no waiting time. #### Examples ``` send(self(), :hello) refute_received :bye send(self(), :hello) refute_received :hello, "Oh No!" ** (ExUnit.AssertionError) Oh No! Process mailbox: :bye ``` elixir Version Version ======== Functions for parsing and matching versions against requirements. A version is a string in a specific format or a [`Version`](#content) generated after parsing via [`Version.parse/1`](version#parse/1). [`Version`](#content) parsing and requirements follow [SemVer 2.0 schema](https://semver.org/). Versions --------- In a nutshell, a version is represented by three numbers: ``` MAJOR.MINOR.PATCH ``` Pre-releases are supported by optionally appending a hyphen and a series of period-separated identifiers immediately following the patch version. Identifiers consist of only ASCII alphanumeric characters and hyphens (`[0-9A-Za-z-]`): ``` "1.0.0-alpha.3" ``` Build information can be added by appending a plus sign and a series of dot-separated identifiers immediately following the patch or pre-release version. Identifiers consist of only ASCII alphanumeric characters and hyphens (`[0-9A-Za-z-]`): ``` "1.0.0-alpha.3+20130417140000.amd64" ``` Struct ------- The version is represented by the [`Version`](#content) struct and fields are named according to SemVer: `:major`, `:minor`, `:patch`, `:pre`, and `:build`. Requirements ------------- Requirements allow you to specify which versions of a given dependency you are willing to work against. Requirements support the common comparison operators such as `>`, `>=`, `<`, `<=`, `==`, `!=` that work as one would expect, and additionally the special operator `~>` described in detail further below. ``` # Only version 2.0.0 "== 2.0.0" # Anything later than 2.0.0 "> 2.0.0" ``` Requirements also support `and` and `or` for complex conditions: ``` # 2.0.0 and later until 2.1.0 ">= 2.0.0 and < 2.1.0" ``` Since the example above is such a common requirement, it can be expressed as: ``` "~> 2.0.0" ``` `~>` will never include pre-release versions of its upper bound, regardless of the usage of the `:allow_pre` option, or whether the operand is a pre-release version. It can also be used to set an upper bound on only the major version part. See the table below for `~>` requirements and their corresponding translations. | `~>` | Translation | | --- | --- | | `~> 2.0.0` | `>= 2.0.0 and < 2.1.0` | | `~> 2.1.2` | `>= 2.1.2 and < 2.2.0` | | `~> 2.1.3-dev` | `>= 2.1.3-dev and < 2.2.0` | | `~> 2.0` | `>= 2.0.0 and < 3.0.0` | | `~> 2.1` | `>= 2.1.0 and < 3.0.0` | The requirement operand after the `~>` is allowed to omit the patch version, allowing us to express `~> 2.1` or `~> 2.1-dev`, something that wouldn't be allowed when using the common comparison operators. When the `:allow_pre` option is set `false` in [`Version.match?/3`](version#match?/3), the requirement will not match a pre-release version unless the operand is a pre-release version. The default is to always allow pre-releases but note that in Hex `:allow_pre` is set to `false`. See the table below for examples. | Requirement | Version | `:allow_pre` | Matches | | --- | --- | --- | --- | | `~> 2.0` | `2.1.0` | `true` or `false` | `true` | | `~> 2.0` | `3.0.0` | `true` or `false` | `false` | | `~> 2.0.0` | `2.0.5` | `true` or `false` | `true` | | `~> 2.0.0` | `2.1.0` | `true` or `false` | `false` | | `~> 2.1.2` | `2.1.6-dev` | `true` | `true` | | `~> 2.1.2` | `2.1.6-dev` | `false` | `false` | | `~> 2.1-dev` | `2.2.0-dev` | `true` or `false` | `true` | | `~> 2.1.2-dev` | `2.1.6-dev` | `true` or `false` | `true` | | `>= 2.1.0` | `2.2.0-dev` | `true` | `true` | | `>= 2.1.0` | `2.2.0-dev` | `false` | `false` | | `>= 2.1.0-dev` | `2.2.6-dev` | `true` or `false` | `true` | Summary ======== Types ------ [build()](#t:build/0) [major()](#t:major/0) [minor()](#t:minor/0) [patch()](#t:patch/0) [pre()](#t:pre/0) [requirement()](#t:requirement/0) [t()](#t:t/0) [version()](#t:version/0) Functions ---------- [compare(version1, version2)](#compare/2) Compares two versions. [compile\_requirement(requirement)](#compile_requirement/1) Compiles a requirement to its internal representation with [`:ets.match_spec_compile/1`](http://www.erlang.org/doc/man/ets.html#match_spec_compile-1) for faster matching. [match?(version, requirement, opts \\ [])](#match?/3) Checks if the given version matches the specification. [parse(string)](#parse/1) Parses a version string into a [`Version`](#content) struct. [parse!(string)](#parse!/1) Parses a version string into a [`Version`](#content). [parse\_requirement(string)](#parse_requirement/1) Parses a version requirement string into a [`Version.Requirement`](version.requirement) struct. [parse\_requirement!(string)](#parse_requirement!/1) Parses a version requirement string into a [`Version.Requirement`](version.requirement) struct. Types ====== ### build() #### Specs ``` build() :: String.t() | nil ``` ### major() #### Specs ``` major() :: non_neg_integer() ``` ### minor() #### Specs ``` minor() :: non_neg_integer() ``` ### patch() #### Specs ``` patch() :: non_neg_integer() ``` ### pre() #### Specs ``` pre() :: [String.t() | non_neg_integer()] ``` ### requirement() #### Specs ``` requirement() :: String.t() | Version.Requirement.t() ``` ### t() #### Specs ``` t() :: %Version{ build: build(), major: major(), minor: minor(), patch: patch(), pre: pre() } ``` ### version() #### Specs ``` version() :: String.t() | t() ``` Functions ========== ### compare(version1, version2) #### Specs ``` compare(version(), version()) :: :gt | :eq | :lt ``` Compares two versions. Returns `:gt` if the first version is greater than the second one, and `:lt` for vice versa. If the two versions are equal, `:eq` is returned. Pre-releases are strictly less than their corresponding release versions. Patch segments are compared lexicographically if they are alphanumeric, and numerically otherwise. Build segments are ignored: if two versions differ only in their build segment they are considered to be equal. Raises a [`Version.InvalidVersionError`](version.invalidversionerror) exception if any of the two given versions are not parsable. If given an already parsed version this function won't raise. #### Examples ``` iex> Version.compare("2.0.1-alpha1", "2.0.0") :gt iex> Version.compare("1.0.0-beta", "1.0.0-rc1") :lt iex> Version.compare("1.0.0-10", "1.0.0-2") :gt iex> Version.compare("2.0.1+build0", "2.0.1") :eq iex> Version.compare("invalid", "2.0.1") ** (Version.InvalidVersionError) invalid version: "invalid" ``` ### compile\_requirement(requirement) #### Specs ``` compile_requirement(Version.Requirement.t()) :: Version.Requirement.t() ``` Compiles a requirement to its internal representation with [`:ets.match_spec_compile/1`](http://www.erlang.org/doc/man/ets.html#match_spec_compile-1) for faster matching. The internal representation is opaque and cannot be converted to external term format and then back again without losing its properties (meaning it can not be sent to a process on another node and still remain a valid compiled match\_spec, nor can it be stored on disk). ### match?(version, requirement, opts \\ []) #### Specs ``` match?(version(), requirement(), keyword()) :: boolean() ``` Checks if the given version matches the specification. Returns `true` if `version` satisfies `requirement`, `false` otherwise. Raises a [`Version.InvalidRequirementError`](version.invalidrequirementerror) exception if `requirement` is not parsable, or a [`Version.InvalidVersionError`](version.invalidversionerror) exception if `version` is not parsable. If given an already parsed version and requirement this function won't raise. #### Options * `:allow_pre` (boolean) - when `false`, pre-release versions will not match unless the operand is a pre-release version. Defaults to `true`. For examples, please refer to the table above under the "Requirements" section. #### Examples ``` iex> Version.match?("2.0.0", "> 1.0.0") true iex> Version.match?("2.0.0", "== 1.0.0") false iex> Version.match?("2.1.6-dev", "~> 2.1.2") true iex> Version.match?("2.1.6-dev", "~> 2.1.2", allow_pre: false) false iex> Version.match?("foo", "== 1.0.0") ** (Version.InvalidVersionError) invalid version: "foo" iex> Version.match?("2.0.0", "== == 1.0.0") ** (Version.InvalidRequirementError) invalid requirement: "== == 1.0.0" ``` ### parse(string) #### Specs ``` parse(String.t()) :: {:ok, t()} | :error ``` Parses a version string into a [`Version`](#content) struct. #### Examples ``` iex> {:ok, version} = Version.parse("2.0.1-alpha1") iex> version #Version<2.0.1-alpha1> iex> Version.parse("2.0-alpha1") :error ``` ### parse!(string) #### Specs ``` parse!(String.t()) :: t() ``` Parses a version string into a [`Version`](#content). If `string` is an invalid version, a [`Version.InvalidVersionError`](version.invalidversionerror) is raised. #### Examples ``` iex> Version.parse!("2.0.1-alpha1") #Version<2.0.1-alpha1> iex> Version.parse!("2.0-alpha1") ** (Version.InvalidVersionError) invalid version: "2.0-alpha1" ``` ### parse\_requirement(string) #### Specs ``` parse_requirement(String.t()) :: {:ok, Version.Requirement.t()} | :error ``` Parses a version requirement string into a [`Version.Requirement`](version.requirement) struct. #### Examples ``` iex> {:ok, requirement} = Version.parse_requirement("== 2.0.1") iex> requirement #Version.Requirement<== 2.0.1> iex> Version.parse_requirement("== == 2.0.1") :error ``` ### parse\_requirement!(string) #### Specs ``` parse_requirement!(String.t()) :: Version.Requirement.t() ``` Parses a version requirement string into a [`Version.Requirement`](version.requirement) struct. If `string` is an invalid requirement, a [`Version.InvalidRequirementError`](version.invalidrequirementerror) is raised. #### Examples ``` iex> Version.parse_requirement!("== 2.0.1") #Version.Requirement<== 2.0.1> iex> Version.parse_requirement!("== == 2.0.1") ** (Version.InvalidRequirementError) invalid requirement: "== == 2.0.1" ```
programming_docs
elixir Keyword Keyword ======== A set of functions for working with keywords. A keyword list is a list of two-element tuples where the first element of the tuple is an atom and the second element can be any value. For example, the following is a keyword list: ``` [{:exit_on_close, true}, {:active, :once}, {:packet_size, 1024}] ``` Elixir provides a special and more concise syntax for keyword lists that looks like this: ``` [exit_on_close: true, active: :once, packet_size: 1024] ``` This is also the syntax that Elixir uses to inspect keyword lists: ``` iex> [{:active, :once}] [active: :once] ``` The two syntaxes are completely equivalent. Like atoms, keywords must be composed of Unicode characters such as letters, numbers, underscore, and `@`. If the keyword has a character that does not belong to the category above, such as spaces, you can wrap it in quotes: ``` iex> ["exit on close": true] ["exit on close": true] ``` Wrapping a keyword in quotes does not make it a string. Keywords are always atoms. If you use quotes when all characters are a valid part of a keyword without quotes, Elixir will warn. Note that when keyword lists are passed as the last argument to a function, if the short-hand syntax is used then the square brackets around the keyword list can be omitted as well. For example, the following: ``` String.split("1-0", "-", trim: true, parts: 2) ``` is equivalent to: ``` String.split("1-0", "-", [trim: true, parts: 2]) ``` A keyword may have duplicated keys so it is not strictly a key-value store. However most of the functions in this module behave exactly as a dictionary so they work similarly to the functions you would find in the [`Map`](map) module. For example, [`Keyword.get/3`](keyword#get/3) will get the first entry matching the given key, regardless if duplicated entries exist. Similarly, [`Keyword.put/3`](keyword#put/3) and [`Keyword.delete/3`](keyword#delete/3) ensure all duplicated entries for a given key are removed when invoked. Note that operations that require keys to be found in the keyword list (like [`Keyword.get/3`](keyword#get/3)) need to traverse the list in order to find keys, so these operations may be slower than their map counterparts. A handful of functions exist to handle duplicated keys, in particular, [`Enum.into/2`](enum#into/2) allows creating new keywords without removing duplicated keys, [`get_values/2`](#get_values/2) returns all values for a given key and [`delete_first/2`](#delete_first/2) deletes just one of the existing entries. The functions in [`Keyword`](#content) do not guarantee any property when it comes to ordering. However, since a keyword list is simply a list, all the operations defined in [`Enum`](enum) and [`List`](list) can be applied too, especially when ordering is required. Most of the functions in this module work in linear time. This means that, the time it takes to perform an operation grows at the same rate as the length of the list. Summary ======== Types ------ [key()](#t:key/0) [t()](#t:t/0) [t(value)](#t:t/1) [value()](#t:value/0) Functions ---------- [delete(keywords, key)](#delete/2) Deletes the entries in the keyword list for a specific `key`. [delete(keywords, key, value)](#delete/3) Deletes the entries in the keyword list for a `key` with `value`. [delete\_first(keywords, key)](#delete_first/2) Deletes the first entry in the keyword list for a specific `key`. [drop(keywords, keys)](#drop/2) Drops the given keys from the keyword list. [equal?(left, right)](#equal?/2) Checks if two keywords are equal. [fetch(keywords, key)](#fetch/2) Fetches the value for a specific `key` and returns it in a tuple. [fetch!(keywords, key)](#fetch!/2) Fetches the value for specific `key`. [get(keywords, key, default \\ nil)](#get/3) Gets the value for a specific `key`. [get\_and\_update(keywords, key, fun)](#get_and_update/3) Gets the value from `key` and updates it, all in one pass. [get\_and\_update!(keywords, key, fun)](#get_and_update!/3) Gets the value from `key` and updates it. Raises if there is no `key`. [get\_lazy(keywords, key, fun)](#get_lazy/3) Gets the value for a specific `key`. [get\_values(keywords, key)](#get_values/2) Gets all values for a specific `key`. [has\_key?(keywords, key)](#has_key?/2) Returns whether a given `key` exists in the given `keywords`. [keys(keywords)](#keys/1) Returns all keys from the keyword list. [keyword?(term)](#keyword?/1) Returns `true` if `term` is a keyword list; otherwise returns `false`. [merge(keywords1, keywords2)](#merge/2) Merges two keyword lists into one. [merge(keywords1, keywords2, fun)](#merge/3) Merges two keyword lists into one. [new()](#new/0) Returns an empty keyword list, i.e. an empty list. [new(pairs)](#new/1) Creates a keyword list from an enumerable. [new(pairs, transform)](#new/2) Creates a keyword list from an enumerable via the transformation function. [pop(keywords, key, default \\ nil)](#pop/3) Returns the first value for `key` and removes all associated entries in the keyword list. [pop\_first(keywords, key, default \\ nil)](#pop_first/3) Returns and removes the first value associated with `key` in the keyword list. [pop\_lazy(keywords, key, fun)](#pop_lazy/3) Lazily returns and removes all values associated with `key` in the keyword list. [put(keywords, key, value)](#put/3) Puts the given `value` under `key`. [put\_new(keywords, key, value)](#put_new/3) Puts the given `value` under `key` unless the entry `key` already exists. [put\_new\_lazy(keywords, key, fun)](#put_new_lazy/3) Evaluates `fun` and puts the result under `key` in keyword list unless `key` is already present. [replace!(keywords, key, value)](#replace!/3) Alters the value stored under `key` to `value`, but only if the entry `key` already exists in `keywords`. [split(keywords, keys)](#split/2) Takes all entries corresponding to the given keys and extracts them into a separate keyword list. [take(keywords, keys)](#take/2) Takes all entries corresponding to the given keys and returns them in a new keyword list. [to\_list(keyword)](#to_list/1) Returns the keyword list itself. [update(keywords, key, initial, fun)](#update/4) Updates the `key` in `keywords` with the given function. [update!(keywords, key, fun)](#update!/3) Updates the `key` with the given function. [values(keywords)](#values/1) Returns all values from the keyword list. Types ====== ### key() #### Specs ``` key() :: atom() ``` ### t() #### Specs ``` t() :: [{key(), value()}] ``` ### t(value) #### Specs ``` t(value) :: [{key(), value}] ``` ### value() #### Specs ``` value() :: any() ``` Functions ========== ### delete(keywords, key) #### Specs ``` delete(t(), key()) :: t() ``` Deletes the entries in the keyword list for a specific `key`. If the `key` does not exist, returns the keyword list unchanged. Use [`delete_first/2`](#delete_first/2) to delete just the first entry in case of duplicated keys. #### Examples ``` iex> Keyword.delete([a: 1, b: 2], :a) [b: 2] iex> Keyword.delete([a: 1, b: 2, a: 3], :a) [b: 2] iex> Keyword.delete([b: 2], :a) [b: 2] ``` ### delete(keywords, key, value) #### Specs ``` delete(t(), key(), value()) :: t() ``` Deletes the entries in the keyword list for a `key` with `value`. If no `key` with `value` exists, returns the keyword list unchanged. #### Examples ``` iex> Keyword.delete([a: 1, b: 2], :a, 1) [b: 2] iex> Keyword.delete([a: 1, b: 2, a: 3], :a, 3) [a: 1, b: 2] iex> Keyword.delete([a: 1], :a, 5) [a: 1] iex> Keyword.delete([a: 1], :b, 5) [a: 1] ``` ### delete\_first(keywords, key) #### Specs ``` delete_first(t(), key()) :: t() ``` Deletes the first entry in the keyword list for a specific `key`. If the `key` does not exist, returns the keyword list unchanged. #### Examples ``` iex> Keyword.delete_first([a: 1, b: 2, a: 3], :a) [b: 2, a: 3] iex> Keyword.delete_first([b: 2], :a) [b: 2] ``` ### drop(keywords, keys) #### Specs ``` drop(t(), [key()]) :: t() ``` Drops the given keys from the keyword list. Duplicated keys are preserved in the new keyword list. #### Examples ``` iex> Keyword.drop([a: 1, b: 2, c: 3], [:b, :d]) [a: 1, c: 3] iex> Keyword.drop([a: 1, b: 2, b: 3, c: 3, a: 5], [:b, :d]) [a: 1, c: 3, a: 5] ``` ### equal?(left, right) #### Specs ``` equal?(t(), t()) :: boolean() ``` Checks if two keywords are equal. Two keywords are considered to be equal if they contain the same keys and those keys contain the same values. #### Examples ``` iex> Keyword.equal?([a: 1, b: 2], [b: 2, a: 1]) true iex> Keyword.equal?([a: 1, b: 2], [b: 1, a: 2]) false iex> Keyword.equal?([a: 1, b: 2, a: 3], [b: 2, a: 3, a: 1]) true ``` ### fetch(keywords, key) #### Specs ``` fetch(t(), key()) :: {:ok, value()} | :error ``` Fetches the value for a specific `key` and returns it in a tuple. If the `key` does not exist, returns `:error`. #### Examples ``` iex> Keyword.fetch([a: 1], :a) {:ok, 1} iex> Keyword.fetch([a: 1], :b) :error ``` ### fetch!(keywords, key) #### Specs ``` fetch!(t(), key()) :: value() ``` Fetches the value for specific `key`. If `key` does not exist, a [`KeyError`](keyerror) is raised. #### Examples ``` iex> Keyword.fetch!([a: 1], :a) 1 iex> Keyword.fetch!([a: 1], :b) ** (KeyError) key :b not found in: [a: 1] ``` ### get(keywords, key, default \\ nil) #### Specs ``` get(t(), key(), value()) :: value() ``` Gets the value for a specific `key`. If `key` does not exist, return the default value (`nil` if no default value). If duplicated entries exist, the first one is returned. Use [`get_values/2`](#get_values/2) to retrieve all entries. #### Examples ``` iex> Keyword.get([], :a) nil iex> Keyword.get([a: 1], :a) 1 iex> Keyword.get([a: 1], :b) nil iex> Keyword.get([a: 1], :b, 3) 3 ``` With duplicated keys: ``` iex> Keyword.get([a: 1, a: 2], :a, 3) 1 iex> Keyword.get([a: 1, a: 2], :b, 3) 3 ``` ### get\_and\_update(keywords, key, fun) #### Specs ``` get_and_update(t(), key(), (value() -> {get, value()} | :pop)) :: {get, t()} when get: term() ``` Gets the value from `key` and updates it, all in one pass. This `fun` argument receives the value of `key` (or `nil` if `key` is not present) and must return a two-element tuple: the "get" value (the retrieved value, which can be operated on before being returned) and the new value to be stored under `key`. The `fun` may also return `:pop`, implying the current value shall be removed from the keyword list and returned. The returned value is a tuple with the "get" value returned by `fun` and a new keyword list with the updated value under `key`. #### Examples ``` iex> Keyword.get_and_update([a: 1], :a, fn current_value -> ...> {current_value, "new value!"} ...> end) {1, [a: "new value!"]} iex> Keyword.get_and_update([a: 1], :b, fn current_value -> ...> {current_value, "new value!"} ...> end) {nil, [b: "new value!", a: 1]} iex> Keyword.get_and_update([a: 1], :a, fn _ -> :pop end) {1, []} iex> Keyword.get_and_update([a: 1], :b, fn _ -> :pop end) {nil, [a: 1]} ``` ### get\_and\_update!(keywords, key, fun) #### Specs ``` get_and_update!(t(), key(), (value() -> {get, value()})) :: {get, t()} when get: term() ``` Gets the value from `key` and updates it. Raises if there is no `key`. This `fun` argument receives the value of `key` and must return a two-element tuple: the "get" value (the retrieved value, which can be operated on before being returned) and the new value to be stored under `key`. The returned value is a tuple with the "get" value returned by `fun` and a new keyword list with the updated value under `key`. #### Examples ``` iex> Keyword.get_and_update!([a: 1], :a, fn current_value -> ...> {current_value, "new value!"} ...> end) {1, [a: "new value!"]} iex> Keyword.get_and_update!([a: 1], :b, fn current_value -> ...> {current_value, "new value!"} ...> end) ** (KeyError) key :b not found in: [a: 1] iex> Keyword.get_and_update!([a: 1], :a, fn _ -> ...> :pop ...> end) {1, []} ``` ### get\_lazy(keywords, key, fun) #### Specs ``` get_lazy(t(), key(), (() -> value())) :: value() ``` Gets the value for a specific `key`. If `key` does not exist, lazily evaluates `fun` and returns its result. This is useful if the default value is very expensive to calculate or generally difficult to setup and teardown again. If duplicated entries exist, the first one is returned. Use [`get_values/2`](#get_values/2) to retrieve all entries. #### Examples ``` iex> keyword = [a: 1] iex> fun = fn -> ...> # some expensive operation here ...> 13 ...> end iex> Keyword.get_lazy(keyword, :a, fun) 1 iex> Keyword.get_lazy(keyword, :b, fun) 13 ``` ### get\_values(keywords, key) #### Specs ``` get_values(t(), key()) :: [value()] ``` Gets all values for a specific `key`. #### Examples ``` iex> Keyword.get_values([], :a) [] iex> Keyword.get_values([a: 1], :a) [1] iex> Keyword.get_values([a: 1, a: 2], :a) [1, 2] ``` ### has\_key?(keywords, key) #### Specs ``` has_key?(t(), key()) :: boolean() ``` Returns whether a given `key` exists in the given `keywords`. #### Examples ``` iex> Keyword.has_key?([a: 1], :a) true iex> Keyword.has_key?([a: 1], :b) false ``` ### keys(keywords) #### Specs ``` keys(t()) :: [key()] ``` Returns all keys from the keyword list. Duplicated keys appear duplicated in the final list of keys. #### Examples ``` iex> Keyword.keys(a: 1, b: 2) [:a, :b] iex> Keyword.keys(a: 1, b: 2, a: 3) [:a, :b, :a] ``` ### keyword?(term) #### Specs ``` keyword?(term()) :: boolean() ``` Returns `true` if `term` is a keyword list; otherwise returns `false`. #### Examples ``` iex> Keyword.keyword?([]) true iex> Keyword.keyword?(a: 1) true iex> Keyword.keyword?([{Foo, 1}]) true iex> Keyword.keyword?([{}]) false iex> Keyword.keyword?([:key]) false iex> Keyword.keyword?(%{}) false ``` ### merge(keywords1, keywords2) #### Specs ``` merge(t(), t()) :: t() ``` Merges two keyword lists into one. All keys, including duplicated keys, given in `keywords2` will be added to `keywords1`, overriding any existing one. There are no guarantees about the order of keys in the returned keyword. #### Examples ``` iex> Keyword.merge([a: 1, b: 2], [a: 3, d: 4]) [b: 2, a: 3, d: 4] iex> Keyword.merge([a: 1, b: 2], [a: 3, d: 4, a: 5]) [b: 2, a: 3, d: 4, a: 5] iex> Keyword.merge([a: 1], [2, 3]) ** (ArgumentError) expected a keyword list as the second argument, got: [2, 3] ``` ### merge(keywords1, keywords2, fun) #### Specs ``` merge(t(), t(), (key(), value(), value() -> value())) :: t() ``` Merges two keyword lists into one. All keys, including duplicated keys, given in `keywords2` will be added to `keywords1`. The given function will be invoked to solve conflicts. If `keywords2` has duplicate keys, the given function will be invoked for each matching pair in `keywords1`. There are no guarantees about the order of keys in the returned keyword. #### Examples ``` iex> Keyword.merge([a: 1, b: 2], [a: 3, d: 4], fn _k, v1, v2 -> ...> v1 + v2 ...> end) [b: 2, a: 4, d: 4] iex> Keyword.merge([a: 1, b: 2], [a: 3, d: 4, a: 5], fn :a, v1, v2 -> ...> v1 + v2 ...> end) [b: 2, a: 4, d: 4, a: 5] iex> Keyword.merge([a: 1, b: 2, a: 3], [a: 3, d: 4, a: 5], fn :a, v1, v2 -> ...> v1 + v2 ...> end) [b: 2, a: 4, d: 4, a: 8] iex> Keyword.merge([a: 1, b: 2], [:a, :b], fn :a, v1, v2 -> ...> v1 + v2 ...> end) ** (ArgumentError) expected a keyword list as the second argument, got: [:a, :b] ``` ### new() #### Specs ``` new() :: [] ``` Returns an empty keyword list, i.e. an empty list. #### Examples ``` iex> Keyword.new() [] ``` ### new(pairs) #### Specs ``` new(Enum.t()) :: t() ``` Creates a keyword list from an enumerable. Duplicated entries are removed, the latest one prevails. Unlike `Enum.into(enumerable, [])`, `Keyword.new(enumerable)` guarantees the keys are unique. #### Examples ``` iex> Keyword.new([{:b, 1}, {:a, 2}]) [b: 1, a: 2] iex> Keyword.new([{:a, 1}, {:a, 2}, {:a, 3}]) [a: 3] ``` ### new(pairs, transform) #### Specs ``` new(Enum.t(), (term() -> {key(), value()})) :: t() ``` Creates a keyword list from an enumerable via the transformation function. Duplicated entries are removed, the latest one prevails. Unlike `Enum.into(enumerable, [], fun)`, `Keyword.new(enumerable, fun)` guarantees the keys are unique. #### Examples ``` iex> Keyword.new([:a, :b], fn x -> {x, x} end) [a: :a, b: :b] ``` ### pop(keywords, key, default \\ nil) #### Specs ``` pop(t(), key(), value()) :: {value(), t()} ``` Returns the first value for `key` and removes all associated entries in the keyword list. It returns a tuple where the first element is the first value for `key` and the second element is a keyword list with all entries associated with `key` removed. If the `key` is not present in the keyword list, `{default, keyword_list}` is returned. If you don't want to remove all the entries associated with `key` use [`pop_first/3`](#pop_first/3) instead, that function will remove only the first entry. #### Examples ``` iex> Keyword.pop([a: 1], :a) {1, []} iex> Keyword.pop([a: 1], :b) {nil, [a: 1]} iex> Keyword.pop([a: 1], :b, 3) {3, [a: 1]} iex> Keyword.pop([a: 1, a: 2], :a) {1, []} ``` ### pop\_first(keywords, key, default \\ nil) #### Specs ``` pop_first(t(), key(), value()) :: {value(), t()} ``` Returns and removes the first value associated with `key` in the keyword list. Duplicated keys are not removed. #### Examples ``` iex> Keyword.pop_first([a: 1], :a) {1, []} iex> Keyword.pop_first([a: 1], :b) {nil, [a: 1]} iex> Keyword.pop_first([a: 1], :b, 3) {3, [a: 1]} iex> Keyword.pop_first([a: 1, a: 2], :a) {1, [a: 2]} ``` ### pop\_lazy(keywords, key, fun) #### Specs ``` pop_lazy(t(), key(), (() -> value())) :: {value(), t()} ``` Lazily returns and removes all values associated with `key` in the keyword list. This is useful if the default value is very expensive to calculate or generally difficult to setup and teardown again. All duplicated keys are removed. See [`pop_first/3`](#pop_first/3) for removing only the first entry. #### Examples ``` iex> keyword = [a: 1] iex> fun = fn -> ...> # some expensive operation here ...> 13 ...> end iex> Keyword.pop_lazy(keyword, :a, fun) {1, []} iex> Keyword.pop_lazy(keyword, :b, fun) {13, [a: 1]} ``` ### put(keywords, key, value) #### Specs ``` put(t(), key(), value()) :: t() ``` Puts the given `value` under `key`. If a previous value is already stored, all entries are removed and the value is overridden. #### Examples ``` iex> Keyword.put([a: 1], :b, 2) [b: 2, a: 1] iex> Keyword.put([a: 1, b: 2], :a, 3) [a: 3, b: 2] iex> Keyword.put([a: 1, b: 2, a: 4], :a, 3) [a: 3, b: 2] ``` ### put\_new(keywords, key, value) #### Specs ``` put_new(t(), key(), value()) :: t() ``` Puts the given `value` under `key` unless the entry `key` already exists. #### Examples ``` iex> Keyword.put_new([a: 1], :b, 2) [b: 2, a: 1] iex> Keyword.put_new([a: 1, b: 2], :a, 3) [a: 1, b: 2] ``` ### put\_new\_lazy(keywords, key, fun) #### Specs ``` put_new_lazy(t(), key(), (() -> value())) :: t() ``` Evaluates `fun` and puts the result under `key` in keyword list unless `key` is already present. This is useful if the value is very expensive to calculate or generally difficult to setup and teardown again. #### Examples ``` iex> keyword = [a: 1] iex> fun = fn -> ...> # some expensive operation here ...> 3 ...> end iex> Keyword.put_new_lazy(keyword, :a, fun) [a: 1] iex> Keyword.put_new_lazy(keyword, :b, fun) [b: 3, a: 1] ``` ### replace!(keywords, key, value) #### Specs ``` replace!(t(), key(), value()) :: t() ``` Alters the value stored under `key` to `value`, but only if the entry `key` already exists in `keywords`. If `key` is not present in `keywords`, a [`KeyError`](keyerror) exception is raised. #### Examples ``` iex> Keyword.replace!([a: 1, b: 2, a: 4], :a, 3) [a: 3, b: 2] iex> Keyword.replace!([a: 1], :b, 2) ** (KeyError) key :b not found in: [a: 1] ``` ### split(keywords, keys) #### Specs ``` split(t(), [key()]) :: {t(), t()} ``` Takes all entries corresponding to the given keys and extracts them into a separate keyword list. Returns a tuple with the new list and the old list with removed keys. Keys for which there are no entries in the keyword list are ignored. Entries with duplicated keys end up in the same keyword list. #### Examples ``` iex> Keyword.split([a: 1, b: 2, c: 3], [:a, :c, :e]) {[a: 1, c: 3], [b: 2]} iex> Keyword.split([a: 1, b: 2, c: 3, a: 4], [:a, :c, :e]) {[a: 1, c: 3, a: 4], [b: 2]} ``` ### take(keywords, keys) #### Specs ``` take(t(), [key()]) :: t() ``` Takes all entries corresponding to the given keys and returns them in a new keyword list. Duplicated keys are preserved in the new keyword list. #### Examples ``` iex> Keyword.take([a: 1, b: 2, c: 3], [:a, :c, :e]) [a: 1, c: 3] iex> Keyword.take([a: 1, b: 2, c: 3, a: 5], [:a, :c, :e]) [a: 1, c: 3, a: 5] ``` ### to\_list(keyword) #### Specs ``` to_list(t()) :: t() ``` Returns the keyword list itself. #### Examples ``` iex> Keyword.to_list(a: 1) [a: 1] ``` ### update(keywords, key, initial, fun) #### Specs ``` update(t(), key(), value(), (value() -> value())) :: t() ``` Updates the `key` in `keywords` with the given function. If the `key` does not exist, inserts the given `initial` value. If there are duplicated keys, they are all removed and only the first one is updated. #### Examples ``` iex> Keyword.update([a: 1], :a, 13, &(&1 * 2)) [a: 2] iex> Keyword.update([a: 1, a: 2], :a, 13, &(&1 * 2)) [a: 2] iex> Keyword.update([a: 1], :b, 11, &(&1 * 2)) [a: 1, b: 11] ``` ### update!(keywords, key, fun) #### Specs ``` update!(t(), key(), (value() -> value())) :: t() ``` Updates the `key` with the given function. If the `key` does not exist, raises [`KeyError`](keyerror). If there are duplicated keys, they are all removed and only the first one is updated. #### Examples ``` iex> Keyword.update!([a: 1], :a, &(&1 * 2)) [a: 2] iex> Keyword.update!([a: 1, a: 2], :a, &(&1 * 2)) [a: 2] iex> Keyword.update!([a: 1], :b, &(&1 * 2)) ** (KeyError) key :b not found in: [a: 1] ``` ### values(keywords) #### Specs ``` values(t()) :: [value()] ``` Returns all values from the keyword list. Values from duplicated keys will be kept in the final list of values. #### Examples ``` iex> Keyword.values(a: 1, b: 2) [1, 2] iex> Keyword.values(a: 1, b: 2, a: 3) [1, 2, 3] ```
programming_docs
elixir ExUnit.CaseTemplate ExUnit.CaseTemplate ==================== This module allows a developer to define a test case template to be used throughout their tests. This is useful when there are a set of functions that should be shared between tests or a set of setup callbacks. By using this module, the callbacks and assertions available for regular test cases will also be available. Example -------- ``` defmodule MyCase do use ExUnit.CaseTemplate setup do IO.puts("This will run before each test that uses this case") end end defmodule MyTest do use MyCase, async: true test "truth" do assert true end end ``` Summary ======== Functions ---------- [using(var \\ quote do \_ end, list)](#using/2) Allows a developer to customize the using block when the case template is used. Functions ========== ### using(var \\ quote do \_ end, list) Allows a developer to customize the using block when the case template is used. #### Example ``` defmodule MyCase do use ExUnit.CaseTemplate using do quote do # This code is injected into every case that calls "use MyCase" alias MyApp.FunModule end end end ``` elixir Function Function ========= A set of functions for working with functions. There are two types of captured functions: **external** and **local**. External functions are functions residing in modules that are captured with [`&/1`](kernel.specialforms#&/1), such as `&String.length/1`. Local functions are anonymous functions defined with [`fn/1`](kernel.specialforms#fn/1) or with the capture operator [`&/1`](kernel.specialforms#&/1) using `&1`, `&2`, and so on as replacements. Summary ======== Types ------ [information()](#t:information/0) Functions ---------- [capture(module, function\_name, arity)](#capture/3) Captures the given function. [info(fun)](#info/1) Returns a keyword list with information about a function. [info(fun, item)](#info/2) Returns a specific information about the function. Types ====== ### information() #### Specs ``` information() :: :arity | :env | :index | :module | :name | :new_index | :new_uniq | :pid | :type | :uniq ``` Functions ========== ### capture(module, function\_name, arity) #### Specs ``` capture(module(), atom(), arity()) :: (... -> any()) ``` Captures the given function. Inlined by the compiler. #### Examples ``` iex> Function.capture(String, :length, 1) &String.length/1 ``` ### info(fun) #### Specs ``` info((... -> any())) :: [{information(), term()}] ``` Returns a keyword list with information about a function. The returned keys (with the corresponding possible values) for all types of functions (local and external) are the following: * `:type` - `:local` (for anonymous functions) or `:external` (for named functions). * `:module` - an atom which is the module where the function is defined when anonymous or the module which the function refers to when it's a named function. * `:arity` - (integer) the number of arguments the function is to be called with. * `:name` - (atom) the name of the function. * `:env` - a list of the environment or free variables. For named functions, the returned list is always empty. When `fun` is an anonymous function (that is, the type is `:local`), the following additional keys are returned: * `:pid` - PID of the process that originally created the function. * `:index` - (integer) an index into the module function table. * `:new_index` - (integer) an index into the module function table. * `:new_uniq` - (binary) a unique value for this function. It's calculated from the compiled code for the entire module. * `:uniq` - (integer) a unique value for this function. This integer is calculated from the compiled code for the entire module. **Note**: this function must be used only for debugging purposes. Inlined by the compiler. #### Examples ``` iex> fun = fn x -> x end iex> info = Function.info(fun) iex> Keyword.get(info, :arity) 1 iex> Keyword.get(info, :type) :local iex> fun = &String.length/1 iex> info = Function.info(fun) iex> Keyword.get(info, :type) :external iex> Keyword.get(info, :name) :length ``` ### info(fun, item) #### Specs ``` info((... -> any()), item) :: {item, term()} when item: information() ``` Returns a specific information about the function. The returned information is a two-element tuple in the shape of `{info, value}`. For any function, the information asked for can be any of the atoms `:module`, `:name`, `:arity`, `:env`, or `:type`. For anonymous functions, there is also information about any of the atoms `:index`, `:new_index`, `:new_uniq`, `:uniq`, and `:pid`. For a named function, the value of any of these items is always the atom `:undefined`. For more information on each of the possible returned values, see [`info/1`](#info/1). Inlined by the compiler. #### Examples ``` iex> f = fn x -> x end iex> Function.info(f, :arity) {:arity, 1} iex> Function.info(f, :type) {:type, :local} iex> fun = &String.length/1 iex> Function.info(fun, :name) {:name, :length} iex> Function.info(fun, :pid) {:pid, :undefined} ``` elixir MapSet MapSet ======= Functions that work on sets. [`MapSet`](#content) is the "go to" set data structure in Elixir. A set can be constructed using [`MapSet.new/0`](mapset#new/0): ``` iex> MapSet.new() #MapSet<[]> ``` A set can contain any kind of elements, and elements in a set don't have to be of the same type. By definition, sets can't contain duplicate elements: when inserting an element in a set where it's already present, the insertion is simply a no-op. ``` iex> map_set = MapSet.new() iex> MapSet.put(map_set, "foo") #MapSet<["foo"]> iex> map_set |> MapSet.put("foo") |> MapSet.put("foo") #MapSet<["foo"]> ``` A [`MapSet`](#content) is represented internally using the `%MapSet{}` struct. This struct can be used whenever there's a need to pattern match on something being a [`MapSet`](#content): ``` iex> match?(%MapSet{}, MapSet.new()) true ``` Note that, however, the struct fields are private and must not be accessed directly; use the functions in this module to perform operations on sets. [`MapSet`](#content)s can also be constructed starting from other collection-type data structures: for example, see [`MapSet.new/1`](mapset#new/1) or [`Enum.into/2`](enum#into/2). [`MapSet`](#content) is built on top of [`Map`](map), this means that they share many properties, including logarithmic time complexity. See the documentation for [`Map`](map) for more information on its execution time complexity. Summary ======== Types ------ [t()](#t:t/0) [t(value)](#t:t/1) [value()](#t:value/0) Functions ---------- [delete(map\_set, value)](#delete/2) Deletes `value` from `map_set`. [difference(map\_set1, map\_set2)](#difference/2) Returns a set that is `map_set1` without the members of `map_set2`. [disjoint?(map\_set1, map\_set2)](#disjoint?/2) Checks if `map_set1` and `map_set2` have no members in common. [equal?(map\_set1, map\_set2)](#equal?/2) Checks if two sets are equal. [intersection(map\_set, map\_set)](#intersection/2) Returns a set containing only members that `map_set1` and `map_set2` have in common. [member?(map\_set, value)](#member?/2) Checks if `map_set` contains `value`. [new()](#new/0) Returns a new set. [new(enumerable)](#new/1) Creates a set from an enumerable. [new(enumerable, transform)](#new/2) Creates a set from an enumerable via the transformation function. [put(map\_set, value)](#put/2) Inserts `value` into `map_set` if `map_set` doesn't already contain it. [size(map\_set)](#size/1) Returns the number of elements in `map_set`. [subset?(map\_set1, map\_set2)](#subset?/2) Checks if `map_set1`'s members are all contained in `map_set2`. [to\_list(map\_set)](#to_list/1) Converts `map_set` to a list. [union(map\_set1, map\_set2)](#union/2) Returns a set containing all members of `map_set1` and `map_set2`. Types ====== ### t() #### Specs ``` t() :: t(term()) ``` ### t(value) #### Specs ``` t(value) ``` ### value() #### Specs ``` value() :: term() ``` Functions ========== ### delete(map\_set, value) #### Specs ``` delete(t(val1), val2) :: t(val1) when val1: value(), val2: value() ``` Deletes `value` from `map_set`. Returns a new set which is a copy of `map_set` but without `value`. #### Examples ``` iex> map_set = MapSet.new([1, 2, 3]) iex> MapSet.delete(map_set, 4) #MapSet<[1, 2, 3]> iex> MapSet.delete(map_set, 2) #MapSet<[1, 3]> ``` ### difference(map\_set1, map\_set2) #### Specs ``` difference(t(val1), t(val2)) :: t(val1) when val1: value(), val2: value() ``` Returns a set that is `map_set1` without the members of `map_set2`. #### Examples ``` iex> MapSet.difference(MapSet.new([1, 2]), MapSet.new([2, 3, 4])) #MapSet<[1]> ``` ### disjoint?(map\_set1, map\_set2) #### Specs ``` disjoint?(t(), t()) :: boolean() ``` Checks if `map_set1` and `map_set2` have no members in common. #### Examples ``` iex> MapSet.disjoint?(MapSet.new([1, 2]), MapSet.new([3, 4])) true iex> MapSet.disjoint?(MapSet.new([1, 2]), MapSet.new([2, 3])) false ``` ### equal?(map\_set1, map\_set2) #### Specs ``` equal?(t(), t()) :: boolean() ``` Checks if two sets are equal. The comparison between elements must be done using [`===/2`](kernel#===/2). #### Examples ``` iex> MapSet.equal?(MapSet.new([1, 2]), MapSet.new([2, 1, 1])) true iex> MapSet.equal?(MapSet.new([1, 2]), MapSet.new([3, 4])) false ``` ### intersection(map\_set, map\_set) #### Specs ``` intersection(t(val), t(val)) :: t(val) when val: value() ``` Returns a set containing only members that `map_set1` and `map_set2` have in common. #### Examples ``` iex> MapSet.intersection(MapSet.new([1, 2]), MapSet.new([2, 3, 4])) #MapSet<[2]> iex> MapSet.intersection(MapSet.new([1, 2]), MapSet.new([3, 4])) #MapSet<[]> ``` ### member?(map\_set, value) #### Specs ``` member?(t(), value()) :: boolean() ``` Checks if `map_set` contains `value`. #### Examples ``` iex> MapSet.member?(MapSet.new([1, 2, 3]), 2) true iex> MapSet.member?(MapSet.new([1, 2, 3]), 4) false ``` ### new() #### Specs ``` new() :: t() ``` Returns a new set. #### Examples ``` iex> MapSet.new() #MapSet<[]> ``` ### new(enumerable) #### Specs ``` new(Enum.t()) :: t() ``` Creates a set from an enumerable. #### Examples ``` iex> MapSet.new([:b, :a, 3]) #MapSet<[3, :a, :b]> iex> MapSet.new([3, 3, 3, 2, 2, 1]) #MapSet<[1, 2, 3]> ``` ### new(enumerable, transform) #### Specs ``` new(Enum.t(), (term() -> val)) :: t(val) when val: value() ``` Creates a set from an enumerable via the transformation function. #### Examples ``` iex> MapSet.new([1, 2, 1], fn x -> 2 * x end) #MapSet<[2, 4]> ``` ### put(map\_set, value) #### Specs ``` put(t(val), new_val) :: t(val | new_val) when val: value(), new_val: value() ``` Inserts `value` into `map_set` if `map_set` doesn't already contain it. #### Examples ``` iex> MapSet.put(MapSet.new([1, 2, 3]), 3) #MapSet<[1, 2, 3]> iex> MapSet.put(MapSet.new([1, 2, 3]), 4) #MapSet<[1, 2, 3, 4]> ``` ### size(map\_set) #### Specs ``` size(t()) :: non_neg_integer() ``` Returns the number of elements in `map_set`. #### Examples ``` iex> MapSet.size(MapSet.new([1, 2, 3])) 3 ``` ### subset?(map\_set1, map\_set2) #### Specs ``` subset?(t(), t()) :: boolean() ``` Checks if `map_set1`'s members are all contained in `map_set2`. This function checks if `map_set1` is a subset of `map_set2`. #### Examples ``` iex> MapSet.subset?(MapSet.new([1, 2]), MapSet.new([1, 2, 3])) true iex> MapSet.subset?(MapSet.new([1, 2, 3]), MapSet.new([1, 2])) false ``` ### to\_list(map\_set) #### Specs ``` to_list(t(val)) :: [val] when val: value() ``` Converts `map_set` to a list. #### Examples ``` iex> MapSet.to_list(MapSet.new([1, 2, 3])) [1, 2, 3] ``` ### union(map\_set1, map\_set2) #### Specs ``` union(t(val1), t(val2)) :: t(val1 | val2) when val1: value(), val2: value() ``` Returns a set containing all members of `map_set1` and `map_set2`. #### Examples ``` iex> MapSet.union(MapSet.new([1, 2]), MapSet.new([2, 3, 4])) #MapSet<[1, 2, 3, 4]> ``` elixir mix profile.eprof mix profile.eprof ================== Profiles the given file or expression using Erlang's `eprof` tool. `:eprof` provides time information of each function call and can be useful when you want to discover the bottlenecks related to this. Before running the code, it invokes the `app.start` task which compiles and loads your project. Then the target expression is profiled, together with all matching function calls using the Erlang trace BIFs. The tracing of the function calls for that is enabled when the profiling is begun, and disabled when profiling is stopped. To profile the code, you can use syntax similar to the [`mix run`](mix.tasks.run) task: ``` mix profile.eprof -e Hello.world mix profile.eprof -e "[1, 2, 3] |> Enum.reverse |> Enum.map(&Integer.to_string/1)" mix profile.eprof my_script.exs arg1 arg2 arg3 ``` This task is automatically reenabled, so you can profile multiple times in the same Mix invocation. Command line options --------------------- * `--matching` - only profile calls matching the given `Module.function/arity` pattern * `--calls` - filters out any results with a call count lower than this * `--time` - filters out any results that took lower than specified (in µs) * `--sort` - sorts the results by `time` or `calls` (default: `time`) * `--eval`, `-e` - evaluates the given code * `--require`, `-r` - requires pattern before running the command * `--parallel`, `-p` - makes all requires parallel * `--no-warmup` - skips the warmup step before profiling * `--no-compile` - does not compile even if files require compilation * `--no-deps-check` - does not check dependencies * `--no-archives-check` - does not check archives * `--no-halt` - does not halt the system after running the command * `--no-start` - does not start applications after compilation * `--no-elixir-version-check` - does not check the Elixir version from mix.exs Profile output --------------- Example output: ``` # CALLS % TIME µS/CALL Total 24 100.0 26 1.08 Enum.reduce_range_inc/4 5 3.85 1 0.20 :erlang.make_fun/3 1 7.69 2 2.00 Enum.each/2 1 7.69 2 2.00 anonymous fn/0 in :elixir_compiler_0.__FILE__/1 1 7.69 2 2.00 :erlang.integer_to_binary/1 5 15.39 4 0.80 :erlang.apply/2 1 15.39 4 4.00 anonymous fn/3 in Enum.each/2 5 19.23 5 1.00 String.Chars.Integer.to_string/1 5 23.08 6 1.20 Profile done over 8 matching functions ``` The default output contains data gathered from all matching functions. The first row after the header contains the sums of the partial results and the average time for all the function calls listed. The following rows contain the function call, followed by the number of times that the function was called, then by the percentage of time that the call uses, then the total time for that function in microseconds, and, finally, the average time per call in microseconds. When `--matching` option is specified, call count tracing will be started only for the functions matching the given pattern: ``` # CALLS % TIME µS/CALL Total 5 100.0 6 1.20 String.Chars.Integer.to_string/1 5 100.0 6 1.20 Profile done over 1 matching functions ``` The pattern can be a module name, such as [`String`](https://hexdocs.pm/elixir/String.html) to count all calls to that module, a call without arity, such as `String.split`, to count all calls to that function regardless of arity, or a call with arity, such as [`String.split/2`](https://hexdocs.pm/elixir/String.html#split/2), to count all calls to that exact module, function and arity. Caveats -------- You should be aware that the code being profiled is running in an anonymous function which is invoked by [`:eprof` module](http://wwww.erlang.org/doc/man/eprof.html). Thus, you'll see some additional entries in your profile output. It is also important to notice that the profiler is stopped as soon as the code has finished running, and this may need special attention, when: running asynchronous code as function calls which were called before the profiler stopped will not be counted; running synchronous code as long running computations and a profiler without a proper MFA trace pattern or filter may lead to a result set which is difficult to comprehend. You should expect a slowdown in your code execution using this tool since `:eprof` has some performance impact on the execution, but the impact is considerably lower than [`Mix.Tasks.Profile.Fprof`](mix.tasks.profile.fprof). If you have a large system try to profile a limited scenario or focus on the main modules or processes. Another alternative is to use [`Mix.Tasks.Profile.Cprof`](mix.tasks.profile.cprof) that uses `:cprof` and has a low performance degradation effect. Summary ======== Functions ---------- [profile(fun, opts \\ [])](#profile/2) Allows to programmatically run the `eprof` profiler on expression in `fun`. Functions ========== ### profile(fun, opts \\ []) Allows to programmatically run the `eprof` profiler on expression in `fun`. #### Options * `:matching` - only profile calls matching the given pattern in form of `{module, function, arity}`, where each element may be replaced by `:_` to allow any value * `:calls` - filters out any results with a call count lower than this * `:time` - filters out any results that took lower than specified (in µs) * `:sort` - sort the results by `:time` or `:calls` (default: `:time`) elixir Version.Requirement Version.Requirement ==================== A struct that holds version requirement information. The struct fields are private and should not be accessed. See the "Requirements" section in the [`Version`](version) module for more information. Summary ======== Types ------ [t()](#t:t/0) Types ====== ### t() #### Specs ``` t() ``` elixir Modules and functions Getting Started Modules and functions ===================== In Elixir we group several functions into modules. We’ve already used many different modules in the previous chapters such as [the `String` module](https://hexdocs.pm/elixir/String.html): ``` iex> String.length("hello") 5 ``` In order to create our own modules in Elixir, we use the `defmodule` macro. We use the `def` macro to define functions in that module: ``` iex> defmodule Math do ...> def sum(a, b) do ...> a + b ...> end ...> end iex> Math.sum(1, 2) 3 ``` In the following sections, our examples are going to get longer in size, and it can be tricky to type them all in the shell. It’s about time for us to learn how to compile Elixir code and also how to run Elixir scripts. Compilation ----------- Most of the time it is convenient to write modules into files so they can be compiled and reused. Let’s assume we have a file named `math.ex` with the following contents: ``` defmodule Math do def sum(a, b) do a + b end end ``` This file can be compiled using `elixirc`: ``` $ elixirc math.ex ``` This will generate a file named `Elixir.Math.beam` containing the bytecode for the defined module. If we start `iex` again, our module definition will be available (provided that `iex` is started in the same directory the bytecode file is in): ``` iex> Math.sum(1, 2) 3 ``` Elixir projects are usually organized into three directories: * ebin - contains the compiled bytecode * lib - contains elixir code (usually `.ex` files) * test - contains tests (usually `.exs` files) When working on actual projects, the build tool called `mix` will be responsible for compiling and setting up the proper paths for you. For learning purposes, Elixir also supports a scripted mode which is more flexible and does not generate any compiled artifacts. Scripted mode ------------- In addition to the Elixir file extension `.ex`, Elixir also supports `.exs` files for scripting. Elixir treats both files exactly the same way, the only difference is in intention. `.ex` files are meant to be compiled while `.exs` files are used for scripting. When executed, both extensions compile and load their modules into memory, although only `.ex` files write their bytecode to disk in the format of `.beam` files. For instance, we can create a file called `math.exs`: ``` defmodule Math do def sum(a, b) do a + b end end IO.puts Math.sum(1, 2) ``` And execute it as: ``` $ elixir math.exs ``` The file will be compiled in memory and executed, printing “3” as the result. No bytecode file will be created. In the following examples, we recommend you write your code into script files and execute them as shown above. Named functions --------------- Inside a module, we can define functions with `def/2` and private functions with `defp/2`. A function defined with `def/2` can be invoked from other modules while a private function can only be invoked locally. ``` defmodule Math do def sum(a, b) do do_sum(a, b) end defp do_sum(a, b) do a + b end end IO.puts Math.sum(1, 2) #=> 3 IO.puts Math.do_sum(1, 2) #=> ** (UndefinedFunctionError) ``` Function declarations also support guards and multiple clauses. If a function has several clauses, Elixir will try each clause until it finds one that matches. Here is an implementation of a function that checks if the given number is zero or not: ``` defmodule Math do def zero?(0) do true end def zero?(x) when is_integer(x) do false end end IO.puts Math.zero?(0) #=> true IO.puts Math.zero?(1) #=> false IO.puts Math.zero?([1, 2, 3]) #=> ** (FunctionClauseError) IO.puts Math.zero?(0.0) #=> ** (FunctionClauseError) ``` *The trailing question mark in `zero?` means that this function returns a boolean; see [Naming Conventions](https://hexdocs.pm/elixir/master/naming-conventions.html#trailing-question-mark-foo).* Giving an argument that does not match any of the clauses raises an error. Similar to constructs like `if`, named functions support both `do:` and `do`/`end` block syntax, as [we learned `do`/`end` is a convenient syntax for the keyword list format](case-cond-and-if#doend-blocks). For example, we can edit `math.exs` to look like this: ``` defmodule Math do def zero?(0), do: true def zero?(x) when is_integer(x), do: false end ``` And it will provide the same behaviour. You may use `do:` for one-liners but always use `do`/`end` for functions spanning multiple lines. Function capturing ------------------ Throughout this tutorial, we have been using the notation `name/arity` to refer to functions. It happens that this notation can actually be used to retrieve a named function as a function type. Start `iex`, running the `math.exs` file defined above: ``` $ iex math.exs ``` ``` iex> Math.zero?(0) true iex> fun = &Math.zero?/1 &Math.zero?/1 iex> is_function(fun) true iex> fun.(0) true ``` Remember Elixir makes a distinction between anonymous functions and named functions, where the former must be invoked with a dot (`.`) between the variable name and parentheses. The capture operator bridges this gap by allowing named functions to be assigned to variables and passed as arguments in the same way we assign, invoke and pass anonymous functions. Local or imported functions, like `is_function/1`, can be captured without the module: ``` iex> &is_function/1 &:erlang.is_function/1 iex> (&is_function/1).(fun) true ``` Note the capture syntax can also be used as a shortcut for creating functions: ``` iex> fun = &(&1 + 1) #Function<6.71889879/1 in :erl_eval.expr/5> iex> fun.(1) 2 iex> fun2 = &"Good #{&1}" #Function<6.127694169/1 in :erl_eval.expr/5> iex)> fun2.("morning") "Good morning" ``` The `&1` represents the first argument passed into the function. `&(&1 + 1)` above is exactly the same as `fn x -> x + 1 end`. The syntax above is useful for short function definitions. If you want to capture a function from a module, you can do `&Module.function()`: ``` iex> fun = &List.flatten(&1, &2) &List.flatten/2 iex> fun.([1, [[2], 3]], [4, 5]) [1, 2, 3, 4, 5] ``` `&List.flatten(&1, &2)` is the same as writing `fn(list, tail) -> List.flatten(list, tail) end` which in this case is equivalent to `&List.flatten/2`. You can read more about the capture operator `&` in [the `Kernel.SpecialForms` documentation](https://hexdocs.pm/elixir/Kernel.SpecialForms.html#&/1). Default arguments ----------------- Named functions in Elixir also support default arguments: ``` defmodule Concat do def join(a, b, sep \\ " ") do a <> sep <> b end end IO.puts Concat.join("Hello", "world") #=> Hello world IO.puts Concat.join("Hello", "world", "_") #=> Hello_world ``` Any expression is allowed to serve as a default value, but it won’t be evaluated during the function definition. Every time the function is invoked and any of its default values have to be used, the expression for that default value will be evaluated: ``` defmodule DefaultTest do def dowork(x \\ "hello") do x end end ``` ``` iex> DefaultTest.dowork "hello" iex> DefaultTest.dowork 123 123 iex> DefaultTest.dowork "hello" ``` If a function with default values has multiple clauses, it is required to create a function head (without an actual body) for declaring defaults: ``` defmodule Concat do # A function head declaring defaults def join(a, b \\ nil, sep \\ " ") def join(a, b, _sep) when is_nil(b) do a end def join(a, b, sep) do a <> sep <> b end end IO.puts Concat.join("Hello", "world") #=> Hello world IO.puts Concat.join("Hello", "world", "_") #=> Hello_world IO.puts Concat.join("Hello") #=> Hello ``` *The leading underscore in `_sep` means that the variable will be ignored in this function; see [Naming Conventions](https://hexdocs.pm/elixir/master/naming-conventions.html#underscore-_foo).* When using default values, one must be careful to avoid overlapping function definitions. Consider the following example: ``` defmodule Concat do def join(a, b) do IO.puts "***First join" a <> b end def join(a, b, sep \\ " ") do IO.puts "***Second join" a <> sep <> b end end ``` If we save the code above in a file named “concat.ex” and compile it, Elixir will emit the following warning: ``` warning: this clause cannot match because a previous clause at line 2 always matches ``` The compiler is telling us that invoking the `join` function with two arguments will always choose the first definition of `join` whereas the second one will only be invoked when three arguments are passed: ``` $ iex concat.ex ``` ``` iex> Concat.join "Hello", "world" ***First join "Helloworld" ``` ``` iex> Concat.join "Hello", "world", "_" ***Second join "Hello_world" ``` This finishes our short introduction to modules. In the next chapters, we will learn how to use named functions for recursion, explore Elixir lexical directives that can be used for importing functions from other modules and discuss module attributes.
programming_docs
elixir mix loadconfig mix loadconfig =============== Loads and persists the given configuration. If no configuration file is given, it loads the project's configuration file, "config/config.exs", if it exists. Keep in mind that the "config/config.exs" file is always loaded by the CLI and invoking it is only required in cases you are starting Mix manually. This task is automatically reenabled, so it can be called multiple times to load different configs. elixir EEx.Engine behaviour EEx.Engine behaviour ===================== Basic EEx engine that ships with Elixir. An engine needs to implement all callbacks below. An engine may also `use EEx.Engine` to get the default behaviour but this is not advised. In such cases, if any of the callbacks are overridden, they must call `super()` to delegate to the underlying [`EEx.Engine`](#content). Summary ======== Types ------ [state()](#t:state/0) Functions ---------- [handle\_assign(arg)](#handle_assign/1) Handles assigns in quoted expressions. Callbacks ---------- [handle\_begin(state)](#c:handle_begin/1) Invoked at the beginning of every nesting. [handle\_body(state)](#c:handle_body/1) Called at the end of every template. [handle\_end(state)](#c:handle_end/1) Invokes at the end of a nesting. [handle\_expr(state, marker, expr)](#c:handle_expr/3) Called for the dynamic/code parts of a template. [handle\_text(state, text)](#c:handle_text/2) Called for the text/static parts of a template. [init(opts)](#c:init/1) Called at the beginning of every template. Types ====== ### state() #### Specs ``` state() :: term() ``` Functions ========== ### handle\_assign(arg) #### Specs ``` handle_assign(Macro.t()) :: Macro.t() ``` Handles assigns in quoted expressions. A warning will be printed on missing assigns. Future versions will raise. This can be added to any custom engine by invoking [`handle_assign/1`](#handle_assign/1) with [`Macro.prewalk/2`](https://hexdocs.pm/elixir/Macro.html#prewalk/2): ``` def handle_expr(state, token, expr) do expr = Macro.prewalk(expr, &EEx.Engine.handle_assign/1) super(state, token, expr) end ``` Callbacks ========== ### handle\_begin(state) #### Specs ``` handle_begin(state()) :: state() ``` Invoked at the beginning of every nesting. It must return a new state that is used only inside the nesting. Once the nesting terminates, the current `state` is resumed. ### handle\_body(state) #### Specs ``` handle_body(state()) :: Macro.t() ``` Called at the end of every template. It must return Elixir's quoted expressions for the template. ### handle\_end(state) #### Specs ``` handle_end(state()) :: Macro.t() ``` Invokes at the end of a nesting. It must return Elixir's quoted expressions for the nesting. ### handle\_expr(state, marker, expr) #### Specs ``` handle_expr(state(), marker :: String.t(), expr :: Macro.t()) :: state() ``` Called for the dynamic/code parts of a template. The marker is what follows exactly after `<%`. For example, `<% foo %>` has an empty marker, but `<%= foo %>` has `"="` as marker. The allowed markers so far are: * `""` * `"="` * `"/"` * `"|"` Markers `"/"` and `"|"` are only for use in custom EEx engines and are not implemented by default. Using them without an appropriate implementation raises [`EEx.SyntaxError`](eex.syntaxerror). It must return the updated state. ### handle\_text(state, text) #### Specs ``` handle_text(state(), text :: String.t()) :: state() ``` Called for the text/static parts of a template. It must return the updated state. ### init(opts) #### Specs ``` init(opts :: keyword()) :: state() ``` Called at the beginning of every template. It must return the initial state. elixir EEx.SmartEngine EEx.SmartEngine ================ The default engine used by EEx. It includes assigns (like `@foo`) and possibly other conveniences in the future. Examples --------- ``` iex> EEx.eval_string("<%= @foo %>", assigns: [foo: 1]) "1" ``` In the example above, we can access the value `foo` under the binding `assigns` using `@foo`. This is useful because a template, after being compiled, can receive different assigns and would not require recompilation for each variable set. Assigns can also be used when compiled to a function: ``` # sample.eex <%= @a + @b %> # sample.ex defmodule Sample do require EEx EEx.function_from_file(:def, :sample, "sample.eex", [:assigns]) end # iex Sample.sample(a: 1, b: 2) #=> "3" ``` Summary ======== Functions ---------- [handle\_begin(state)](#handle_begin/1) Callback implementation for [`EEx.Engine.handle_begin/1`](eex.engine#c:handle_begin/1). [handle\_body(state)](#handle_body/1) Callback implementation for [`EEx.Engine.handle_body/1`](eex.engine#c:handle_body/1). [handle\_end(state)](#handle_end/1) Callback implementation for [`EEx.Engine.handle_end/1`](eex.engine#c:handle_end/1). [handle\_expr(state, marker, expr)](#handle_expr/3) Callback implementation for [`EEx.Engine.handle_expr/3`](eex.engine#c:handle_expr/3). [handle\_text(state, text)](#handle_text/2) Callback implementation for [`EEx.Engine.handle_text/2`](eex.engine#c:handle_text/2). [init(opts)](#init/1) Callback implementation for [`EEx.Engine.init/1`](eex.engine#c:init/1). Functions ========== ### handle\_begin(state) Callback implementation for [`EEx.Engine.handle_begin/1`](eex.engine#c:handle_begin/1). ### handle\_body(state) Callback implementation for [`EEx.Engine.handle_body/1`](eex.engine#c:handle_body/1). ### handle\_end(state) Callback implementation for [`EEx.Engine.handle_end/1`](eex.engine#c:handle_end/1). ### handle\_expr(state, marker, expr) Callback implementation for [`EEx.Engine.handle_expr/3`](eex.engine#c:handle_expr/3). ### handle\_text(state, text) Callback implementation for [`EEx.Engine.handle_text/2`](eex.engine#c:handle_text/2). ### init(opts) Callback implementation for [`EEx.Engine.init/1`](eex.engine#c:init/1). elixir mix escript.build mix escript.build ================== Builds an escript for the project. An escript is an executable that can be invoked from the command line. An escript can run on any machine that has Erlang/OTP installed and by default does not require Elixir to be installed, as Elixir is embedded as part of the escript. This task guarantees the project and its dependencies are compiled and packages them inside an escript. Before invoking [`mix escript.build`](#content), it is only necessary to define a `:escript` key with a `:main_module` option in your `mix.exs` file: ``` escript: [main_module: MyApp.CLI] ``` Escripts should be used as a mechanism to share scripts between developers and not as a deployment mechanism. For running live systems, consider using [`mix run`](mix.tasks.run) or building releases. See the [`Application`](https://hexdocs.pm/elixir/Application.html) module for more information on systems life-cycles. By default, this task starts the current application. If this is not desired, set the `:app` configuration to nil. This task also removes documentation and debugging chunks from the compiled `.beam` files to reduce the size of the escript. If this is not desired, check the `:strip_beams` option. > > Note: escripts do not support projects and dependencies that need to store or read artifacts from the priv directory. > > Command line options --------------------- Expects the same command line options as [`mix compile`](mix.tasks.compile). Configuration -------------- The following option must be specified in your `mix.exs` under `:escript` key: * `:main_module` - the module to be invoked once the escript starts. The module must contain a function named `main/1` that will receive the command line arguments as binaries. The remaining options can be specified to further customize the escript: * `:name` - the name of the generated escript. Defaults to app name. * `:path` - the path to write the escript to. Defaults to app name. * `:app` - the app that starts with the escript. Defaults to app name. Set it to `nil` if no application should be started. * `:strip_beam` - if `true` strips BEAM code in the escript to remove chunks unnecessary at runtime, such as debug information and documentation. Defaults to `true`. * `:embed_elixir` - if `true` embeds Elixir and its children apps (`ex_unit`, `mix`, etc.) mentioned in the `:applications` list inside the `application/0` function in `mix.exs`. Defaults to `true` for Elixir projects, `false` for Erlang projects. Note: if you set this to `false` for an Elixir project, you will have to add paths to Elixir's `ebin` directories to `ERL_LIBS` environment variable when running the resulting escript, in order for the code loader to be able to find `:elixir` application and its children applications (if they are used). * `:shebang` - shebang interpreter directive used to execute the escript. Defaults to `"#! /usr/bin/env escript\n"`. * `:comment` - comment line to follow shebang directive in the escript. Defaults to `""`. * `:emu_args` - emulator arguments to embed in the escript file. Defaults to `""`. There is one project-level option that affects how the escript is generated: * `language: :elixir | :erlang` - set it to `:erlang` for Erlang projects managed by Mix. Doing so will ensure Elixir is not embedded by default. Your app will still be started as part of escript loading, with the config used during build. Example -------- ``` defmodule MyApp.MixProject do use Mix.Project def project do [ app: :my_app, version: "0.0.1", escript: escript() ] end def escript do [main_module: MyApp.CLI] end end defmodule MyApp.CLI do def main(_args) do IO.puts("Hello from MyApp!") end end ``` elixir mix clean mix clean ========== Deletes generated application files. This command deletes all build artifacts for the current project. Dependencies' sources and build files are cleaned only if the `--deps` option is given. By default this task works across all environments, unless `--only` is given. elixir Path Path ===== This module provides conveniences for manipulating or retrieving file system paths. The functions in this module may receive a chardata as argument (i.e. a string or a list of characters / string) and will always return a string (encoded in UTF-8). The majority of the functions in this module do not interact with the file system, except for a few functions that require it (like [`wildcard/2`](#wildcard/2) and [`expand/1`](#expand/1)). Summary ======== Types ------ [t()](#t:t/0) Functions ---------- [absname(path)](#absname/1) Converts the given path to an absolute one. Unlike [`expand/1`](#expand/1), no attempt is made to resolve `..`, `.` or `~`. [absname(path, relative\_to)](#absname/2) Builds a path from `relative_to` to `path`. [basename(path)](#basename/1) Returns the last component of the path or the path itself if it does not contain any directory separators. [basename(path, extension)](#basename/2) Returns the last component of `path` with the `extension` stripped. [dirname(path)](#dirname/1) Returns the directory component of `path`. [expand(path)](#expand/1) Converts the path to an absolute one and expands any `.` and `..` characters and a leading `~`. [expand(path, relative\_to)](#expand/2) Expands the path relative to the path given as the second argument expanding any `.` and `..` characters. [extname(path)](#extname/1) Returns the extension of the last component of `path`. [join(list)](#join/1) Joins a list of paths. [join(left, right)](#join/2) Joins two paths. [relative(name)](#relative/1) Forces the path to be a relative path. [relative\_to(path, from)](#relative_to/2) Returns the given `path` relative to the given `from` path. [relative\_to\_cwd(path)](#relative_to_cwd/1) Convenience to get the path relative to the current working directory. [rootname(path)](#rootname/1) Returns the `path` with the `extension` stripped. [rootname(path, extension)](#rootname/2) Returns the `path` with the `extension` stripped. [split(path)](#split/1) Splits the path into a list at the path separator. [type(name)](#type/1) Returns the path type. [wildcard(glob, opts \\ [])](#wildcard/2) Traverses paths according to the given `glob` expression and returns a list of matches. Types ====== ### t() #### Specs ``` t() :: IO.chardata() ``` Functions ========== ### absname(path) #### Specs ``` absname(t()) :: binary() ``` Converts the given path to an absolute one. Unlike [`expand/1`](#expand/1), no attempt is made to resolve `..`, `.` or `~`. #### Examples ### Unix ``` Path.absname("foo") #=> "/usr/local/foo" Path.absname("../x") #=> "/usr/local/../x" ``` ### Windows ``` Path.absname("foo") #=> "D:/usr/local/foo" Path.absname("../x") #=> "D:/usr/local/../x" ``` ### absname(path, relative\_to) #### Specs ``` absname(t(), t()) :: binary() ``` Builds a path from `relative_to` to `path`. If `path` is already an absolute path, `relative_to` is ignored. See also [`relative_to/2`](#relative_to/2). Unlike [`expand/2`](#expand/2), no attempt is made to resolve `..`, `.` or `~`. #### Examples ``` iex> Path.absname("foo", "bar") "bar/foo" iex> Path.absname("../x", "bar") "bar/../x" ``` ### basename(path) #### Specs ``` basename(t()) :: binary() ``` Returns the last component of the path or the path itself if it does not contain any directory separators. #### Examples ``` iex> Path.basename("foo") "foo" iex> Path.basename("foo/bar") "bar" iex> Path.basename("/") "" ``` ### basename(path, extension) #### Specs ``` basename(t(), t()) :: binary() ``` Returns the last component of `path` with the `extension` stripped. This function should be used to remove a specific extension which may or may not be there. #### Examples ``` iex> Path.basename("~/foo/bar.ex", ".ex") "bar" iex> Path.basename("~/foo/bar.exs", ".ex") "bar.exs" iex> Path.basename("~/foo/bar.old.ex", ".ex") "bar.old" ``` ### dirname(path) #### Specs ``` dirname(t()) :: binary() ``` Returns the directory component of `path`. #### Examples ``` iex> Path.dirname("/foo/bar.ex") "/foo" iex> Path.dirname("/foo/bar/baz.ex") "/foo/bar" iex> Path.dirname("/foo/bar/") "/foo/bar" iex> Path.dirname("bar.ex") "." ``` ### expand(path) #### Specs ``` expand(t()) :: binary() ``` Converts the path to an absolute one and expands any `.` and `..` characters and a leading `~`. #### Examples ``` Path.expand("/foo/bar/../bar") #=> "/foo/bar" ``` ### expand(path, relative\_to) #### Specs ``` expand(t(), t()) :: binary() ``` Expands the path relative to the path given as the second argument expanding any `.` and `..` characters. If the path is already an absolute path, `relative_to` is ignored. Note that this function treats a `path` with a leading `~` as an absolute one. The second argument is first expanded to an absolute path. #### Examples ``` # Assuming that the absolute path to baz is /quux/baz Path.expand("foo/bar/../bar", "baz") #=> "/quux/baz/foo/bar" Path.expand("foo/bar/../bar", "/baz") #=> "/baz/foo/bar" Path.expand("/foo/bar/../bar", "/baz") #=> "/foo/bar" ``` ### extname(path) #### Specs ``` extname(t()) :: binary() ``` Returns the extension of the last component of `path`. #### Examples ``` iex> Path.extname("foo.erl") ".erl" iex> Path.extname("~/foo/bar") "" ``` ### join(list) #### Specs ``` join([t(), ...]) :: binary() ``` Joins a list of paths. This function should be used to convert a list of paths to a path. Note that any trailing slash is removed when joining. #### Examples ``` iex> Path.join(["~", "foo"]) "~/foo" iex> Path.join(["foo"]) "foo" iex> Path.join(["/", "foo", "bar/"]) "/foo/bar" ``` ### join(left, right) #### Specs ``` join(t(), t()) :: binary() ``` Joins two paths. The right path will always be expanded to its relative format and any trailing slash will be removed when joining. #### Examples ``` iex> Path.join("foo", "bar") "foo/bar" iex> Path.join("/foo", "/bar/") "/foo/bar" ``` The functions in this module support chardata, so giving a list will treat it as a single entity: ``` iex> Path.join("foo", ["bar", "fiz"]) "foo/barfiz" iex> Path.join(["foo", "bar"], "fiz") "foobar/fiz" ``` ### relative(name) #### Specs ``` relative(t()) :: binary() ``` Forces the path to be a relative path. #### Examples ### Unix ``` Path.relative("/usr/local/bin") #=> "usr/local/bin" Path.relative("usr/local/bin") #=> "usr/local/bin" Path.relative("../usr/local/bin") #=> "../usr/local/bin" ``` ### Windows ``` Path.relative("D:/usr/local/bin") #=> "usr/local/bin" Path.relative("usr/local/bin") #=> "usr/local/bin" Path.relative("D:bar.ex") #=> "bar.ex" Path.relative("/bar/foo.ex") #=> "bar/foo.ex" ``` ### relative\_to(path, from) #### Specs ``` relative_to(t(), t()) :: binary() ``` Returns the given `path` relative to the given `from` path. In other words, this function tries to strip the `from` prefix from `path`. This function does not query the file system, so it assumes no symlinks between the paths. In case a direct relative path cannot be found, it returns the original path. #### Examples ``` iex> Path.relative_to("/usr/local/foo", "/usr/local") "foo" iex> Path.relative_to("/usr/local/foo", "/") "usr/local/foo" iex> Path.relative_to("/usr/local/foo", "/etc") "/usr/local/foo" ``` ### relative\_to\_cwd(path) #### Specs ``` relative_to_cwd(t()) :: binary() ``` Convenience to get the path relative to the current working directory. If, for some reason, the current working directory cannot be retrieved, this function returns the given `path`. ### rootname(path) #### Specs ``` rootname(t()) :: binary() ``` Returns the `path` with the `extension` stripped. #### Examples ``` iex> Path.rootname("/foo/bar") "/foo/bar" iex> Path.rootname("/foo/bar.ex") "/foo/bar" ``` ### rootname(path, extension) #### Specs ``` rootname(t(), t()) :: binary() ``` Returns the `path` with the `extension` stripped. This function should be used to remove a specific extension which may or may not be there. #### Examples ``` iex> Path.rootname("/foo/bar.erl", ".erl") "/foo/bar" iex> Path.rootname("/foo/bar.erl", ".ex") "/foo/bar.erl" ``` ### split(path) #### Specs ``` split(t()) :: [binary()] ``` Splits the path into a list at the path separator. If an empty string is given, returns an empty list. On Windows, path is split on both "\" and "/" separators and the driver letter, if there is one, is always returned in lowercase. #### Examples ``` iex> Path.split("") [] iex> Path.split("foo") ["foo"] iex> Path.split("/foo/bar") ["/", "foo", "bar"] ``` ### type(name) #### Specs ``` type(t()) :: :absolute | :relative | :volumerelative ``` Returns the path type. #### Examples ### Unix ``` Path.type("/") #=> :absolute Path.type("/usr/local/bin") #=> :absolute Path.type("usr/local/bin") #=> :relative Path.type("../usr/local/bin") #=> :relative Path.type("~/file") #=> :relative ``` ### Windows ``` Path.type("D:/usr/local/bin") #=> :absolute Path.type("usr/local/bin") #=> :relative Path.type("D:bar.ex") #=> :volumerelative Path.type("/bar/foo.ex") #=> :volumerelative ``` ### wildcard(glob, opts \\ []) #### Specs ``` wildcard(t(), keyword()) :: [binary()] ``` Traverses paths according to the given `glob` expression and returns a list of matches. The wildcard looks like an ordinary path, except that the following "wildcard characters" are interpreted in a special way: * `?` - matches one character. * `*` - matches any number of characters up to the end of the filename, the next dot, or the next slash. * `**` - two adjacent `*`'s used as a single pattern will match all files and zero or more directories and subdirectories. * `[char1,char2,...]` - matches any of the characters listed; two characters separated by a hyphen will match a range of characters. Do not add spaces before and after the comma as it would then match paths containing the space character itself. * `{item1,item2,...}` - matches one of the alternatives. Do not add spaces before and after the comma as it would then match paths containing the space character itself. Other characters represent themselves. Only paths that have exactly the same character in the same position will match. Note that matching is case-sensitive: `"a"` will not match `"A"`. Directory separators must always be written as `/`, even on Windows. You may call [`Path.expand/1`](path#expand/1) to normalize the path before invoking this function. By default, the patterns `*` and `?` do not match files starting with a dot `.`. See the `:match_dot` option in the "Options" section below. #### Options * `:match_dot` - (boolean) if `false`, the special wildcard characters `*` and `?` will not match files starting with a dot (`.`). If `true`, files starting with a `.` will not be treated specially. Defaults to `false`. #### Examples Imagine you have a directory called `projects` with three Elixir projects inside of it: `elixir`, `ex_doc`, and `plug`. You can find all `.beam` files inside the `ebin` directory of each project as follows: ``` Path.wildcard("projects/*/ebin/**/*.beam") ``` If you want to search for both `.beam` and `.app` files, you could do: ``` Path.wildcard("projects/*/ebin/**/*.{beam,app}") ```
programming_docs
elixir Macros Meta-programming in Elixir Macros ====== Foreword -------- Even though Elixir attempts its best to provide a safe environment for macros, the major responsibility of writing clean code with macros falls on developers. Macros are harder to write than ordinary Elixir functions and it’s considered to be bad style to use them when they’re not necessary. So write macros responsibly. Elixir already provides mechanisms to write your everyday code in a simple and readable fashion by using its data structures and functions. Macros should only be used as a last resort. Remember that **explicit is better than implicit**. **Clear code is better than concise code.** Our first macro --------------- Macros in Elixir are defined via `defmacro/2`. > For this chapter, we will be using files instead of running code samples in IEx. That’s because the code samples will span multiple lines of code and typing them all in IEx can be counter-productive. You should be able to run the code samples by saving them into a `macros.exs` file and running it with `elixir macros.exs` or `iex macros.exs`. > > In order to better understand how macros work, let’s create a new module where we are going to implement `unless`, which does the opposite of `if`, as a macro and as a function: ``` defmodule Unless do def fun_unless(clause, do: expression) do if(!clause, do: expression) end defmacro macro_unless(clause, do: expression) do quote do if(!unquote(clause), do: unquote(expression)) end end end ``` The function receives the arguments and passes them to `if`. However, as we learned in the [previous chapter](quote-and-unquote), the macro will receive quoted expressions, inject them into the quote, and finally return another quoted expression. Let’s start `iex` with the module above: ``` $ iex macros.exs ``` And play with those definitions: ``` iex> require Unless iex> Unless.macro_unless true, do: IO.puts "this should never be printed" nil iex> Unless.fun_unless true, do: IO.puts "this should never be printed" "this should never be printed" nil ``` Note that in our macro implementation, the sentence was not printed, although it was printed in our function implementation. That’s because the arguments to a function call are evaluated before calling the function. However, macros do not evaluate their arguments. Instead, they receive the arguments as quoted expressions which are then transformed into other quoted expressions. In this case, we have rewritten our `unless` macro to become an `if` behind the scenes. In other words, when invoked as: ``` Unless.macro_unless true, do: IO.puts "this should never be printed" ``` Our `macro_unless` macro received the following: ``` macro_unless(true, [do: {{:., [], [{:__aliases__, [alias: false], [:IO]}, :puts]}, [], ["this should never be printed"]}]) ``` And it then returned a quoted expression as follows: ``` {:if, [], [{:!, [], [true]}, [do: {{:., [], [{:__aliases__, [], [:IO]}, :puts]}, [], ["this should never be printed"]}]]} ``` We can actually verify that this is the case by using `Macro.expand_once/2`: ``` iex> expr = quote do: Unless.macro_unless(true, do: IO.puts "this should never be printed") iex> res = Macro.expand_once(expr, __ENV__) iex> IO.puts Macro.to_string(res) if(!true) do IO.puts("this should never be printed") end :ok ``` `Macro.expand_once/2` receives a quoted expression and expands it according to the current environment. In this case, it expanded/invoked the `Unless.macro_unless/2` macro and returned its result. We then proceeded to convert the returned quoted expression to a string and print it (we will talk about `__ENV__` later in this chapter). That’s what macros are all about. They are about receiving quoted expressions and transforming them into something else. In fact, `unless/2` in Elixir is implemented as a macro: ``` defmacro unless(clause, do: expression) do quote do if(!unquote(clause), do: unquote(expression)) end end ``` Constructs such as `unless/2`, `defmacro/2`, `def/2`, `defprotocol/2`, and many others used throughout this getting started guide are implemented in pure Elixir, often as a macro. This means that the constructs being used to build the language can be used by developers to extend the language to the domains they are working on. We can define any function and macro we want, including ones that override the built-in definitions provided by Elixir. The only exceptions are Elixir special forms which are not implemented in Elixir and therefore cannot be overridden, [the full list of special forms is available in `Kernel.SpecialForms`](https://hexdocs.pm/elixir/Kernel.SpecialForms.html#summary). Macro hygiene ------------- Elixir macros have late resolution. This guarantees that a variable defined inside a quote won’t conflict with a variable defined in the context where that macro is expanded. For example: ``` defmodule Hygiene do defmacro no_interference do quote do: a = 1 end end defmodule HygieneTest do def go do require Hygiene a = 13 Hygiene.no_interference() a end end HygieneTest.go # => 13 ``` In the example above, even though the macro injects `a = 1`, it does not affect the variable `a` defined by the `go` function. If a macro wants to explicitly affect the context, it can use `var!`: ``` defmodule Hygiene do defmacro interference do quote do: var!(a) = 1 end end defmodule HygieneTest do def go do require Hygiene a = 13 Hygiene.interference() a end end HygieneTest.go # => 1 ``` The code above will work but issue a warning: `variable "a" is unused`. The macro is overriding the original value and the original value is never used. Variable hygiene only works because Elixir annotates variables with their context. For example, a variable `x` defined on line 3 of a module would be represented as: ``` {:x, [line: 3], nil} ``` However, a quoted variable is represented as: ``` defmodule Sample do def quoted do quote do: x end end Sample.quoted() #=> {:x, [line: 3], Sample} ``` Notice that the third element in the quoted variable is the atom `Sample`, instead of `nil`, which marks the variable as coming from the `Sample` module. Therefore, Elixir considers these two variables as coming from different contexts and handles them accordingly. Elixir provides similar mechanisms for imports and aliases too. This guarantees that a macro will behave as specified by its source module rather than conflicting with the target module where the macro is expanded. Hygiene can be bypassed under specific situations by using macros like `var!/2` and `alias!/1`, although one must be careful when using those as they directly change the user environment. Sometimes variable names might be dynamically created. In such cases, `Macro.var/2` can be used to define new variables: ``` defmodule Sample do defmacro initialize_to_char_count(variables) do Enum.map variables, fn(name) -> var = Macro.var(name, nil) length = name |> Atom.to_string |> String.length quote do unquote(var) = unquote(length) end end end def run do initialize_to_char_count [:red, :green, :yellow] [red, green, yellow] end end > Sample.run #=> [3, 5, 6] ``` Take note of the second argument to `Macro.var/2`. This is the context being used and will determine hygiene as described in the next section. The environment --------------- When calling `Macro.expand_once/2` earlier in this chapter, we used the special form `__ENV__`. `__ENV__` returns an instance of the `Macro.Env` struct which contains useful information about the compilation environment, including the current module, file, and line, all variables defined in the current scope, as well as imports, requires and so on: ``` iex> __ENV__.module nil iex> __ENV__.file "iex" iex> __ENV__.requires [IEx.Helpers, Kernel, Kernel.Typespec] iex> require Integer nil iex> __ENV__.requires [IEx.Helpers, Integer, Kernel, Kernel.Typespec] ``` Many of the functions in the `Macro` module expect an environment. You can read more about these functions in [the docs for the `Macro` module](https://hexdocs.pm/elixir/Macro.html) and learn more about the compilation environment in the [docs for `Macro.Env`](https://hexdocs.pm/elixir/Macro.Env.html). Private macros -------------- Elixir also supports private macros via `defmacrop`. As private functions, these macros are only available inside the module that defines them, and only at compilation time. It is important that a macro is defined before its usage. Failing to define a macro before its invocation will raise an error at runtime, since the macro won’t be expanded and will be translated to a function call: ``` iex> defmodule Sample do ...> def four, do: two + two ...> defmacrop two, do: 2 ...> end ** (CompileError) iex:2: function two/0 undefined ``` Write macros responsibly ------------------------ Macros are a powerful construct and Elixir provides many mechanisms to ensure they are used responsibly. * Macros are hygienic: by default, variables defined inside a macro are not going to affect the user code. Furthermore, function calls and aliases available in the macro context are not going to leak into the user context. * Macros are lexical: it is impossible to inject code or macros globally. In order to use a macro, you need to explicitly `require` or `import` the module that defines the macro. * Macros are explicit: it is impossible to run a macro without explicitly invoking it. For example, some languages allow developers to completely rewrite functions behind the scenes, often via parse transforms or via some reflection mechanisms. In Elixir, a macro must be explicitly invoked in the caller during compilation time. * Macros’ language is clear: many languages provide syntax shortcuts for `quote` and `unquote`. In Elixir, we preferred to have them explicitly spelled out, in order to clearly delimit the boundaries of a macro definition and its quoted expressions. Even with such guarantees, the developer plays a big role when writing macros responsibly. If you are confident you need to resort to macros, remember that macros are not your API. Keep your macro definitions short, including their quoted contents. For example, instead of writing a macro like this: ``` defmodule MyModule do defmacro my_macro(a, b, c) do quote do do_this(unquote(a)) ... do_that(unquote(b)) ... and_that(unquote(c)) end end end ``` write: ``` defmodule MyModule do defmacro my_macro(a, b, c) do quote do # Keep what you need to do here to a minimum # and move everything else to a function MyModule.do_this_that_and_that(unquote(a), unquote(b), unquote(c)) end end def do_this_that_and_that(a, b, c) do do_this(a) ... do_that(b) ... and_that(c) end end ``` This makes your code clearer and easier to test and maintain, as you can invoke and test `do_this_that_and_that/3` directly. It also helps you design an actual API for developers that do not want to rely on macros. With those lessons, we finish our introduction to macros. The next chapter is a brief discussion on DSLs that shows how we can mix macros and module attributes to annotate and extend modules and functions. elixir Quote and unquote Meta-programming in Elixir Quote and unquote ================= This guide aims to introduce the meta-programming techniques available in Elixir. The ability to represent an Elixir program by its own data structures is at the heart of meta-programming. This chapter starts by exploring those structures and the associated `quote` and `unquote` constructs, so we can take a look at macros in the next chapter and finally build our own domain specific language. > The Elixir guides are also available in EPUB format: > > * [Getting started guide](https://repo.hex.pm/guides/elixir/elixir-getting-started-guide.epub) > * [Mix and OTP guide](https://repo.hex.pm/guides/elixir/mix-and-otp.epub) > * [Meta-programming guide](https://repo.hex.pm/guides/elixir/meta-programming-in-elixir.epub) > > Quoting ------- The building block of an Elixir program is a tuple with three elements. For example, the function call `sum(1, 2, 3)` is represented internally as: ``` {:sum, [], [1, 2, 3]} ``` You can get the representation of any expression by using the `quote` macro: ``` iex> quote do: sum(1, 2, 3) {:sum, [], [1, 2, 3]} ``` The first element is the function name, the second is a keyword list containing metadata and the third is the arguments list. Operators are also represented as such tuples: ``` iex> quote do: 1 + 2 {:+, [context: Elixir, import: Kernel], [1, 2]} ``` Even a map is represented as a call to `%{}`: ``` iex> quote do: %{1 => 2} {:%{}, [], [{1, 2}]} ``` Variables are also represented using such triplets, except the last element is an atom, instead of a list: ``` iex> quote do: x {:x, [], Elixir} ``` When quoting more complex expressions, we can see that the code is represented in such tuples, which are often nested inside each other in a structure resembling a tree. Many languages would call such representations an Abstract Syntax Tree (AST). Elixir calls them quoted expressions: ``` iex> quote do: sum(1, 2 + 3, 4) {:sum, [], [1, {:+, [context: Elixir, import: Kernel], [2, 3]}, 4]} ``` Sometimes when working with quoted expressions, it may be useful to get the textual code representation back. This can be done with `Macro.to_string/1`: ``` iex> Macro.to_string(quote do: sum(1, 2 + 3, 4)) "sum(1, 2 + 3, 4)" ``` In general, the tuples above are structured according to the following format: ``` {atom | tuple, list, list | atom} ``` * The first element is an atom or another tuple in the same representation; * The second element is a keyword list containing metadata, like numbers and contexts; * The third element is either a list of arguments for the function call or an atom. When this element is an atom, it means the tuple represents a variable. Besides the tuple defined above, there are five Elixir literals that, when quoted, return themselves (and not a tuple). They are: ``` :sum #=> Atoms 1.0 #=> Numbers [1, 2] #=> Lists "strings" #=> Strings {key, value} #=> Tuples with two elements ``` Most Elixir code has a straight-forward translation to its underlying quoted expression. We recommend you try out different code samples and see what the results are. For example, what does `String.upcase("foo")` expand to? We have also learned that `if(true, do: :this, else: :that)` is the same as `if true do :this else :that end`. How does this affirmation hold with quoted expressions? Unquoting --------- Quote is about retrieving the inner representation of some particular chunk of code. However, sometimes it may be necessary to inject some other particular chunk of code inside the representation we want to retrieve. For example, imagine you have a variable `number` which contains the number you want to inject inside a quoted expression. ``` iex> number = 13 iex> Macro.to_string(quote do: 11 + number) "11 + number" ``` That’s not what we wanted, since the value of the `number` variable has not been injected and `number` has been quoted in the expression. In order to inject the *value* of the `number` variable, `unquote` has to be used inside the quoted representation: ``` iex> number = 13 iex> Macro.to_string(quote do: 11 + unquote(number)) "11 + 13" ``` `unquote` can even be used to inject function names: ``` iex> fun = :hello iex> Macro.to_string(quote do: unquote(fun)(:world)) "hello(:world)" ``` In some cases, it may be necessary to inject many values inside a list. For example, imagine you have a list containing `[1, 2, 6]` and we want to inject `[3, 4, 5]` into it. Using `unquote` won’t yield the desired result: ``` iex> inner = [3, 4, 5] iex> Macro.to_string(quote do: [1, 2, unquote(inner), 6]) "[1, 2, [3, 4, 5], 6]" ``` That’s when `unquote_splicing` becomes handy: ``` iex> inner = [3, 4, 5] iex> Macro.to_string(quote do: [1, 2, unquote_splicing(inner), 6]) "[1, 2, 3, 4, 5, 6]" ``` Unquoting is very useful when working with macros. When writing macros, developers are able to receive code chunks and inject them inside other code chunks, which can be used to transform code or write code that generates code during compilation. Escaping -------- As we saw at the beginning of this chapter, only some values are valid quoted expressions in Elixir. For example, a map is not a valid quoted expression. Neither is a tuple with four elements. However, such values *can* be expressed as a quoted expression: ``` iex> quote do: %{1 => 2} {:%{}, [], [{1, 2}]} ``` In some cases, you may need to inject such *values* into *quoted expressions*. To do that, we need to first escape those values into quoted expressions with the help of `Macro.escape/1`: ``` iex> map = %{hello: :world} iex> Macro.escape(map) {:%{}, [], [hello: :world]} ``` Macros receive quoted expressions and must return quoted expressions. However, sometimes during the execution of a macro, you may need to work with values and making a distinction between values and quoted expressions will be required. In other words, it is important to make a distinction between a regular Elixir value (like a list, a map, a process, a reference, etc) and a quoted expression. Some values, such as integers, atoms, and strings, have a quoted expression equal to the value itself. Other values, like maps, need to be explicitly converted. Finally, values like functions and references cannot be converted to a quoted expression at all. You can read more about `quote` and `unquote` in the [`Kernel.SpecialForms` module](https://hexdocs.pm/elixir/Kernel.SpecialForms.html). Documentation for `Macro.escape/1` and other functions related to quoted expressions can be found in the [`Macro` module](https://hexdocs.pm/elixir/Macro.html). In this introduction, we have laid the groundwork to finally write our first macro, so let’s move to the next chapter. elixir Domain-specific languages Meta-programming in Elixir Domain-specific languages ========================= Foreword -------- [Domain-specific languages (DSL)](https://en.wikipedia.org/wiki/Domain-specific_language) allow developers to tailor their application to a particular domain. You don’t need macros in order to have a DSL: every data structure and every function you define in your module is part of your Domain-specific language. For example, imagine we want to implement a Validator module which provides a data validation domain-specific language. We could implement it using data structures, functions or macros. Let’s see what those different DSLs would look like: ``` # 1. data structures import Validator validate user, name: [length: 1..100], email: [matches: ~r/@/] # 2. functions import Validator user |> validate_length(:name, 1..100) |> validate_matches(:email, ~r/@/) # 3. macros + modules defmodule MyValidator do use Validator validate_length :name, 1..100 validate_matches :email, ~r/@/ end MyValidator.validate(user) ``` Of all the approaches above, the first is definitely the most flexible. If our domain rules can be encoded with data structures, they are by far the easiest to compose and implement, as Elixir’s standard library is filled with functions for manipulating different data types. The second approach uses function calls which better suits more complex APIs (for example, if you need to pass many options) and reads nicely in Elixir thanks to the pipe operator. The third approach uses macros, and is by far the most complex. It will take more lines of code to implement, it is hard and expensive to test (compared to testing simple functions), and it limits how the user may use the library since all validations need to be defined inside a module. To drive the point home, imagine you want to validate a certain attribute only if a given condition is met. We could easily achieve it with the first solution, by manipulating the data structure accordingly, or with the second solution by using conditionals (if/else) before invoking the function. However, it is impossible to do so with the macros approach unless its DSL is augmented. In other words: ``` data > functions > macros ``` That said, there are still cases where using macros and modules to build domain-specific languages is useful. Since we have explored data structures and function definitions in the Getting Started guide, this chapter will explore how to use macros and module attributes to tackle more complex DSLs. Building our own test case -------------------------- The goal in this chapter is to build a module named `TestCase` that allows us to write the following: ``` defmodule MyTest do use TestCase test "arithmetic operations" do 4 = 2 + 2 end test "list operations" do [1, 2, 3] = [1, 2] ++ [3] end end MyTest.run ``` In the example above, by using `TestCase`, we can write tests using the `test` macro, which defines a function named `run` to automatically run all tests for us. Our prototype will rely on the match operator (`=`) as a mechanism to do assertions. The `test` macro ---------------- Let’s start by creating a module that defines and imports the `test` macro when used: ``` defmodule TestCase do # Callback invoked by `use`. # # For now it returns a quoted expression that # imports the module itself into the user code. @doc false defmacro __using__(_opts) do quote do import TestCase end end @doc """ Defines a test case with the given description. ## Examples test "arithmetic operations" do 4 = 2 + 2 end """ defmacro test(description, do: block) do function_name = String.to_atom("test " <> description) quote do def unquote(function_name)(), do: unquote(block) end end end ``` Assuming we defined `TestCase` in a file named `tests.exs`, we can open it up by running `iex tests.exs` and define our first tests: ``` iex> defmodule MyTest do ...> use TestCase ...> ...> test "hello" do ...> "hello" = "world" ...> end ...> end ``` For now, we don’t have a mechanism to run tests, but we know that a function named “test hello” was defined behind the scenes. When we invoke it, it should fail: ``` iex> MyTest."test hello"() ** (MatchError) no match of right hand side value: "world" ``` Storing information with attributes ----------------------------------- In order to finish our `TestCase` implementation, we need to be able to access all defined test cases. One way of doing this is by retrieving the tests at runtime via `__MODULE__.__info__(:functions)`, which returns a list of all functions in a given module. However, considering that we may want to store more information about each test besides the test name, a more flexible approach is required. When discussing module attributes in earlier chapters, we mentioned how they can be used as temporary storage. That’s exactly the property we will apply in this section. In the `__using__/1` implementation, we will initialize a module attribute named `@tests` to an empty list, then store the name of each defined test in this attribute so the tests can be invoked from the `run` function. Here is the updated code for the `TestCase` module: ``` defmodule TestCase do @doc false defmacro __using__(_opts) do quote do import TestCase # Initialize @tests to an empty list @tests [] # Invoke TestCase.__before_compile__/1 before the module is compiled @before_compile TestCase end end @doc """ Defines a test case with the given description. ## Examples test "arithmetic operations" do 4 = 2 + 2 end """ defmacro test(description, do: block) do function_name = String.to_atom("test " <> description) quote do # Prepend the newly defined test to the list of tests @tests [unquote(function_name) | @tests] def unquote(function_name)(), do: unquote(block) end end # This will be invoked right before the target module is compiled # giving us the perfect opportunity to inject the `run/0` function @doc false defmacro __before_compile__(_env) do quote do def run do Enum.each @tests, fn name -> IO.puts "Running #{name}" apply(__MODULE__, name, []) end end end end end ``` By starting a new IEx session, we can now define our tests and run them: ``` iex> defmodule MyTest do ...> use TestCase ...> ...> test "hello" do ...> "hello" = "world" ...> end ...> end iex> MyTest.run Running test hello ** (MatchError) no match of right hand side value: "world" ``` Although we have overlooked some details, this is the main idea behind creating domain-specific modules in Elixir. Macros enable us to return quoted expressions that are executed in the caller, which we can then use to transform code and store relevant information in the target module via module attributes. Finally, callbacks such as `@before_compile` allow us to inject code into the module when its definition is complete. Besides `@before_compile`, there are other useful module attributes like `@on_definition` and `@after_compile`, which you can read more about in [the docs for the `Module` module](https://hexdocs.pm/elixir/Module.html). You can also find useful information about macros and the compilation environment in the documentation for the [`Macro` module](https://hexdocs.pm/elixir/Macro.html) and [`Macro.Env`](https://hexdocs.pm/elixir/Macro.Env.html).
programming_docs
elixir Distributed tasks and tags Mix and OTP Distributed tasks and tags ========================== > This chapter is part of the *Mix and OTP guide* and it depends on previous chapters in this guide. For more information, [read the introduction guide](introduction-to-mix) or check out the chapter index in the sidebar. > > In this chapter, we will go back to the `:kv` application and add a routing layer that will allow us to distribute requests between nodes based on the bucket name. The routing layer will receive a routing table of the following format: ``` [ {?a..?m, :"foo@computer-name"}, {?n..?z, :"bar@computer-name"} ] ``` The router will check the first byte of the bucket name against the table and dispatch to the appropriate node based on that. For example, a bucket starting with the letter “a” (`?a` represents the Unicode codepoint of the letter “a”) will be dispatched to node `foo@computer-name`. If the matching entry points to the node evaluating the request, then we’ve finished routing, and this node will perform the requested operation. If the matching entry points to a different node, we’ll pass the request to this node, which will look at its own routing table (which may be different from the one in the first node) and act accordingly. If no entry matches, an error will be raised. > Note: we will be using two nodes in the same machine throughout this chapter. You are free to use two (or more) different machines on the same network but you need to do some prep work. First of all, you need to ensure all machines have a `~/.erlang.cookie` file with exactly the same value. Second, you need to guarantee [epmd](http://www.erlang.org/doc/man/epmd.html) is running on a port that is not blocked (you can run `epmd -d` for debug info). Third, if you want to learn more about distribution in general, we recommend [this great Distribunomicon chapter from Learn You Some Erlang](http://learnyousomeerlang.com/distribunomicon). > > Our first distributed code -------------------------- Elixir ships with facilities to connect nodes and exchange information between them. In fact, we use the same concepts of processes, message passing and receiving messages when working in a distributed environment because Elixir processes are *location transparent*. This means that when sending a message, it doesn’t matter if the recipient process is on the same node or on another node, the VM will be able to deliver the message in both cases. In order to run distributed code, we need to start the VM with a name. The name can be short (when in the same network) or long (requires the full computer address). Let’s start a new IEx session: ``` $ iex --sname foo ``` You can see now the prompt is slightly different and shows the node name followed by the computer name: ``` Interactive Elixir - press Ctrl+C to exit (type h() ENTER for help) iex(foo@jv)1> ``` My computer is named `jv`, so I see `foo@jv` in the example above, but you will get a different result. We will use `foo@computer-name` in the following examples and you should update them accordingly when trying out the code. Let’s define a module named `Hello` in this shell: ``` iex> defmodule Hello do ...> def world, do: IO.puts "hello world" ...> end ``` If you have another computer on the same network with both Erlang and Elixir installed, you can start another shell on it. If you don’t, you can start another IEx session in another terminal. In either case, give it the short name of `bar`: ``` $ iex --sname bar ``` Note that inside this new IEx session, we cannot access `Hello.world/0`: ``` iex> Hello.world ** (UndefinedFunctionError) undefined function: Hello.world/0 Hello.world() ``` However, we can spawn a new process on `foo@computer-name` from `bar@computer-name`! Let’s give it a try (where `@computer-name` is the one you see locally): ``` iex> Node.spawn_link :"foo@computer-name", fn -> Hello.world end #PID<9014.59.0> hello world ``` Elixir spawned a process on another node and returned its pid. The code then executed on the other node where the `Hello.world/0` function exists and invoked that function. Note that the result of “hello world” was printed on the current node `bar` and not on `foo`. In other words, the message to be printed was sent back from `foo` to `bar`. This happens because the process spawned on the other node (`foo`) knows all of the output should be sent back to the original node! We can send and receive messages from the pid returned by `Node.spawn_link/2` as usual. Let’s try a quick ping-pong example: ``` iex> pid = Node.spawn_link :"foo@computer-name", fn -> ...> receive do ...> {:ping, client} -> send client, :pong ...> end ...> end #PID<9014.59.0> iex> send pid, {:ping, self()} {:ping, #PID<0.73.0>} iex> flush() :pong :ok ``` From our quick exploration, we could conclude that we should use `Node.spawn_link/2` to spawn processes on a remote node every time we need to do a distributed computation. However, we have learned throughout this guide that spawning processes outside of supervision trees should be avoided if possible, so we need to look for other options. There are three better alternatives to `Node.spawn_link/2` that we could use in our implementation: 1. We could use Erlang’s [:rpc](http://www.erlang.org/doc/man/rpc.html) module to execute functions on a remote node. Inside the `bar@computer-name` shell above, you can call `:rpc.call(:"foo@computer-name", Hello, :world, [])` and it will print “hello world” 2. We could have a server running on the other node and send requests to that node via the [GenServer](https://hexdocs.pm/elixir/GenServer.html) API. For example, you can call a server on a remote node by using `GenServer.call({name, node}, arg)` or passing the remote process PID as the first argument 3. We could use [tasks](https://hexdocs.pm/elixir/Task.html), which we have learned about in [a previous chapter](task-and-gen-tcp), as they can be spawned on both local and remote nodes The options above have different properties. Both `:rpc` and using a GenServer would serialize your requests on a single server, while tasks are effectively running asynchronously on the remote node, with the only serialization point being the spawning done by the supervisor. For our routing layer, we are going to use tasks, but feel free to explore the other alternatives too. async/await ----------- So far we have explored tasks that are started and run in isolation, with no regard for their return value. However, sometimes it is useful to run a task to compute a value and read its result later on. For this, tasks also provide the `async/await` pattern: ``` task = Task.async(fn -> compute_something_expensive() end) res = compute_something_else() res + Task.await(task) ``` `async/await` provides a very simple mechanism to compute values concurrently. Not only that, `async/await` can also be used with the same [`Task.Supervisor`](https://hexdocs.pm/elixir/Task.Supervisor.html) we have used in previous chapters. We just need to call `Task.Supervisor.async/2` instead of `Task.Supervisor.start_child/2` and use `Task.await/2` to read the result later on. Distributed tasks ----------------- Distributed tasks are exactly the same as supervised tasks. The only difference is that we pass the node name when spawning the task on the supervisor. Open up `lib/kv/supervisor.ex` from the `:kv` application. Let’s add a task supervisor as the last child of the tree: ``` {Task.Supervisor, name: KV.RouterTasks}, ``` Now, let’s start two named nodes again, but inside the `:kv` application: ``` $ iex --sname foo -S mix $ iex --sname bar -S mix ``` From inside `bar@computer-name`, we can now spawn a task directly on the other node via the supervisor: ``` iex> task = Task.Supervisor.async {KV.RouterTasks, :"foo@computer-name"}, fn -> ...> {:ok, node()} ...> end %Task{owner: #PID<0.122.0>, pid: #PID<12467.88.0>, ref: #Reference<0.0.0.400>} iex> Task.await(task) {:ok, :"foo@computer-name"} ``` Our first distributed task retrieves the name of the node the task is running on. Notice we have given an anonymous function to `Task.Supervisor.async/2` but, in distributed cases, it is preferable to give the module, function, and arguments explicitly: ``` iex> task = Task.Supervisor.async {KV.RouterTasks, :"foo@computer-name"}, Kernel, :node, [] %Task{owner: #PID<0.122.0>, pid: #PID<12467.89.0>, ref: #Reference<0.0.0.404>} iex> Task.await(task) :"foo@computer-name" ``` The difference is that anonymous functions require the target node to have exactly the same code version as the caller. Using module, function, and arguments is more robust because you only need to find a function with matching arity in the given module. With this knowledge in hand, let’s finally write the routing code. Routing layer ------------- Create a file at `lib/kv/router.ex` with the following contents: ``` defmodule KV.Router do @doc """ Dispatch the given `mod`, `fun`, `args` request to the appropriate node based on the `bucket`. """ def route(bucket, mod, fun, args) do # Get the first byte of the binary first = :binary.first(bucket) # Try to find an entry in the table() or raise entry = Enum.find(table(), fn {enum, _node} -> first in enum end) || no_entry_error(bucket) # If the entry node is the current node if elem(entry, 1) == node() do apply(mod, fun, args) else {KV.RouterTasks, elem(entry, 1)} |> Task.Supervisor.async(KV.Router, :route, [bucket, mod, fun, args]) |> Task.await() end end defp no_entry_error(bucket) do raise "could not find entry for #{inspect bucket} in table #{inspect table()}" end @doc """ The routing table. """ def table do # Replace computer-name with your local machine name [{?a..?m, :"foo@computer-name"}, {?n..?z, :"bar@computer-name"}] end end ``` Let’s write a test to verify our router works. Create a file named `test/kv/router_test.exs` containing: ``` defmodule KV.RouterTest do use ExUnit.Case, async: true test "route requests across nodes" do assert KV.Router.route("hello", Kernel, :node, []) == :"foo@computer-name" assert KV.Router.route("world", Kernel, :node, []) == :"bar@computer-name" end test "raises on unknown entries" do assert_raise RuntimeError, ~r/could not find entry/, fn -> KV.Router.route(<<0>>, Kernel, :node, []) end end end ``` The first test invokes `Kernel.node/0`, which returns the name of the current node, based on the bucket names “hello” and “world”. According to our routing table so far, we should get `foo@computer-name` and `bar@computer-name` as responses, respectively. The second test checks that the code raises for unknown entries. In order to run the first test, we need to have two nodes running. Move into `apps/kv` and let’s restart the node named `bar` which is going to be used by tests. ``` $ iex --sname bar -S mix ``` And now run tests with: ``` $ elixir --sname foo -S mix test ``` The test should pass. Test filters and tags --------------------- Although our tests pass, our testing structure is getting more complex. In particular, running tests with only `mix test` causes failures in our suite, since our test requires a connection to another node. Luckily, ExUnit ships with a facility to tag tests, allowing us to run specific callbacks or even filter tests altogether based on those tags. We have already used the `:capture_log` tag in the previous chapter, which has its semantics specified by ExUnit itself. This time let’s add a `:distributed` tag to `test/kv/router_test.exs`: ``` @tag :distributed test "route requests across nodes" do ``` Writing `@tag :distributed` is equivalent to writing `@tag distributed: true`. With the test properly tagged, we can now check if the node is alive on the network and, if not, we can exclude all distributed tests. Open up `test/test_helper.exs` inside the `:kv` application and add the following: ``` exclude = if Node.alive?, do: [], else: [distributed: true] ExUnit.start(exclude: exclude) ``` Now run tests with `mix test`: ``` $ mix test Excluding tags: [distributed: true] ....... Finished in 0.1 seconds (0.1s on load, 0.01s on tests) 7 tests, 0 failures, 1 skipped ``` This time all tests passed and ExUnit warned us that distributed tests were being excluded. If you run tests with `$ elixir --sname foo -S mix test`, one extra test should run and successfully pass as long as the `bar@computer-name` node is available. The `mix test` command also allows us to dynamically include and exclude tags. For example, we can run `$ mix test --include distributed` to run distributed tests regardless of the value set in `test/test_helper.exs`. We could also pass `--exclude` to exclude a particular tag from the command line. Finally, `--only` can be used to run only tests with a particular tag: ``` $ elixir --sname foo -S mix test --only distributed ``` You can read more about filters, tags and the default tags in [`ExUnit.Case` module documentation](https://hexdocs.pm/ex_unit/ExUnit.Case.html). Wiring it all up ---------------- Now with our routing system in place, let’s change `KVServer` to use the router. Replace the `lookup/2` function in `KVServer.Command` by the following one: ``` defp lookup(bucket, callback) do case KV.Router.route(bucket, KV.Registry, :lookup, [KV.Registry, bucket]) do {:ok, pid} -> callback.(pid) :error -> {:error, :not_found} end end ``` Good! Now `GET`, `PUT` and `DELETE` requests are all routed to the approriate node. Let’s also make sure that when a new bucket is created it ends up on the correct node. Replace the `run/1` function in `KVServer.Command`, the one that matches the `:create` command, with the following: ``` def run({:create, bucket}) do case KV.Router.route(bucket, KV.Registry, :create, [KV.Registry, bucket]) do pid when is_pid(pid) -> {:ok, "OK\r\n"} _ -> {:error, "FAILED TO CREATE BUCKET"} end end ``` Now if you run the tests, you will see the test that checks the server interaction will fail, as it will attempt to use the routing table. To address this failure, add `@tag :distributed` to this test too: ``` @tag :distributed test "server interaction", %{socket: socket} do ``` However, keep in mind that by making the test distributed, we will likely run it less frequently, since we may not do the distributed setup on every test run. There are a couple other options here. One option is to spawn the distributed node programmatically at the beginning of `test/test_helper.exs`. Erlang/OTP does provide APIs for doing so, but they are non-trivial and therefore we won’t cover them here. Another option is to make the routing table configurable. This means we can change the routing table on specific tests to assert for specific behaviour. As we will learn in the next chapter, changing the routing table this way has the downside that those particular tests can no longer run asynchronously, so it is a technique that should be used sparingly. With the routing table integrated, we have made a lot of progress in building our distributed key-value store but, up to this point, the routing table is still hard-coded. In the next chapter, we will learn how to make the routing table configurable and how to package our application for production. elixir Introduction to Mix Mix and OTP Introduction to Mix =================== In this guide, we will learn how to build a complete Elixir application, with its own supervision tree, configuration, tests and more. The requirements for this guide are (see `elixir -v`): * Elixir 1.9.0 onwards * Erlang/OTP 20 onwards The application works as a distributed key-value store. We are going to organize key-value pairs into buckets and distribute those buckets across multiple nodes. We will also build a simple client that allows us to connect to any of those nodes and send requests such as: ``` CREATE shopping OK PUT shopping milk 1 OK PUT shopping eggs 3 OK GET shopping milk 1 OK DELETE shopping eggs OK ``` In order to build our key-value application, we are going to use three main tools: * ***OTP*** *(Open Telecom Platform)* is a set of libraries that ships with Erlang. Erlang developers use OTP to build robust, fault-tolerant applications. In this chapter we will explore how many aspects from OTP integrate with Elixir, including supervision trees, event managers and more; * ***[Mix](https://hexdocs.pm/mix/)*** is a build tool that ships with Elixir that provides tasks for creating, compiling, testing your application, managing its dependencies and much more; * ***[ExUnit](https://hexdocs.pm/ex_unit/)*** is a test-unit based framework that ships with Elixir; In this chapter, we will create our first project using Mix and explore different features in OTP, Mix and ExUnit as we go. > If you have any questions or improvements to the guide, please reach discussion channels such as the [Elixir Forum](https://elixirforum.com) or the [issues tracker](https://github.com/elixir-lang/elixir-lang.github.com/issues). Your input is really important to help us guarantee the guides are accessible and up to date! > > The final code for the application built in this guide is in [this repository](https://github.com/josevalim/kv_umbrella) and can be used as a reference. > > > The Elixir guides are also available in EPUB format: > > * [Getting started guide](https://repo.hex.pm/guides/elixir/elixir-getting-started-guide.epub) > * [Mix and OTP guide](https://repo.hex.pm/guides/elixir/mix-and-otp.epub) > * [Meta-programming guide](https://repo.hex.pm/guides/elixir/meta-programming-in-elixir.epub) > > Our first project ----------------- When you install Elixir, besides getting the `elixir`, `elixirc` and `iex` executables, you also get an executable Elixir script named `mix`. Let’s create our first project by invoking `mix new` from the command line. We’ll pass the project name as the argument (`kv`, in this case), and tell Mix that our main module should be the all-uppercase `KV`, instead of the default, which would have been `Kv`: ``` $ mix new kv --module KV ``` Mix will create a directory named `kv` with a few files in it: ``` * creating README.md * creating .formatter.exs * creating .gitignore * creating mix.exs * creating lib * creating lib/kv.ex * creating test * creating test/test_helper.exs * creating test/kv_test.exs ``` Let’s take a brief look at those generated files. > Note: Mix is an Elixir executable. This means that in order to run `mix`, you need to have both `mix` and `elixir` executables in your PATH. That’s what happens when you install Elixir. > > Project compilation ------------------- A file named `mix.exs` was generated inside our new project folder (`kv`) and its main responsibility is to configure our project. Let’s take a look at it: ``` defmodule KV.MixProject do use Mix.Project def project do [ app: :kv, version: "0.1.0", elixir: "~> 1.9", start_permanent: Mix.env == :prod, deps: deps() ] end # Run "mix help compile.app" to learn about applications def application do [ extra_applications: [:logger] ] end # Run "mix help deps" to learn about dependencies defp deps do [ # {:dep_from_hexpm, "~> 0.3.0"}, # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}, ] end end ``` Our `mix.exs` defines two public functions: `project`, which returns project configuration like the project name and version, and `application`, which is used to generate an application file. There is also a private function named `deps`, which is invoked from the `project` function, that defines our project dependencies. Defining `deps` as a separate function is not required, but it helps keep the project configuration tidy. Mix also generates a file at `lib/kv.ex` with a module containing exactly one function, called `hello`: ``` defmodule KV do @moduledoc """ Documentation for KV. """ @doc """ Hello world. ## Examples iex> KV.hello() :world """ def hello do :world end end ``` This structure is enough to compile our project: ``` $ cd kv $ mix compile ``` Will output: ``` Compiling 1 file (.ex) Generated kv app ``` The `lib/kv.ex` file was compiled, an application manifest named `kv.app` was generated. All compilation artifacts are placed inside the `_build` directory using the options defined in the `mix.exs` file. Once the project is compiled, you can start an `iex` session inside the project by running: ``` $ iex -S mix ``` We are going to work on this `kv` project, making modifications and trying out the latest changes from an `iex` session. While you may start a new session whenever there are changes to the project source code, you can also recompile the project from within `iex` with the `recompile` helper, like this: ``` iex> recompile() Compiling 1 file (.ex) :ok iex> recompile() :noop ``` If anything had to be compiled, you see some informative text, and get the `:ok` atom back, otherwise the function is silent, and returns `:noop`. Running tests ------------- Mix also generated the appropriate structure for running our project tests. Mix projects usually follow the convention of having a `<filename>_test.exs` file in the `test` directory for each file in the `lib` directory. For this reason, we can already find a `test/kv_test.exs` corresponding to our `lib/kv.ex` file. It doesn’t do much at this point: ``` defmodule KVTest do use ExUnit.Case doctest KV test "greets the world" do assert KV.hello() == :world end end ``` It is important to note a couple of things: 1. the test file is an Elixir script file (`.exs`). This is convenient because we don’t need to compile test files before running them; 2. we define a test module named `KVTest`, in which we [`use ExUnit.Case`](https://hexdocs.pm/ex_unit/ExUnit.Case.html) to inject the testing API; 3. we use one of the injected macros, [`doctest/1`](https://hexdocs.pm/ex_unit/ExUnit.DocTest.html#doctest/2), to indicate that the `KV` module contains doctests (we will discuss those in a later chapter); 4. we use the [`test/2`](https://hexdocs.pm/ex_unit/ExUnit.Case.html#test/3) macro to define a simple test; Mix also generated a file named `test/test_helper.exs` which is responsible for setting up the test framework: ``` ExUnit.start() ``` This file will be required by Mix every time before we run our tests. We can run tests with: ``` $ mix test Compiled lib/kv.ex Generated kv app .. Finished in 0.04 seconds 1 doctest, 1 test, 0 failures Randomized with seed 540224 ``` Notice that by running `mix test`, Mix has compiled the source files and generated the application manifest once again. This happens because Mix supports multiple environments, which we will discuss later in this chapter. Furthermore, you can see that ExUnit prints a dot for each successful test and automatically randomizes tests too. Let’s make the test fail on purpose and see what happens. Change the assertion in `test/kv_test.exs` to the following: ``` assert KV.hello() == :oops ``` Now run `mix test` again (notice this time there will be no compilation): ``` 1) test greets the world (KVTest) test/kv_test.exs:5 Assertion with == failed code: assert KV.hello() == :oops left: :world right: :oops stacktrace: test/kv_test.exs:6: (test) . Finished in 0.05 seconds 1 doctest, 1 test, 1 failure ``` For each failure, ExUnit prints a detailed report, containing the test name with the test case, the code that failed and the values for the left side and right side (rhs) of the `==` operator. In the second line of the failure, right below the test name, there is the location where the test was defined. If you copy the test location in full, including the file and line number, and append it to `mix test`, Mix will load and run just that particular test: ``` $ mix test test/kv_test.exs:5 ``` This shortcut will be extremely useful as we build our project, allowing us to quickly iterate by running a single test. Finally, the stacktrace relates to the failure itself, giving information about the test and often the place the failure was generated from within the source files. Automatic code formatting ------------------------- One of the files generated by `mix new` is the `.formatter.exs`. Elixir ships with a code formatter that is capable of automatically formatting our codebase according to a consistent style. The formatter is triggered with the `mix format` task. The generated `.formatter.exs` file configures which files should be formatted when `mix format` runs. To give the formatter a try, change a file in the `lib` or `test` directories to include extra spaces or extra newlines, such as `def hello do`, and then run `mix format`. Most editors provide built-in integration with the formatter, allowing a file to be formatted on save or via a chosen keybinding. If you are learning Elixir, editor integration gives you useful and quick feedback when learning the Elixir syntax. For companies and teams, we recommend developers to run `mix format --check-formatted` on their continuous integration servers, ensuring all current and future code follows the standard. You can learn more about the code formatter by checking [the format task documentation](https://hexdocs.pm/mix/Mix.Tasks.Format.html) or by reading [the release announcement for Elixir v1.6](https://elixir-lang.org/blog/2018/01/17/elixir-v1-6-0-released/), the first version to include the formatter. Environments ------------ Mix provides the concept of “environments”. They allow a developer to customize compilation and other options for specific scenarios. By default, Mix understands three environments: * `:dev` - the one in which Mix tasks (like `compile`) run by default * `:test` - used by `mix test` * `:prod` - the one you will use to run your project in production The environment applies only to the current project. As we will see in future chapters, any dependency you add to your project will by default run in the `:prod` environment. Customization per environment can be done by accessing [the `Mix.env` function](https://hexdocs.pm/mix/Mix.html#env/0) in your `mix.exs` file, which returns the current environment as an atom. That’s what we have used in the `:start_permanent` options: ``` def project do [ ..., start_permanent: Mix.env == :prod, ... ] end ``` When true, the `:start_permanent` option starts your application in permanent mode, which means the Erlang VM will crash if your application’s supervision tree shuts down. Notice we don’t want this behaviour in dev and test because it is useful to keep the VM instance running in those environments for troubleshooting purposes. Mix will default to the `:dev` environment, except for the `test` task that will default to the `:test` environment. The environment can be changed via the `MIX_ENV` environment variable: ``` $ MIX_ENV=prod mix compile ``` Or on Windows: ``` > set "MIX_ENV=prod" && mix compile ``` > Mix is a build tool and, as such, it is not expected to be available in production. Therefore, it is recommended to access `Mix.env` only in configuration files and inside `mix.exs`, never in your application code (`lib`). > > Exploring --------- There is much more to Mix, and we will continue to explore it as we build our project. A [general overview is available on the Mix documentation](https://hexdocs.pm/mix/). Read [the Mix source code here](https://github.com/elixir-lang/elixir/tree/master/lib/mix). Keep in mind that you can always invoke the help task to list all available tasks: ``` $ mix help ``` You can get further information about a particular task by invoking `mix help TASK`. Let’s write some code!
programming_docs
elixir Task and gen_tcp Mix and OTP Task and gen\_tcp ================= > This chapter is part of the *Mix and OTP guide* and it depends on previous chapters in this guide. For more information, [read the introduction guide](introduction-to-mix) or check out the chapter index in the sidebar. > > In this chapter, we are going to learn how to use [Erlang’s `:gen_tcp` module](http://www.erlang.org/doc/man/gen_tcp.html) to serve requests. This provides a great opportunity to explore Elixir’s `Task` module. In future chapters, we will expand our server so it can actually serve the commands. Echo server ----------- We will start our TCP server by first implementing an echo server. It will send a response with the text it received in the request. We will slowly improve our server until it is supervised and ready to handle multiple connections. A TCP server, in broad strokes, performs the following steps: 1. Listens to a port until the port is available and it gets hold of the socket 2. Waits for a client connection on that port and accepts it 3. Reads the client request and writes a response back Let’s implement those steps. Move to the `apps/kv_server` application, open up `lib/kv_server.ex`, and add the following functions: ``` defmodule KVServer do require Logger def accept(port) do # The options below mean: # # 1. `:binary` - receives data as binaries (instead of lists) # 2. `packet: :line` - receives data line by line # 3. `active: false` - blocks on `:gen_tcp.recv/2` until data is available # 4. `reuseaddr: true` - allows us to reuse the address if the listener crashes # {:ok, socket} = :gen_tcp.listen(port, [:binary, packet: :line, active: false, reuseaddr: true]) Logger.info("Accepting connections on port #{port}") loop_acceptor(socket) end defp loop_acceptor(socket) do {:ok, client} = :gen_tcp.accept(socket) serve(client) loop_acceptor(socket) end defp serve(socket) do socket |> read_line() |> write_line(socket) serve(socket) end defp read_line(socket) do {:ok, data} = :gen_tcp.recv(socket, 0) data end defp write_line(line, socket) do :gen_tcp.send(socket, line) end end ``` We are going to start our server by calling `KVServer.accept(4040)`, where 4040 is the port. The first step in `accept/1` is to listen to the port until the socket becomes available and then call `loop_acceptor/1`. `loop_acceptor/1` is a loop accepting client connections. For each accepted connection, we call `serve/1`. `serve/1` is another loop that reads a line from the socket and writes those lines back to the socket. Note that the `serve/1` function uses [the pipe operator `|>`](https://hexdocs.pm/elixir/Kernel.html#%7C%3E/2) to express this flow of operations. The pipe operator evaluates the left side and passes its result as the first argument to the function on the right side. The example above: ``` socket |> read_line() |> write_line(socket) ``` is equivalent to: ``` write_line(read_line(socket), socket) ``` The `read_line/1` implementation receives data from the socket using `:gen_tcp.recv/2` and `write_line/2` writes to the socket using `:gen_tcp.send/2`. Note that `serve/1` is an infinite loop called sequentially inside `loop_acceptor/1`, so the tail call to `loop_acceptor/1` is never reached and could be avoided. However, as we shall see, we will need to execute `serve/1` in a separate process, so we will need that tail call soon. This is pretty much all we need to implement our echo server. Let’s give it a try! Start an IEx session inside the `kv_server` application with `iex -S mix`. Inside IEx, run: ``` iex> KVServer.accept(4040) ``` The server is now running, and you will even notice the console is blocked. Let’s use [a `telnet` client](https://en.wikipedia.org/wiki/Telnet) to access our server. There are clients available on most operating systems, and their command lines are generally similar: ``` $ telnet 127.0.0.1 4040 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. hello hello is it me is it me you are looking for? you are looking for? ``` Type “hello”, press enter, and you will get “hello” back. Excellent! My particular telnet client can be exited by typing `ctrl + ]`, typing `quit`, and pressing `<Enter>`, but your client may require different steps. Once you exit the telnet client, you will likely see an error in the IEx session: ``` ** (MatchError) no match of right hand side value: {:error, :closed} (kv_server) lib/kv_server.ex:45: KVServer.read_line/1 (kv_server) lib/kv_server.ex:37: KVServer.serve/1 (kv_server) lib/kv_server.ex:30: KVServer.loop_acceptor/1 ``` That’s because we were expecting data from `:gen_tcp.recv/2` but the client closed the connection. We need to handle such cases better in future revisions of our server. For now, there is a more important bug we need to fix: what happens if our TCP acceptor crashes? Since there is no supervision, the server dies and we won’t be able to serve more requests, because it won’t be restarted. That’s why we must move our server to a supervision tree. Tasks ----- We have learned about agents, generic servers, and supervisors. They are all meant to work with multiple messages or manage state. But what do we use when we only need to execute some task and that is it? [The Task module](https://hexdocs.pm/elixir/Task.html) provides this functionality exactly. For example, it has a `start_link/1` function that receives an anonymous function and executes it inside a new process that will be part of a supervision tree. Let’s give it a try. Open up `lib/kv_server/application.ex`, and let’s change the supervisor in the `start/2` function to the following: ``` def start(_type, _args) do children = [ {Task, fn -> KVServer.accept(4040) end} ] opts = [strategy: :one_for_one, name: KVServer.Supervisor] Supervisor.start_link(children, opts) end ``` As usual, we’ve passed a two-element tuple as a child specification, which in turn will invoke `Task.start_link/1`. With this change, we are saying that we want to run `KVServer.accept(4040)` as a task. We are hardcoding the port for now but this could be changed in a few ways, for example, by reading the port out of the system environment when starting the application: ``` port = String.to_integer(System.get_env("PORT") || "4040") # ... {Task, fn -> KVServer.accept(port) end} ``` Insert these changes in your code and now you may start your application using the following command `PORT=4321 mix run --no-halt`, notice how we are passing the port as a variable, but still defaults to 4040 if none is given. Now that the server is part of the supervision tree, it should start automatically when we run the application. Start your server, now passing the port, and once again use the `telnet` client to make sure that everything still works: ``` $ telnet 127.0.0.1 4040 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. say you say you say me say me ``` Yes, it works! However, does it *scale*? Try to connect two telnet clients at the same time. When you do so, you will notice that the second client doesn’t echo: ``` $ telnet 127.0.0.1 4040 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. hello hello? HELLOOOOOO? ``` It doesn’t seem to work at all. That’s because we are serving requests in the same process that are accepting connections. When one client is connected, we can’t accept another client. Task supervisor --------------- In order to make our server handle simultaneous connections, we need to have one process working as an acceptor that spawns other processes to serve requests. One solution would be to change: ``` defp loop_acceptor(socket) do {:ok, client} = :gen_tcp.accept(socket) serve(client) loop_acceptor(socket) end ``` to also use `Task.start_link/1`: ``` defp loop_acceptor(socket) do {:ok, client} = :gen_tcp.accept(socket) Task.start_link(fn -> serve(client) end) loop_acceptor(socket) end ``` We are starting a linked Task directly from the acceptor process. But we’ve already made this mistake once. Do you remember? This is similar to the mistake we made when we called `KV.Bucket.start_link/1` straight from the registry. That meant a failure in any bucket would bring the whole registry down. The code above would have the same flaw: if we link the `serve(client)` task to the acceptor, a crash when serving a request would bring the acceptor, and consequently all other connections, down. We fixed the issue for the registry by using a simple one for one supervisor. We are going to use the same tactic here, except that this pattern is so common with tasks that `Task` already comes with a solution: a simple one for one supervisor that starts temporary tasks as part of our supervision tree. Let’s change `start/2` once again, to add a supervisor to our tree: ``` def start(_type, _args) do port = String.to_integer(System.get_env("PORT") || "4040") children = [ {Task.Supervisor, name: KVServer.TaskSupervisor}, {Task, fn -> KVServer.accept(port) end} ] opts = [strategy: :one_for_one, name: KVServer.Supervisor] Supervisor.start_link(children, opts) end ``` We’ll now start a [`Task.Supervisor`](https://hexdocs.pm/elixir/Task.Supervisor.html) process with name `KVServer.TaskSupervisor`. Remember, since the acceptor task depends on this supervisor, the supervisor must be started first. Now we need to change `loop_acceptor/1` to use `Task.Supervisor` to serve each request: ``` defp loop_acceptor(socket) do {:ok, client} = :gen_tcp.accept(socket) {:ok, pid} = Task.Supervisor.start_child(KVServer.TaskSupervisor, fn -> serve(client) end) :ok = :gen_tcp.controlling_process(client, pid) loop_acceptor(socket) end ``` You might notice that we added a line, `:ok = :gen_tcp.controlling_process(client, pid)`. This makes the child process the “controlling process” of the `client` socket. If we didn’t do this, the acceptor would bring down all the clients if it crashed because sockets would be tied to the process that accepted them (which is the default behaviour). Start a new server with `PORT=4040 mix run --no-halt` and we can now open up many concurrent telnet clients. You will also notice that quitting a client does not bring the acceptor down. Excellent! Here is the full echo server implementation: ``` defmodule KVServer do require Logger @doc """ Starts accepting connections on the given `port`. """ def accept(port) do {:ok, socket} = :gen_tcp.listen(port, [:binary, packet: :line, active: false, reuseaddr: true]) Logger.info "Accepting connections on port #{port}" loop_acceptor(socket) end defp loop_acceptor(socket) do {:ok, client} = :gen_tcp.accept(socket) {:ok, pid} = Task.Supervisor.start_child(KVServer.TaskSupervisor, fn -> serve(client) end) :ok = :gen_tcp.controlling_process(client, pid) loop_acceptor(socket) end defp serve(socket) do socket |> read_line() |> write_line(socket) serve(socket) end defp read_line(socket) do {:ok, data} = :gen_tcp.recv(socket, 0) data end defp write_line(line, socket) do :gen_tcp.send(socket, line) end end ``` Since we have changed the supervisor specification, we need to ask: is our supervision strategy still correct? In this case, the answer is yes: if the acceptor crashes, there is no need to crash the existing connections. On the other hand, if the task supervisor crashes, there is no need to crash the acceptor too. However, there is still one concern left, which are the restart strategies. Tasks, by default, have the `:restart` value set to `:temporary`, which means they are not restarted. This is an excellent default for the connections started via the `Task.Supervisor`, as it makes no sense to restart a failed connection, but it is a bad choice for the acceptor. If the acceptor crashes, we want to bring the acceptor up and running again. We could fix this by defining our own module that calls `use Task, restart: :permanent` and invokes a `start_link` function responsible for restarting the task, quite similar to `Agent` and `GenServer`. However, let’s take a different approach here. When integrating with someone else’s library, we won’t be able to change how their agents, tasks, and servers are defined. Instead, we need to be able to customize their child specification dynamically. This can be done by using `Supervisor.child_spec/2`, a function that we happen to know from previous chapters. Let’s rewrite `start/2` in `KVServer.Application` once more: ``` def start(_type, _args) do port = String.to_integer(System.get_env("PORT") || "4040") children = [ {Task.Supervisor, name: KVServer.TaskSupervisor}, Supervisor.child_spec({Task, fn -> KVServer.accept(port) end}, restart: :permanent) ] opts = [strategy: :one_for_one, name: KVServer.Supervisor] Supervisor.start_link(children, opts) end ``` `Supervisor.child_spec/2` is capable of building a child specification from a given module and/or tuple, and it also accepts values that override the underlying child specification. Now we have an always running acceptor that starts temporary task processes under an always running task supervisor. In the next chapter, we will start parsing the client requests and sending responses, finishing our server. elixir Doctests, patterns and with Mix and OTP Doctests, patterns and with =========================== > This chapter is part of the *Mix and OTP guide* and it depends on previous chapters in this guide. For more information, [read the introduction guide](introduction-to-mix) or check out the chapter index in the sidebar. > > In this chapter, we will implement the code that parses the commands we described in the first chapter: ``` CREATE shopping OK PUT shopping milk 1 OK PUT shopping eggs 3 OK GET shopping milk 1 OK DELETE shopping eggs OK ``` After the parsing is done, we will update our server to dispatch the parsed commands to the `:kv` application we built previously. Doctests -------- On the language homepage, we mention that Elixir makes documentation a first-class citizen in the language. We have explored this concept many times throughout this guide, be it via `mix help` or by typing `h Enum` or another module in an IEx console. In this section, we will implement the parsing functionality, document it and make sure our documentation is up to date with doctests. This helps us provide documentation with accurate code samples. Let’s create our command parser at `lib/kv_server/command.ex` and start with the doctest: ``` defmodule KVServer.Command do @doc ~S""" Parses the given `line` into a command. ## Examples iex> KVServer.Command.parse("CREATE shopping\r\n") {:ok, {:create, "shopping"}} """ def parse(_line) do :not_implemented end end ``` Doctests are specified by an indentation of four spaces followed by the `iex>` prompt in a documentation string. If a command spans multiple lines, you can use `...>`, as in IEx. The expected result should start at the next line after `iex>` or `...>` line(s) and is terminated either by a newline or a new `iex>` prefix. Also, note that we started the documentation string using `@doc ~S"""`. The `~S` prevents the `\r\n` characters from being converted to a carriage return and line feed until they are evaluated in the test. To run our doctests, we’ll create a file at `test/kv_server/command_test.exs` and call `doctest KVServer.Command` in the test case: ``` defmodule KVServer.CommandTest do use ExUnit.Case, async: true doctest KVServer.Command end ``` Run the test suite and the doctest should fail: ``` 1) test doc at KVServer.Command.parse/1 (1) (KVServer.CommandTest) test/kv_server/command_test.exs:3 Doctest failed code: KVServer.Command.parse "CREATE shopping\r\n" === {:ok, {:create, "shopping"}} lhs: :not_implemented stacktrace: lib/kv_server/command.ex:7: KVServer.Command (module) ``` Excellent! Now let’s make the doctest pass. Let’s implement the `parse/1` function: ``` def parse(line) do case String.split(line) do ["CREATE", bucket] -> {:ok, {:create, bucket}} end end ``` Our implementation splits the line on whitespace and then matches the command against a list. Using `String.split/1` means our commands will be whitespace-insensitive. Leading and trailing whitespace won’t matter, nor will consecutive spaces between words. Let’s add some new doctests to test this behaviour along with the other commands: ``` @doc ~S""" Parses the given `line` into a command. ## Examples iex> KVServer.Command.parse "CREATE shopping\r\n" {:ok, {:create, "shopping"}} iex> KVServer.Command.parse "CREATE shopping \r\n" {:ok, {:create, "shopping"}} iex> KVServer.Command.parse "PUT shopping milk 1\r\n" {:ok, {:put, "shopping", "milk", "1"}} iex> KVServer.Command.parse "GET shopping milk\r\n" {:ok, {:get, "shopping", "milk"}} iex> KVServer.Command.parse "DELETE shopping eggs\r\n" {:ok, {:delete, "shopping", "eggs"}} Unknown commands or commands with the wrong number of arguments return an error: iex> KVServer.Command.parse "UNKNOWN shopping eggs\r\n" {:error, :unknown_command} iex> KVServer.Command.parse "GET shopping\r\n" {:error, :unknown_command} """ ``` With doctests at hand, it is your turn to make tests pass! Once you’re ready, you can compare your work with our solution below: ``` def parse(line) do case String.split(line) do ["CREATE", bucket] -> {:ok, {:create, bucket}} ["GET", bucket, key] -> {:ok, {:get, bucket, key}} ["PUT", bucket, key, value] -> {:ok, {:put, bucket, key, value}} ["DELETE", bucket, key] -> {:ok, {:delete, bucket, key}} _ -> {:error, :unknown_command} end end ``` Notice how we were able to elegantly parse the commands without adding a bunch of `if/else` clauses that check the command name and number of arguments! Finally, you may have observed that each doctest corresponds to a different test in our suite, which now reports a total of 7 doctests. That is because ExUnit considers the following to define two different doctests: ``` iex> KVServer.Command.parse("UNKNOWN shopping eggs\r\n") {:error, :unknown_command} iex> KVServer.Command.parse("GET shopping\r\n") {:error, :unknown_command} ``` Without new lines, as seen below, ExUnit compiles it into a single doctest: ``` iex> KVServer.Command.parse("UNKNOWN shopping eggs\r\n") {:error, :unknown_command} iex> KVServer.Command.parse("GET shopping\r\n") {:error, :unknown_command} ``` As the name says, doctest is documentation first and a test later. Their goal is not to replace tests but to provide up to date documentation. You can read more about doctests in [the `ExUnit.DocTest` docs](https://hexdocs.pm/ex_unit/ExUnit.DocTest.html). with ---- As we are now able to parse commands, we can finally start implementing the logic that runs the commands. Let’s add a stub definition for this function for now: ``` defmodule KVServer.Command do @doc """ Runs the given command. """ def run(command) do {:ok, "OK\r\n"} end end ``` Before we implement this function, let’s change our server to start using our new `parse/1` and `run/1` functions. Remember, our `read_line/1` function was also crashing when the client closed the socket, so let’s take the opportunity to fix it, too. Open up `lib/kv_server.ex` and replace the existing server definition: ``` defp serve(socket) do socket |> read_line() |> write_line(socket) serve(socket) end defp read_line(socket) do {:ok, data} = :gen_tcp.recv(socket, 0) data end defp write_line(line, socket) do :gen_tcp.send(socket, line) end ``` by the following: ``` defp serve(socket) do msg = case read_line(socket) do {:ok, data} -> case KVServer.Command.parse(data) do {:ok, command} -> KVServer.Command.run(command) {:error, _} = err -> err end {:error, _} = err -> err end write_line(socket, msg) serve(socket) end defp read_line(socket) do :gen_tcp.recv(socket, 0) end defp write_line(socket, {:ok, text}) do :gen_tcp.send(socket, text) end defp write_line(socket, {:error, :unknown_command}) do # Known error; write to the client :gen_tcp.send(socket, "UNKNOWN COMMAND\r\n") end defp write_line(_socket, {:error, :closed}) do # The connection was closed, exit politely exit(:shutdown) end defp write_line(socket, {:error, error}) do # Unknown error; write to the client and exit :gen_tcp.send(socket, "ERROR\r\n") exit(error) end ``` If we start our server, we can now send commands to it. For now, we will get two different responses: “OK” when the command is known and “UNKNOWN COMMAND” otherwise: ``` $ telnet 127.0.0.1 4040 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. CREATE shopping OK HELLO UNKNOWN COMMAND ``` This means our implementation is going in the correct direction, but it doesn’t look very elegant, does it? The previous implementation used pipelines which made the logic straightforward to follow. However, now that we need to handle different error codes along the way, our server logic is nested inside many `case` calls. Thankfully, Elixir v1.2 introduced the `with` construct, which allows you to simplify code like the above, replacing nested `case` calls with a chain of matching clauses. Let’s rewrite the `serve/1` function to use `with`: ``` defp serve(socket) do msg = with {:ok, data} <- read_line(socket), {:ok, command} <- KVServer.Command.parse(data), do: KVServer.Command.run(command) write_line(socket, msg) serve(socket) end ``` Much better! `with` will retrieve the value returned by the right-side of `<-` and match it against the pattern on the left side. If the value matches the pattern, `with` moves on to the next expression. In case there is no match, the non-matching value is returned. In other words, we converted each expression given to `case/2` as a step in `with`. As soon as any of the steps return something that does not match `{:ok, x}`, `with` aborts, and returns the non-matching value. You can read more about [`with` in our documentation](https://hexdocs.pm/elixir/Kernel.SpecialForms.html#with/1). Running commands ---------------- The last step is to implement `KVServer.Command.run/1`, to run the parsed commands against the `:kv` application. Its implementation is shown below: ``` @doc """ Runs the given command. """ def run(command) def run({:create, bucket}) do KV.Registry.create(KV.Registry, bucket) {:ok, "OK\r\n"} end def run({:get, bucket, key}) do lookup(bucket, fn pid -> value = KV.Bucket.get(pid, key) {:ok, "#{value}\r\nOK\r\n"} end) end def run({:put, bucket, key, value}) do lookup(bucket, fn pid -> KV.Bucket.put(pid, key, value) {:ok, "OK\r\n"} end) end def run({:delete, bucket, key}) do lookup(bucket, fn pid -> KV.Bucket.delete(pid, key) {:ok, "OK\r\n"} end) end defp lookup(bucket, callback) do case KV.Registry.lookup(KV.Registry, bucket) do {:ok, pid} -> callback.(pid) :error -> {:error, :not_found} end end ``` Every function clause dispatches the appropriate command to the `KV.Registry` server that we registered during the `:kv` application startup. Since our `:kv_server` depends on the `:kv` application, it is completely fine to depend on the services it provides. You might have noticed we have a function head, `def run(command)`, without a body. In the [Modules and Functions](../modules-and-functions#default-arguments) chapter, we learned that a bodiless function can be used to declare default arguments for a multi-clause function. Here is another use case where we use a function without a body to document what the arguments are. Note that we have also defined a private function named `lookup/2` to help with the common functionality of looking up a bucket and returning its `pid` if it exists, `{:error, :not_found}` otherwise. By the way, since we are now returning `{:error, :not_found}`, we should amend the `write_line/2` function in `KVServer` to print such error as well: ``` defp write_line(socket, {:error, :not_found}) do :gen_tcp.send(socket, "NOT FOUND\r\n") end ``` Our server functionality is almost complete. Only tests are missing. This time, we have left tests for last because there are some important considerations to be made. `KVServer.Command.run/1`’s implementation is sending commands directly to the server named `KV.Registry`, which is registered by the `:kv` application. This means this server is global and if we have two tests sending messages to it at the same time, our tests will conflict with each other (and likely fail). We need to decide between having unit tests that are isolated and can run asynchronously, or writing integration tests that work on top of the global state, but exercise our application’s full stack as it is meant to be exercised in production. So far we have only written unit tests, typically testing a single module directly. However, in order to make `KVServer.Command.run/1` testable as a unit we would need to change its implementation to not send commands directly to the `KV.Registry` process but instead pass a server as an argument. For example, we would need to change `run`’s signature to `def run(command, pid)` and then change all clauses accordingly: ``` def run({:create, bucket}, pid) do KV.Registry.create(pid, bucket) {:ok, "OK\r\n"} end # ... other run clauses ... ``` Feel free to go ahead and do the changes above and write some unit tests. The idea is that your tests will start an instance of the `KV.Registry` and pass it as an argument to `run/2` instead of relying on the global `KV.Registry`. This has the advantage of keeping our tests asynchronous as there is no shared state. But let’s also try something different. Let’s write integration tests that rely on the global server names to exercise the whole stack from the TCP server to the bucket. Our integration tests will rely on global state and must be synchronous. With integration tests, we get coverage on how the components in our application work together at the cost of test performance. They are typically used to test the main flows in your application. For example, we should avoid using integration tests to test an edge case in our command parsing implementation. Our integration test will use a TCP client that sends commands to our server and assert we are getting the desired responses. Let’s implement the integration test in `test/kv_server_test.exs` as shown below: ``` defmodule KVServerTest do use ExUnit.Case setup do Application.stop(:kv) :ok = Application.start(:kv) end setup do opts = [:binary, packet: :line, active: false] {:ok, socket} = :gen_tcp.connect('localhost', 4040, opts) %{socket: socket} end test "server interaction", %{socket: socket} do assert send_and_recv(socket, "UNKNOWN shopping\r\n") == "UNKNOWN COMMAND\r\n" assert send_and_recv(socket, "GET shopping eggs\r\n") == "NOT FOUND\r\n" assert send_and_recv(socket, "CREATE shopping\r\n") == "OK\r\n" assert send_and_recv(socket, "PUT shopping eggs 3\r\n") == "OK\r\n" # GET returns two lines assert send_and_recv(socket, "GET shopping eggs\r\n") == "3\r\n" assert send_and_recv(socket, "") == "OK\r\n" assert send_and_recv(socket, "DELETE shopping eggs\r\n") == "OK\r\n" # GET returns two lines assert send_and_recv(socket, "GET shopping eggs\r\n") == "\r\n" assert send_and_recv(socket, "") == "OK\r\n" end defp send_and_recv(socket, command) do :ok = :gen_tcp.send(socket, command) {:ok, data} = :gen_tcp.recv(socket, 0, 1000) data end end ``` Our integration test checks all server interaction, including unknown commands and not found errors. It is worth noting that, as with ETS tables and linked processes, there is no need to close the socket. Once the test process exits, the socket is automatically closed. This time, since our test relies on global data, we have not given `async: true` to `use ExUnit.Case`. Furthermore, in order to guarantee our test is always in a clean state, we stop and start the `:kv` application before each test. In fact, stopping the `:kv` application even prints a warning on the terminal: ``` 18:12:10.698 [info] Application kv exited: :stopped ``` To avoid printing log messages during tests, ExUnit provides a neat feature called `:capture_log`. By setting `@tag :capture_log` before each test or `@moduletag :capture_log` for the whole test case, ExUnit will automatically capture anything that is logged while the test runs. In case our test fails, the captured logs will be printed alongside the ExUnit report. Between `use ExUnit.Case` and setup, add the following call: ``` @moduletag :capture_log ``` In case the test crashes, you will see a report as follows: ``` 1) test server interaction (KVServerTest) test/kv_server_test.exs:17 ** (RuntimeError) oops stacktrace: test/kv_server_test.exs:29 The following output was logged: 13:44:10.035 [info] Application kv exited: :stopped ``` With this simple integration test, we start to see why integration tests may be slow. Not only can this test not run asynchronously, but it also requires the expensive setup of stopping and starting the `:kv` application. In fact, your test suite may even fail and run into timeouts. If that’s the case, you can tweak the `:gen_tcp.recv(socket, 0)` call to pass a third argument, which is the timeout in milliseconds. In the next chapter we will learn about application configuration, which we could use to make the timeout configurable, if desired. At the end of the day, it is up to you and your team to figure out the best testing strategy for your applications. You need to balance code quality, confidence, and test suite runtime. For example, we may start with testing the server only with integration tests, but if the server continues to grow in future releases, or it becomes a part of the application with frequent bugs, it is important to consider breaking it apart and writing more intensive unit tests that don’t have the weight of an integration test. Let’s move to the next chapter. We will finally make our system distributed by adding a bucket routing mechanism. We will use this opportunity to also improve our testing chops.
programming_docs
elixir Supervisor and Application Mix and OTP Supervisor and Application ========================== > This chapter is part of the *Mix and OTP guide* and it depends on previous chapters in this guide. For more information, [read the introduction guide](introduction-to-mix) or check out the chapter index in the sidebar. > > In the previous chapter about `GenServer`, we implemented `KV.Registry` to manage buckets. At some point, we started monitoring buckets so we were able to take action whenever a `KV.Bucket` crashed. Although the change was relatively small, it introduced a question which is frequently asked by Elixir developers: what happens when something fails? Before we added monitoring, if a bucket crashed, the registry would forever point to a bucket that no longer exists. If a user tried to read or write to the crashed bucket, it would fail. Any attempt at creating a new bucket with the same name would just return the PID of the crashed bucket. In other words, that registry entry for that bucket would forever be in a bad state. Once we added monitoring, the registry automatically removes the entry for the crashed bucket. Trying to lookup the crashed bucket now (correctly) says the bucket does not exist and a user of the system can successfully create a new one if desired. In practice, we are not expecting the processes working as buckets to fail. But, if it does happen, for whatever reason, we can rest assured that our system will continue to work as intended. If you have prior programming experience, you may be wondering: “could we just guarantee the bucket does not crash in the first place?”. As we will see, Elixir developers tend to refer to those practices as “defensive programming”. That’s because a live production system has dozens of different reasons why something can go wrong. The disk can fail, memory can be corrupted, bugs, the network may stop working for a second, etc. If we were to write software that attempted to protect or circumvent all of those errors, we would spend more time handling failures than writing our own software! Therefore, an Elixir developer prefers to “let it crash” or “fail fast”. And one of the most common ways we can recover from a failure is by restarting whatever part of the system crashed. For example, imagine your computer, router, printer, or whatever device is not working properly. How often do you fix it by restarting it? Once we restart the device, we reset the device back to its initial state, which is well-tested and guaranteed to work. In Elixir, we apply this same approach to software: whenever a process crashes, we start a new process to perform the same job as the crashed process. In Elixir, this is done by a Supervisor. A Supervisor is a process that supervises other processes and restarts them whenever they crash. To do so, Supervisors manage the whole life-cycle of any supervised processes, including startup and shutdown. In this chapter, we will learn how to put those concepts into practice by supervising the `KV.Registry` process. After all, if something goes wrong with the registry, the whole registry is lost and no bucket could ever be found! To address this, we will define a `KV.Supervisor` module that guarantees that our `KV.Registry` is up and running at any given moment. At the end of the chapter, we will also talk about Applications. As we will see, Mix has been packaging all of our code into an application, and we will learn how to customize our application to guarantee that our Supervisor and the Registry are up and running whenever our system starts. Our first supervisor -------------------- A supervisor is a process which supervises other processes, which we refer to as child processes. The act of supervising a process includes three distinct responsibilities. The first one is to start child processes. Once a child process is running, the supervisor may restart a child process, either because it terminated abnormally or because a certain condition was reached. For example, a supervisor may restart all children if any child dies. Finally, a supervisor is also responsible for shutting down the child processes when the system is shutting down. Please see the [Supervisor](https://hexdocs.pm/elixir/Supervisor.html) module for a more in-depth discussion. Creating a supervisor is not much different from creating a GenServer. We are going to define a module named `KV.Supervisor`, which will use the Supervisor behaviour, inside the `lib/kv/supervisor.ex` file: ``` defmodule KV.Supervisor do use Supervisor def start_link(opts) do Supervisor.start_link(__MODULE__, :ok, opts) end @impl true def init(:ok) do children = [ KV.Registry ] Supervisor.init(children, strategy: :one_for_one) end end ``` Our supervisor has a single child so far: `KV.Registry`. After we define a list of children, we call `Supervisor.init/2`, passing the children and the supervision strategy. The supervision strategy dictates what happens when one of the children crashes. `:one_for_one` means that if a child dies, it will be the only one restarted. Since we have only one child now, that’s all we need. The `Supervisor` behaviour supports many different strategies and we will discuss them in this chapter. Once the supervisor starts, it will traverse the list of children and it will invoke the `child_spec/1` function on each module. The `child_spec/1` function returns the child specification which describes how to start the process, if the process is a worker or a supervisor, if the process is temporary, transient or permanent and so on. The `child_spec/1` function is automatically defined when we `use Agent`, `use GenServer`, `use Supervisor`, etc. Let’s give it a try in the terminal with `iex -S mix`: ``` iex(1)> KV.Registry.child_spec([]) %{id: KV.Registry, start: {KV.Registry, :start_link, [[]]}} ``` We will learn those details as we move forward on this guide. If you would rather peek ahead, check the [Supervisor](https://hexdocs.pm/elixir/Supervisor.html) docs. After the supervisor retrieves all child specifications, it proceeds to start its children one by one, in the order they were defined, using the information in the `:start` key in the child specification. For our current specification, it will call `KV.Registry.start_link([])`. Let’s take the supervisor for a spin: ``` iex(1)> {:ok, sup} = KV.Supervisor.start_link([]) {:ok, #PID<0.148.0>} iex(2)> Supervisor.which_children(sup) [{KV.Registry, #PID<0.150.0>, :worker, [KV.Registry]}] ``` So far we have started the supervisor and listed its children. Once the supervisor started, it also started all of its children. What happens if we intentionally crash the registry started by the supervisor? Let’s do so by sending it a bad input on `call`: ``` iex(3)> [{_, registry, _, _}] = Supervisor.which_children(sup) [{KV.Registry, #PID<0.150.0>, :worker, [KV.Registry]}] iex(4) GenServer.call(registry, :bad_input) 08:52:57.311 [error] GenServer KV.Registry terminating ** (FunctionClauseError) no function clause matching in KV.Registry.handle_call/3 iex(5) Supervisor.which_children(sup) [{KV.Registry, #PID<0.157.0>, :worker, [KV.Registry]}] ``` Notice how the supervisor automatically started a new registry, with a new PID, in place of the first one once we caused it to crash due to a bad input. In the previous chapters, we have always started processes directly. For example, we would call `KV.Registry.start_link([])`, which would return `{:ok, pid}`, and that would allow us to interact with the registry via its `pid`. Now that processes are started by the supervisor, we have to directly ask the supervisor who its children are, and fetch the pid from the returned list of children. In practice, doing so every time would be very expensive. To address this, we often give names to processes, allowing them to be uniquely identified in a single machine from anywhere in our code. Let’s learn how to do that. Naming processes ---------------- While our application will have many buckets, it will only have a single registry. Therefore, whenever we start the registry, we want to give it a unique name so we can reach out to it from anywhere. We do so by passing a `:name` option to `KV.Registry.start_link/1`. Let’s slightly change our children definition (in `KV.Supervisor.init/1`) to be a list of tuples instead of a list of atoms: ``` def init(:ok) do children = [ {KV.Registry, name: KV.Registry} ] ``` With this in place, the supervisor will now start `KV.Registry` by calling `KV.Registry.start_link(name: KV.Registry)`. If you revisit the `KV.Registry.start_link/1` implementation, you will remember it simply passes the options to GenServer: ``` def start_link(opts) do GenServer.start_link(__MODULE__, :ok, opts) end ``` which in turn will register the process with the given name. The `:name` option expects an atom for locally named processes (locally named means it is available to this machine - there are other options, which we won’t discuss here). Since module identifiers are atoms (try `i(KV.Registry)` in IEx), we can name a process after the module that implements it, provided there is only one process for that name. This helps when debugging and introspecting the system. Let’s give the updated supervisor a try inside `iex -S mix`: ``` iex> KV.Supervisor.start_link([]) {:ok, #PID<0.66.0>} iex> KV.Registry.create(KV.Registry, "shopping") :ok iex> KV.Registry.lookup(KV.Registry, "shopping") {:ok, #PID<0.70.0>} ``` This time the supervisor started a named registry, allowing us to create buckets without having to explicitly fetch the PID from the supervisor. You should also know how to make the registry crash again, without looking up its PID: give it a try. > At this point, you may be wondering: should you also locally name bucket processes? Remember buckets are started dynamically based on user input. Since local names MUST be atoms, we would have to dynamically create atoms, which is a bad idea since once an atom is defined, it is never erased nor garbage collected. This means that, if we create atoms dynamically based on user input, we will eventually run out of memory (or to be more precise, the VM will crash because it imposes a hard limit on the number of atoms). This limitation is precisely why we created our own registry (or why one would use Elixir’s built-in [`Registry`](https://hexdocs.pm/elixir/Registry.html) module). > > We are getting closer and closer to a fully working system. The supervisor automatically starts the registry. But how can we automatically start the supervisor whenever our system starts? To answer this question, let’s talk about applications. Understanding applications -------------------------- We have been working inside an application this entire time. Every time we changed a file and ran `mix compile`, we could see a `Generated kv app` message in the compilation output. We can find the generated `.app` file at `_build/dev/lib/kv/ebin/kv.app`. Let’s have a look at its contents: ``` {application,kv, [{applications,[kernel,stdlib,elixir,logger]}, {description,"kv"}, {modules,['Elixir.KV','Elixir.KV.Bucket','Elixir.KV.Registry', 'Elixir.KV.Supervisor']}, {registered,[]}, {vsn,"0.1.0"}]}. ``` This file contains Erlang terms (written using Erlang syntax). Even though we are not familiar with Erlang, it is easy to guess this file holds our application definition. It contains our application `version`, all the modules defined by it, as well as a list of applications we depend on, like Erlang’s `kernel`, `elixir` itself, and `logger`. > The `logger` application ships as part of Elixir. We stated that our application needs it by specifying it in the `:extra_applications` list in `mix.exs`. See the [official docs](https://hexdocs.pm/logger) for more information. > > In a nutshell, an application consists of all of the modules defined in the `.app` file, including the `.app` file itself. An application has generally only two directories: `ebin`, for Elixir artefacts, such as `.beam` and `.app` files, and `priv`, with any other artefact or asset you may need in your application. Although Mix generates and maintains the `.app` file for us, we can customize its contents by adding new entries to the `application/0` function inside the `mix.exs` project file. We are going to do our first customization soon. ### Starting applications Each application in our system can be started and stopped. The rules for starting and stopping an application are also defined in the `.app` file. When we invoke `iex -S mix`, Mix compiles our application and then starts it. Let’s see this in practice. Start a console with `iex -S mix` and try: ``` iex> Application.start(:kv) {:error, {:already_started, :kv}} ``` Oops, it’s already started. Mix starts the current application and all of its dependencies automatically. This is also true for `mix test` and many other Mix commands. You can change this behaviour by giving the `--no-start` flag to Mix. It is rarely used in practice but it allows us to understand the underlying mechanisms better. Let’s give it a try. Invoking `mix` is the same as `mix run`. Therefore, if you want to pass a flag to `mix` or `iex -S mix`, we just need to add the task name and the desired flags. For example, run `iex -S mix run --no-start`: ``` iex> Application.start(:kv) :ok ``` We can stop our `:kv` application as well as the `:logger` application, which is started by default with Elixir: ``` iex> Application.stop(:kv) :ok iex> Application.stop(:logger) :ok ``` And let’s try to start our application again: ``` iex> Application.start(:kv) {:error, {:not_started, :logger}} ``` Now we get an error because an application that `:kv` depends on (`:logger` in this case) isn’t started. We need to either start each application manually in the correct order or call `Application.ensure_all_started` as follows: ``` iex> Application.ensure_all_started(:kv) {:ok, [:logger, :kv]} ``` In practice, our tools always start our applications for us, but there is an API available if you need fine-grained control. The application callback ------------------------ Whenever we invoke `iex -S mix`, Mix automatically starts our application by calling `Application.start(:kv)`. But can we customize what happens when our application starts? As a matter of fact, we can! To do so, we define an application callback. The first step is to tell our application definition (i.e. our `.app` file) which module is going to implement the application callback. Let’s do so by opening `mix.exs` and changing `def application` to the following: ``` def application do [ extra_applications: [:logger], mod: {KV, []} ] end ``` The `:mod` option specifies the “application callback module”, followed by the arguments to be passed on application start. The application callback module can be any module that implements the [Application](https://hexdocs.pm/elixir/Application.html) behaviour. To implement the `Application` behaviour, we have to `use Application` and define a `start/2` function. The goal of `start/2` is to start a supervisor, which will then start any child services or execute any other code our application may need. Let’s use this opportunity to start the `KV.Supervisor` we have implemented earlier in this chapter. Since we have specified `KV` as the module callback, let’s change the `KV` module defined in `lib/kv.ex` to implement a `start/2` function: ``` defmodule KV do use Application @impl true def start(_type, _args) do # Although we don't use the supervisor name below directly, # it can be useful when debugging or introspecting the system. KV.Supervisor.start_link(name: KV.Supervisor) end end ``` > Please note that by doing this, we are breaking the boilerplate test case which tested the `hello` function in `KV`. You can simply remove that test case. > > When we `use Application`, we may define a couple of functions, similar to when we used `Supervisor` or `GenServer`. This time we only had to define a `start/2` function. The `Application` behaviour also has a `stop/1` callback, but it is rarely used in practice. You can check the documentation for more information. Now that you have defined an application callback which starts our supervisor, we expect the `KV.Registry` process to be up and running as soon we start `iex -S mix`. Let’s give it another try: ``` iex(1)> KV.Registry.create(KV.Registry, "shopping") :ok iex(2)> KV.Registry.lookup(KV.Registry, "shopping") {:ok, #PID<0.88.0>} ``` Let’s recap what is happening. Whenever we invoke `iex -S mix`, it automatically starts our application by calling `Application.start(:kv)`, which then invokes the application callback. The application callback’s job is to start a **supervision tree**. Right now, we only have a single supervisor, but sometimes a supervisor is also supervised, giving it a shape of a tree. So far, our supervisor has a single child, a `KV.Registry`, which is started with name `KV.Registry`. Projects or applications? ------------------------- Mix makes a distinction between projects and applications. Based on the contents of our `mix.exs` file, we would say we have a Mix project that defines the `:kv` application. As we will see in later chapters, there are projects that don’t define any application. When we say “project” you should think about Mix. Mix is the tool that manages your project. It knows how to compile your project, test your project and more. It also knows how to compile and start the application relevant to your project. When we talk about applications, we talk about OTP. Applications are the entities that are started and stopped as a whole by the runtime. You can learn more about applications and how they relate to booting and shutting down of your system as a whole in the [docs for the Application module](https://hexdocs.pm/elixir/Application.html). Next steps ---------- Although this chapter was the first time we implemented a supervisor, it was not the first time we used one! In the previous chapter, when we used `start_supervised!` to start the registry during our tests, `ExUnit` started the registry under a supervisor managed by the ExUnit framework itself. By defining our own supervisor, we provide more structure on how we initialize, shutdown and supervise processes in our applications, aligning our production code and tests with best practices. But we are not done yet. So far we are supervising the registry but our application is also starting buckets. Since buckets are started dynamically, they have to be supervised by a special type of supervisor, called `DynamicSupervisor`, which we will explore next. elixir Dynamic supervisors Mix and OTP Dynamic supervisors =================== > This chapter is part of the *Mix and OTP guide* and it depends on previous chapters in this guide. For more information, [read the introduction guide](introduction-to-mix) or check out the chapter index in the sidebar. > > We have now successfully defined our supervisor which is automatically started (and stopped) as part of our application lifecycle. Remember however that our `KV.Registry` is both linking (via `start_link`) and monitoring (via `monitor`) bucket processes in the `handle_cast/2` callback: ``` {:ok, bucket} = KV.Bucket.start_link([]) ref = Process.monitor(bucket) ``` Links are bidirectional, which implies that a crash in a bucket will crash the registry. Although we now have the supervisor, which guarantees the registry will be back up and running, crashing the registry still means we lose all data associating bucket names to their respective processes. In other words, we want the registry to keep on running even if a bucket crashes. Let’s write a new registry test: ``` test "removes bucket on crash", %{registry: registry} do KV.Registry.create(registry, "shopping") {:ok, bucket} = KV.Registry.lookup(registry, "shopping") # Stop the bucket with non-normal reason Agent.stop(bucket, :shutdown) assert KV.Registry.lookup(registry, "shopping") == :error end ``` The test is similar to “removes bucket on exit” except that we are being a bit more harsh by sending `:shutdown` as the exit reason instead of `:normal`. If a process terminates with a reason different than `:normal`, all linked processes receive an EXIT signal, causing the linked process to also terminate unless it is trapping exits. Since the bucket terminated, the registry also stopped, and our test fails when trying to `GenServer.call/3` it: ``` 1) test removes bucket on crash (KV.RegistryTest) test/kv/registry_test.exs:26 ** (exit) exited in: GenServer.call(#PID<0.148.0>, {:lookup, "shopping"}, 5000) ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started code: assert KV.Registry.lookup(registry, "shopping") == :error stacktrace: (elixir) lib/gen_server.ex:770: GenServer.call/3 test/kv/registry_test.exs:33: (test) ``` We are going to solve this issue by defining a new supervisor that will spawn and supervise all buckets. Opposite to the previous Supervisor we defined, the children are not known upfront, but they are rather started dynamically. For those situations, we use a `DynamicSupervisor`. The `DynamicSupervisor` does not expect a list of children during initialization; instead each child is started manually via `DynamicSupervisor.start_child/2`. The bucket supervisor --------------------- Since a `DynamicSupervisor` does not define any children during initialization, the `DynamicSupervisor` also allows us to skip the work of defining a whole separate module with the usual `start_link` function and the `init` callback. Instead, we can define a `DynamicSupervisor` directly in the supervision tree, by giving it a name and a strategy. Open up `lib/kv/supervisor.ex` and add the dynamic supervisor as a child as follows: ``` def init(:ok) do children = [ {KV.Registry, name: KV.Registry}, {DynamicSupervisor, name: KV.BucketSupervisor, strategy: :one_for_one} ] Supervisor.init(children, strategy: :one_for_one) end ``` Remember that the name of a process can be any atom. So far, we have named processes with the same name as the modules that define their implementation. For example, the process defined by `KV.Registry` was given a process name of `KV.Registry`. This is simply a convention: If later there is an error in your system that says, “process named KV.Registry crashed with reason”, we know exactly where to investigate. In this case, there is no module, so we picked the name `KV.BucketSupervisor`. It could have been any other name. We also chose the `:one_for_one` strategy, which is currently the only available strategy for dynamic supervisors. Run `iex -S mix` so we can give our dynamic supervisor a try: ``` iex> {:ok, bucket} = DynamicSupervisor.start_child(KV.BucketSupervisor, KV.Bucket) {:ok, #PID<0.72.0>} iex> KV.Bucket.put(bucket, "eggs", 3) :ok iex> KV.Bucket.get(bucket, "eggs") 3 ``` `DynamicSupervisor.start_child/2` expects the name of the supervisor and the child specification of the child to be started. The last step is to change the registry to use the dynamic supervisor: ``` def handle_cast({:create, name}, {names, refs}) do if Map.has_key?(names, name) do {:noreply, {names, refs}} else {:ok, pid} = DynamicSupervisor.start_child(KV.BucketSupervisor, KV.Bucket) ref = Process.monitor(pid) refs = Map.put(refs, ref, name) names = Map.put(names, name, pid) {:noreply, {names, refs}} end end ``` That’s enough for our tests to pass but there is a resource leakage in our application. When a bucket terminates, the supervisor will start a new bucket in its place. After all, that’s the role of the supervisor! However, when the supervisor restarts the new bucket, the registry does not know about it. So we will have an empty bucket in the supervisor that nobody can access! To solve this, we want to say that buckets are actually temporary. If they crash, regardless of the reason, they should not be restarted. We can do this by passing the `restart: :temporary` option to `use Agent` in `KV.Bucket`: ``` defmodule KV.Bucket do use Agent, restart: :temporary ``` Let’s also add a test to `test/kv/bucket_test.exs` that guarantees the bucket is temporary: ``` test "are temporary workers" do assert Supervisor.child_spec(KV.Bucket, []).restart == :temporary end ``` Our test uses the `Supervisor.child_spec/2` function to retrieve the child specification out of a module and then assert its restart value is `:temporary`. At this point, you may be wondering why use a supervisor if it never restarts its children. It happens that supervisors provide more than restarts, they are also responsible for guaranteeing proper startup and shutdown, especially in case of crashes in a supervision tree. Supervision trees ----------------- When we added `KV.BucketSupervisor` as a child of `KV.Supervisor`, we began to have supervisors that supervise other supervisors, forming so-called “supervision trees”. Every time you add a new child to a supervisor, it is important to evaluate if the supervisor strategy is correct as well as the order of child processes. In this case, we are using `:one_for_one` and the `KV.Registry` is started before `KV.BucketSupervisor`. One flaw that shows up right away is the ordering issue. Since `KV.Registry` invokes `KV.BucketSupervisor`, then the `KV.BucketSupervisor` must be started before `KV.Registry`. Otherwise, it may happen that the registry attempts to reach the bucket supervisor before it has started. The second flaw is related to the supervision strategy. If `KV.Registry` dies, all information linking `KV.Bucket` names to bucket processes is lost. Therefore the `KV.BucketSupervisor` and all children must terminate too - otherwise we will have orphan processes. In light of this observation, we should consider moving to another supervision strategy. The two other candidates are `:one_for_all` and `:rest_for_one`. A supervisor using the `:rest_for_one` strategy will kill and restart child processes which were started *after* the crashed child. In this case, we would want `KV.BucketSupervisor` to terminate if `KV.Registry` terminates. This would require the bucket supervisor to be placed after the registry which violates the ordering constraints we have established two paragraphs above. So our last option is to go all in and pick the `:one_for_all` strategy: the supervisor will kill and restart all of its children processes whenever any one of them dies. This is a completely reasonable approach for our application, since the registry can’t work without the bucket supervisor, and the bucket supervisor should terminate without the registry. Let’s reimplement `init/1` in `KV.Supervisor` to encode those properties: ``` def init(:ok) do children = [ {DynamicSupervisor, name: KV.BucketSupervisor, strategy: :one_for_one}, {KV.Registry, name: KV.Registry} ] Supervisor.init(children, strategy: :one_for_all) end ``` There are two topics left before we move on to the next chapter. Shared state in tests --------------------- So far we have been starting one registry per test to ensure they are isolated: ``` setup do registry = start_supervised!(KV.Registry) %{registry: registry} end ``` Since we have now changed our registry to use `KV.BucketSupervisor`, which is registered globally, our tests are now relying on this shared supervisor even though each test has its own registry. The question is: should we? It depends. It is ok to rely on shared state as long as we depend only on a non-shared partition of this state. Although multiple registries may start buckets on the shared bucket supervisor, those buckets and registries are isolated from each other. We would only run into concurrency issues if we used a function like `Supervisor.count_children(KV.BucketSupervisor)` which would count all buckets from all registries, potentially giving different results when tests run concurrently. Since we have relied only on a non-shared partition of the bucket supervisor so far, we don’t need to worry about concurrency issues in our test suite. In case it ever becomes a problem, we can start a supervisor per test and pass it as an argument to the registry `start_link` function. Observer -------- Now that we have defined our supervision tree, it is a great opportunity to introduce the Observer tool that ships with Erlang. Start your application with `iex -S mix` and key this in: ``` iex> :observer.start ``` A GUI should pop-up containing all sorts of information about our system, from general statistics to load charts as well as a list of all running processes and applications. > Note: If `observer` does not start, here is what may have happened: some package managers default to installing a minimized Erlang without WX bindings for GUI support. In some package managers, you may be able to replace the headless Erlang with a more complete package (look for packages named `erlang` vs `erlang-nox` on Debian/Ubuntu/Arch). In others managers, you may need to install a separate `erlang-wx` (or similarly named) package. Alternatively, you can skip this section and continue the guide. > > In the Applications tab, you will see all applications currently running in your system alongside their supervision tree. You can select the `kv` application to explore it further: Not only that, as you create new buckets on the terminal, you should see new processes spawned in the supervision tree shown in Observer: ``` iex> KV.Registry.create(KV.Registry, "shopping") :ok ``` We will leave it up to you to further explore what Observer provides. Note you can double click any process in the supervision tree to retrieve more information about it, as well as right-click a process to send “a kill signal”, a perfect way to emulate failures and see if your supervisor reacts as expected. At the end of the day, tools like Observer are one of the reasons you want to always start processes inside supervision trees, even if they are temporary, to ensure they are always reachable and introspectable. Now that our buckets are properly linked and supervised, let’s see how we can speed things up.
programming_docs
elixir ETS Mix and OTP ETS === > This chapter is part of the *Mix and OTP guide* and it depends on previous chapters in this guide. For more information, [read the introduction guide](introduction-to-mix) or check out the chapter index in the sidebar. > > Every time we need to look up a bucket, we need to send a message to the registry. In case our registry is being accessed concurrently by multiple processes, the registry may become a bottleneck! In this chapter, we will learn about ETS (Erlang Term Storage) and how to use it as a cache mechanism. > Warning! Don’t use ETS as a cache prematurely! Log and analyze your application performance and identify which parts are bottlenecks, so you know *whether* you should cache, and *what* you should cache. This chapter is merely an example of how ETS can be used, once you’ve determined the need. > > ETS as a cache -------------- ETS allows us to store any Elixir term in an in-memory table. Working with ETS tables is done via [Erlang’s `:ets` module](http://www.erlang.org/doc/man/ets.html): ``` iex> table = :ets.new(:buckets_registry, [:set, :protected]) #Reference<0.1885502827.460455937.234656> iex> :ets.insert(table, {"foo", self()}) true iex> :ets.lookup(table, "foo") [{"foo", #PID<0.41.0>}] ``` When creating an ETS table, two arguments are required: the table name and a set of options. From the available options, we passed the table type and its access rules. We have chosen the `:set` type, which means that keys cannot be duplicated. We’ve also set the table’s access to `:protected`, meaning only the process that created the table can write to it, but all processes can read from it. The possible access controls: `:public` — Read/Write available to all processes. `:protected` — Read available to all processes. Only writable by owner process. This is the default. `:private` — Read/Write limited to owner process. Be aware that if your Read/Write call violates the access control, the operation will raise `ArgumentError`. Finally, since `:set` and `:protected` are the default values, we will skip them from now on. ETS tables can also be named, allowing us to access them by a given name: ``` iex> :ets.new(:buckets_registry, [:named_table]) :buckets_registry iex> :ets.insert(:buckets_registry, {"foo", self()}) true iex> :ets.lookup(:buckets_registry, "foo") [{"foo", #PID<0.41.0>}] ``` Let’s change the `KV.Registry` to use ETS tables. The first change is to modify our registry to require a name argument, we will use it to name the ETS table and the registry process itself. ETS names and process names are stored in different locations, so there is no chance of conflicts. Open up `lib/kv/registry.ex`, and let’s change its implementation. We’ve added comments to the source code to highlight the changes we’ve made: ``` defmodule KV.Registry do use GenServer ## Client API @doc """ Starts the registry with the given options. `:name` is always required. """ def start_link(opts) do # 1. Pass the name to GenServer's init server = Keyword.fetch!(opts, :name) GenServer.start_link(__MODULE__, server, opts) end @doc """ Looks up the bucket pid for `name` stored in `server`. Returns `{:ok, pid}` if the bucket exists, `:error` otherwise. """ def lookup(server, name) do # 2. Lookup is now done directly in ETS, without accessing the server case :ets.lookup(server, name) do [{^name, pid}] -> {:ok, pid} [] -> :error end end @doc """ Ensures there is a bucket associated with the given `name` in `server`. """ def create(server, name) do GenServer.cast(server, {:create, name}) end ## Server callbacks @impl true def init(table) do # 3. We have replaced the names map by the ETS table names = :ets.new(table, [:named_table, read_concurrency: true]) refs = %{} {:ok, {names, refs}} end # 4. The previous handle_call callback for lookup was removed @impl true def handle_cast({:create, name}, {names, refs}) do # 5. Read and write to the ETS table instead of the map case lookup(names, name) do {:ok, _pid} -> {:noreply, {names, refs}} :error -> {:ok, pid} = DynamicSupervisor.start_child(KV.BucketSupervisor, KV.Bucket) ref = Process.monitor(pid) refs = Map.put(refs, ref, name) :ets.insert(names, {name, pid}) {:noreply, {names, refs}} end end @impl true def handle_info({:DOWN, ref, :process, _pid, _reason}, {names, refs}) do # 6. Delete from the ETS table instead of the map {name, refs} = Map.pop(refs, ref) :ets.delete(names, name) {:noreply, {names, refs}} end @impl true def handle_info(_msg, state) do {:noreply, state} end end ``` Notice that before our changes `KV.Registry.lookup/2` sent requests to the server, but now it reads directly from the ETS table, which is shared across all processes. That’s the main idea behind the cache mechanism we are implementing. In order for the cache mechanism to work, the created ETS table needs to have access `:protected` (the default), so all clients can read from it, while only the `KV.Registry` process writes to it. We have also set `read_concurrency: true` when starting the table, optimizing the table for the common scenario of concurrent read operations. The changes we have performed above have broken our tests because the registry requires the `:name` option when starting up. Furthermore, some registry operations such as `lookup/2` require the name to be given as an argument, instead of a PID, so we can do the ETS table lookup. Let’s change the setup function in `test/kv/registry_test.exs` to fix both issues: ``` setup context do _ = start_supervised!({KV.Registry, name: context.test}) %{registry: context.test} end ``` Since each test has a unique name, we use the test name to name our registries. This way, we no longer need to pass the registry PID around, instead we identify it by the test name. Also note we assigned the result of `start_supervised!` to underscore (`_`). This idiom is often used to signal that we are not interested in the result of `start_supervised!`. Once we change `setup`, some tests will continue to fail. You may even notice tests pass and fail inconsistently between runs. For example, the “spawns buckets” test: ``` test "spawns buckets", %{registry: registry} do assert KV.Registry.lookup(registry, "shopping") == :error KV.Registry.create(registry, "shopping") assert {:ok, bucket} = KV.Registry.lookup(registry, "shopping") KV.Bucket.put(bucket, "milk", 1) assert KV.Bucket.get(bucket, "milk") == 1 end ``` may be failing on this line: ``` {:ok, bucket} = KV.Registry.lookup(registry, "shopping") ``` How can this line fail if we just created the bucket in the previous line? The reason those failures are happening is because, for didactic purposes, we have made two mistakes: 1. We are prematurely optimizing (by adding this cache layer) 2. We are using `cast/2` (while we should be using `call/2`) Race conditions? ---------------- Developing in Elixir does not make your code free of race conditions. However, Elixir’s abstractions where nothing is shared by default make it easier to spot a race condition’s root cause. What is happening in our tests is that there is a delay in between an operation and the time we can observe this change in the ETS table. Here is what we were expecting to happen: 1. We invoke `KV.Registry.create(registry, "shopping")` 2. The registry creates the bucket and updates the cache table 3. We access the information from the table with `KV.Registry.lookup(registry, "shopping")` 4. The command above returns `{:ok, bucket}` However, since `KV.Registry.create/2` is a cast operation, the command will return before we actually write to the table! In other words, this is happening: 1. We invoke `KV.Registry.create(registry, "shopping")` 2. We access the information from the table with `KV.Registry.lookup(registry, "shopping")` 3. The command above returns `:error` 4. The registry creates the bucket and updates the cache table To fix the failure we need to make `KV.Registry.create/2` synchronous by using `call/2` rather than `cast/2`. This will guarantee that the client will only continue after changes have been made to the table. Let’s back to `lib/kv/registry.ex` and change the function and its callback as follows: ``` def create(server, name) do GenServer.call(server, {:create, name}) end ``` ``` @impl true def handle_call({:create, name}, _from, {names, refs}) do case lookup(names, name) do {:ok, pid} -> {:reply, pid, {names, refs}} :error -> {:ok, pid} = DynamicSupervisor.start_child(KV.BucketSupervisor, KV.Bucket) ref = Process.monitor(pid) refs = Map.put(refs, ref, name) :ets.insert(names, {name, pid}) {:reply, pid, {names, refs}} end end ``` We changed the callback from `handle_cast/2` to `handle_call/3` and changed it to reply with the pid of the created bucket. Generally speaking, Elixir developers prefer to use `call/2` instead of `cast/2` as it also provides back-pressure - you block until you get a reply. Using `cast/2` when not necessary can also be considered a premature optimization. Let’s run the tests once again. This time though, we will pass the `--trace` option: ``` $ mix test --trace ``` The `--trace` option is useful when your tests are deadlocking or there are race conditions, as it runs all tests synchronously (`async: true` has no effect) and shows detailed information about each test. If you run the tests multiple times you may see this intermittent failure: ``` 1) test removes buckets on exit (KV.RegistryTest) test/kv/registry_test.exs:19 Assertion with == failed code: KV.Registry.lookup(registry, "shopping") == :error lhs: {:ok, #PID<0.109.0>} rhs: :error stacktrace: test/kv/registry_test.exs:23 ``` According to the failure message, we are expecting that the bucket no longer exists on the table, but it still does! This problem is the opposite of the one we have just solved: while previously there was a delay between the command to create a bucket and updating the table, now there is a delay between the bucket process dying and its entry being removed from the table. Since this is a race condition, you may not be able to reproduce it on your machine, but it is there. Last time we fixed the race condition by replacing the asynchronous operation, a `cast`, by a `call`, which is synchronous. Unfortunately, the `handle_info/2` callback we are using to receive the `:DOWN` message and delete the entry from the ETS table does not have a synchronous equivalent. This time, we need to find a way to guarantee the registry has processed the `:DOWN` notification sent when the bucket process terminated. An easy way to do so is by sending a synchronous request to the registry before we do the bucket lookup. The `Agent.stop/2` operation is synchronous and only returns after the bucket process terminates and all `:DOWN` messages are delivered. Therefore, once `Agent.stop/2` returns, the registry has already received the `:DOWN` message but it may not have processed it yet. In order to guarantee the processing of the `:DOWN` message, we can do a synchronous request. Since messages are processed in order, once the registry replies to the synchronous request, then the `:DOWN` message will definitely have been processed. Let’s do so by creating a “bogus” bucket, which is a synchronous request, after `Agent.stop/2` in both “remove” tests at `test/kv/registry_test.exs`: ``` test "removes buckets on exit", %{registry: registry} do KV.Registry.create(registry, "shopping") {:ok, bucket} = KV.Registry.lookup(registry, "shopping") Agent.stop(bucket) # Do a call to ensure the registry processed the DOWN message _ = KV.Registry.create(registry, "bogus") assert KV.Registry.lookup(registry, "shopping") == :error end test "removes bucket on crash", %{registry: registry} do KV.Registry.create(registry, "shopping") {:ok, bucket} = KV.Registry.lookup(registry, "shopping") # Stop the bucket with non-normal reason Agent.stop(bucket, :shutdown) # Do a call to ensure the registry processed the DOWN message _ = KV.Registry.create(registry, "bogus") assert KV.Registry.lookup(registry, "shopping") == :error end ``` Our tests should now (always) pass! Note that the purpose of the test is to check whether the registry processes the bucket’s shutdown message correctly. The fact that the `KV.Registry.lookup/2` sends us a valid bucket does not mean that the bucket is still alive by the time you call it. For example, it might have crashed for some reason. The following test depicts this situation: ``` test "bucket can crash at any time", %{registry: registry} do KV.Registry.create(registry, "shopping") {:ok, bucket} = KV.Registry.lookup(registry, "shopping") # Simulate a bucket crash by explicitly and synchronously shutting it down Agent.stop(bucket, :shutdown) # Now trying to call the dead process causes a :noproc exit catch_exit KV.Bucket.put(bucket, "milk", 3) end ``` This concludes our optimization chapter. We have used ETS as a cache mechanism where reads can happen from any processes but writes are still serialized through a single process. More importantly, we have also learned that once data can be read asynchronously, we need to be aware of the race conditions it might introduce. In practice, if you find yourself in a position where you need a process registry for dynamic processes, you should use [the `Registry` module](https://hexdocs.pm/elixir/Registry.html) provided as part of Elixir. It provides functionality similar to the one we have built using a GenServer + `:ets` while also being able to perform both writes and reads concurrently. [It has been benchmarked to scale across all cores even on machines with 40 cores](https://elixir-lang.org/blog/2017/01/05/elixir-v1-4-0-released/). Next, let’s discuss external and internal dependencies and how Mix helps us manage large codebases. elixir Configuration and releases Mix and OTP Configuration and releases ========================== > This chapter is part of the *Mix and OTP guide* and it depends on previous chapters in this guide. For more information, [read the introduction guide](introduction-to-mix) or check out the chapter index in the sidebar. > > In this last chapter, we will make the routing table for our distributed key-value store configurable, and then finally package the software for production. Let’s do this. Application environment ----------------------- So far we have hardcoded the routing table into the `KV.Router` module. However, we would like to make the table dynamic. This allows us not only to configure development/test/production, but also to allow different nodes to run with different entries in the routing table. There is a feature of OTP that does exactly that: the application environment. Each application has an environment that stores the application’s specific configuration by key. For example, we could store the routing table in the `:kv` application environment, giving it a default value and allowing other applications to change the table as needed. Open up `apps/kv/mix.exs` and change the `application/0` function to return the following: ``` def application do [ extra_applications: [:logger], env: [routing_table: []], mod: {KV, []} ] end ``` We have added a new `:env` key to the application. It returns the application default environment, which has an entry of key `:routing_table` and value of an empty list. It makes sense for the application environment to ship with an empty table, as the specific routing table depends on the testing/deployment structure. In order to use the application environment in our code, we need to replace `KV.Router.table/0` with the definition below: ``` @doc """ The routing table. """ def table do Application.fetch_env!(:kv, :routing_table) end ``` We use `Application.fetch_env!/2` to read the entry for `:routing_table` in `:kv`’s environment. You can find more information and other functions to manipulate the app environment in the [Application module](https://hexdocs.pm/elixir/Application.html). Since our routing table is now empty, our distributed tests should fail. Restart the apps and re-run tests to see the failure: ``` $ iex --sname bar -S mix $ elixir --sname foo -S mix test --only distributed ``` We need a way to configure the application environment. That’s when we use configuration files. Configuration ------------- Configuration files provide a mechanism for us to configure the environment of any application. Such configuration is done by the `config/config.exs` file. This config file is read at build time, when we compile our application. For example, we can configure IEx default prompt to another value. Let’s create the `config/config.exs` file with the following content: ``` import Config config :iex, default_prompt: ">>>" ``` Start IEx with `iex -S mix` and you can see that the IEx prompt has changed. This means we can also configure our `:routing_table` directly in the `config/config.exs` file. However, which configuration value should we use? Currently we have two tests tagged with `@tag :distributed`. The “server interaction” test in `KVServerTest`, and the “route requests across nodes” in `KV.RouterTest`. Both tests are failing since they require a routing table, which is currently empty. For simplicity, we will define a routing table that always points to the current node. That’s the table we will use for development and most of our tests. Back in `config/config.exs`, add this line: ``` config :kv, :routing_table, [{?a..?z, node()}] ``` With such a simple table available, we can now remove `@tag :distributed` from the test in `test/kv_server_test.exs`. If you run the complete suite, the test should now pass. However, for the tests in `KV.RouterTest`, we effectively need two nodes in our routing table. To do so, we will write a setup block that runs before all tests in that file. The setup block will change the application environment and revert it back once we are done, like this: ``` defmodule KV.RouterTest do use ExUnit.Case setup_all do current = Application.get_env(:kv, :routing_table) Application.put_env(:kv, :routing_table, [ {?a..?m, :"foo@computer-name"}, {?n..?z, :"bar@computer-name"} ]) on_exit fn -> Application.put_env(:kv, :routing_table, current) end end @tag :distributed test "route requests across nodes" do ``` Note we removed `async: true` from `use ExUnit.Case`. Since the application environment is a global storage, tests that modify it cannot run concurrently. With all changes in place, all tests should pass, including the distributed one. Releases -------- Now that our application runs distributed, you may be wondering how we can package our application to run in production. After all, all of our code so far depends on Erlang and Elixir versions that are installed in your current system. To achieve this goal, Elixir provides releases. A release is a self-contained directory that consists of your application code, all of its dependencies, plus the whole Erlang Virtual Machine (VM) and runtime. Once a release is assembled, it can be packaged and deployed to a target as long as the target runs on the same operating system (OS) distribution and version as the machine that assembled the release. In a regular project, we can assemble a release by simply running `mix release`. However, we have an umbrella project, and in such cases Elixir requires some extra input from us. Let’s see what is necessary: ``` $ MIX_ENV=prod mix release ** (Mix) Umbrella projects require releases to be explicitly defined with a non-empty applications key that chooses which umbrella children should be part of the releases: releases: [ foo: [ applications: [child_app_foo: :permanent] ], bar: [ applications: [child_app_bar: :permanent] ] ] Alternatively you can perform the release from the children applications ``` That’s because an umbrella project gives us plenty of options when deploying the software. We can: * deploy all applications in the umbrella to a node that will work as both TCP server and key-value storage * deploy the `:kv_server` application to work only as a TCP server as long as the routing table points only to other nodes * deploy only the `:kv` application when we want a node to work only as storage (no TCP access) As a starting point, let’s define a release that includes both `:kv_server` and `:kv` applications. We will also add a version to it. Open up the `mix.exs` in the umbrella root and add inside `def project`: ``` releases: [ foo: [ version: "0.0.1", applications: [kv_server: :permanent, kv: :permanent] ] ] ``` That defines a release named `foo` with both `kv_server` and `kv` applications. Their mode is set to `:permanent`, which means that, if those applications crash, the whole node terminates. That’s reasonable since those applications are essential to our system. Before we assemble the release, let’s also define our routing table for production. Given we expect to have two nodes, we want our routing table back in `config/config.exs` to look like this: ``` if Mix.env() == :prod do config :kv, :routing_table, [ {?a..?m, :"foo@computer-name"}, {?n..?z, :"bar@computer-name"} ] end ``` Note we have wrapped it in a `Mix.env() == :prod` check, so this configuration does not apply to other environments. While this will suffice for now, you may find the configuration a bit backwards. Usually, the computer name is usually not known upfront during development but only when deploying to production. For this purpose, we will later introduce [`config/releases.exs`](#runtime-configuration), which is a configuration file that is executed in the production machine before the system starts, giving you an opportunity to set the proper node name at the right time. With the configuration in place, let’s give assembling the release another try: ``` $ MIX_ENV=prod mix release foo * assembling foo-0.0.1 on MIX_ENV=prod * skipping runtime configuration (config/releases.exs not found) Release created at _build/prod/rel/foo! # To start your system _build/prod/rel/foo/bin/foo start Once the release is running: # To connect to it remotely _build/prod/rel/foo/bin/foo remote # To stop it gracefully (you may also send SIGINT/SIGTERM) _build/prod/rel/foo/bin/foo stop To list all commands: _build/prod/rel/foo/bin/foo ``` Excellent! A release was assembled in `_build/prod/rel/foo`. Inside the release, there will be a `bin/foo` file which is the entry point to your system. It supports multiple commands, such as: * `bin/foo start`, `bin/foo start_iex`, `bin/foo restart`, and `bin/foo stop` - for general management of the release * `bin/foo rpc COMMAND` and `bin/foo remote` - for running commands on the running system or to connect to the running system * `bin/foo eval COMMAND` - to start a fresh system that runs a single command and then shuts down * `bin/foo daemon` and `bin/foo daemon_iex` - to start the system as a daemon on Unix-like systems * `bin/foo install` - to install the system as a service on Windows machines If you run `bin/foo start`, it will start the system using a short name (`--sname`) equal to the release name, which in this case is `foo`. The next step is to start a system named `bar`, so we can connect `foo` and `bar` together, like we did in the previous chapter. But before we achieve this, let’s talk a bit about the benefits of releases. Why releases? ------------- Releases allow developers to precompile and package all of their code and the runtime into a single unit. The benefits of releases are: * Code preloading. The VM has two mechanisms for loading code: interactive and embedded. By default, it runs in the interactive mode which dynamically loads modules when they are used for the first time. The first time your application calls `Enum.map/2`, the VM will find the `Enum` module and load it. There’s a downside. When you start a new server in production, it may need to load many other modules, causing the first requests to have an unusual spike in response time. Releases run in embedded mode, which loads all available modules upfront, guaranteeing your system is ready to handle requests after booting. * Configuration and customization. Releases give developers fine grained control over system configuration and the VM flags used to start the system. * Self-contained. A release does not require the source code to be included in your production artifacts. All of the code is precompiled and packaged. Releases do not even require Erlang or Elixir on your servers, as they include the Erlang VM and its runtime by default. Furthermore, both Erlang and Elixir standard libraries are stripped to bring only the parts you are actually using. * Multiple releases. You can assemble different releases with different configuration per application or even with different applications altogether. We have written extensive documentation on releases, so [please check the official docs for more information](https://hexdocs.pm/mix/Mix.Tasks.Release.html). For now, we will continue exploring some of the features outlined above. Assembling multiple releases ---------------------------- So far, we have assembled a release named `foo`, but our routing table contains information for both `foo` and `bar`. Let’s start `foo`: ``` $ _build/prod/rel/foo/bin/foo start 16:58:58.508 [info] Accepting connections on port 4040 ``` And let’s connect to it and issue a request in another terminal: ``` $ telnet 127.0.0.1 4040 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GET shopping foo Connection closed by foreign host. ``` Since the “shopping” bucket would be stored on `bar`, the request fails as `bar` is not available. If you go back to the terminal running `foo`, you will see: ``` 17:16:19.555 [error] Task #PID<0.622.0> started from #PID<0.620.0> terminating ** (stop) exited in: GenServer.call({KV.RouterTasks, :"bar@computer-name"}, {:start_task, [{:"foo@josemac-2", #PID<0.622.0>, #PID<0.622.0>}, [#PID<0.622.0>, #PID<0.620.0>, #PID<0.618.0>], :monitor, {KV.Router, :route, ["shopping", KV.Registry, :lookup, [KV.Registry, "shopping"]]}], :temporary, nil}, :infinity) ** (EXIT) no connection to bar@computer-name (elixir) lib/gen_server.ex:1010: GenServer.call/3 (elixir) lib/task/supervisor.ex:454: Task.Supervisor.async/6 (kv) lib/kv/router.ex:21: KV.Router.route/4 (kv_server) lib/kv_server/command.ex:74: KVServer.Command.lookup/2 (kv_server) lib/kv_server.ex:29: KVServer.serve/1 (elixir) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2 (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3 Function: #Function<0.128611034/0 in KVServer.loop_acceptor/1> Args: [] ``` Let’s now define a release for `:bar`. One first step could be to define a release exactly like `foo` inside `mix.exs`. Additionally we will set the `cookie` option on both releases to `weknoweachother` in order for them to allow connections from each other. See the [Distributed Erlang Documentation](http://erlang.org/doc/reference_manual/distributed.html) for further information on this topic: ``` releases: [ foo: [ version: "0.0.1", applications: [kv_server: :permanent, kv: :permanent], cookie: "weknoweachother" ], bar: [ version: "0.0.1", applications: [kv_server: :permanent, kv: :permanent], cookie: "weknoweachother" ] ] ``` And now let’s assemble it: ``` $ MIX_ENV=prod mix release bar ``` And then start it: ``` $ _build/prod/rel/bar/bin/bar start ``` If you start `bar` while `foo` is still running, you will see an error like the error below happen 5 times, before the application finally shuts down: ``` 17:21:57.567 [error] Task #PID<0.620.0> started from KVServer.Supervisor terminating ** (MatchError) no match of right hand side value: {:error, :eaddrinuse} (kv_server) lib/kv_server.ex:12: KVServer.accept/1 (elixir) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2 (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3 Function: #Function<0.98032413/0 in KVServer.Application.start/2> Args: [] ``` That’s happening because the release `foo` is already listening on port `4040` and `bar` is trying to do the same! One option could be to move the `:port` configuration to the application environment, like we did for the routing table. But let’s try something else. Let’s make it so the `bar` release contains only the `:kv` application. So it works as a storage but it won’t have a front-end. Change the `:bar` information to this: ``` releases: [ foo: [ version: "0.0.1", applications: [kv_server: :permanent, kv: :permanent], cookie: "weknoweachother" ], bar: [ version: "0.0.1", applications: [kv: :permanent], cookie: "weknoweachother" ] ] ``` And now let’s assemble it once more: ``` $ MIX_ENV=prod mix release bar ``` And finally successfully boot it: ``` $ _build/prod/rel/bar/bin/bar start ``` If you connect to localhost once again and perform another request, now everything should work, as long as the routing table contains the correct node names. Outstanding! With releases, we were able to “cut different slices” of our project and prepared them to run in production, all packaged into a single directory. Configuring releases -------------------- Releases also provide built-in hooks for configuring almost every need of the production system: * `config/config.exs` - provides build-time application configuration, which is executed when the release is assembled. This file often imports configuration files based on the environment, such as `config/dev.exs` and `config/prod.exs` * `config/releases.exs` - provides runtime application configuration. It is executed every time the release boots and is further extensible via config providers * `rel/vm.args.eex` - a template file that is copied into every release and provides static configuration of the Erlang Virtual Machine and other runtime flags * `rel/env.sh.eex` and `rel/env.bat.eex` - template files that are copied into every release and executed on every command to set up environment variables, including ones specific to the VM, and the general environment We have already explored `config/config.exs`. Now let’s talk about `rel/env.sh.eex` and then `config/releases.exs` before we end this chapter. ### Operating System environment configuration Every release contains an environment file, named `env.sh` on Unix-like systems and `env.bat` on Windows machines, that executes before the Elixir system starts. In this file, you can execute any OS-level code, such as invoke other applications, set environment variables and so on. Some of those environment variables can even configure how the release itself runs. For instance, releases run using short-names (`--sname`). However, if you want to actually run a distributed key-value store in production, you will need multiple nodes and start the release with the `--name` option. We can achieve this by setting the `RELEASE_DISTRIBUTION` environment variable inside the `env.sh` and `env.bat` files. Mix already has a template for said files which we can customize, so let’s ask Mix to copy them to our application: ``` $ mix release.init * creating rel/vm.args.eex * creating rel/env.sh.eex * creating rel/env.bat.eex ``` If you open up `rel/env.sh.eex`, you will see: ``` #!/bin/sh # Sets and enables heart (recommended only in daemon mode) # if [ "$RELEASE_COMMAND" = "daemon" ] || [ "$RELEASE_COMMAND" = "daemon_iex" ]; then # HEART_COMMAND="$RELEASE_ROOT/bin/$RELEASE_NAME $RELEASE_COMMAND" # export HEART_COMMAND # export ELIXIR_ERL_OPTIONS="-heart" # fi # Set the release to work across nodes # export RELEASE_DISTRIBUTION=name # export RELEASE_NODE=<%= @release.name %>@127.0.0.1 ``` The steps necessary to work across nodes is already commented out as an example. You can enable full distribution by uncommenting the last two lines by removing the leading `#` . If you are on Windows, you will have to open up `rel/env.bat.eex`, where you will find this: ``` @echo off rem Set the release to work across nodes rem set RELEASE_DISTRIBUTION=name rem set RELEASE_NODE=<%= @release.name %>@127.0.0.1 ``` Once again, uncomment the last two lines by removing the leading `rem` to enable full distribution. And that’s all! ### Runtime configuration Another common need in releases is to compute configuration when the release runs, not when the release is assembled. The `config/config.exs` file we defined at the beginning of this chapter runs on every Mix command, when we build, test and run our application. This is great, because it provides a unified configuration for dev, test, and prod. However, your production environments may have specific needs. For example, right now we are hardcoding the routing table, but in production, you may need to read the routing table from disk, from another service, or even reach out to your orchestration tool, like Kubernetes. This can be done by adding a `config/releases.exs`. As the name says, this file runs every time the release starts. For instance, you could make the `KVServer` port configurable, and the value for the port is only given at runtime: ``` import Config config :kv_server, :port, System.fetch_env!("PORT") ``` `config/releases.exs` files work very similar to regular `config/config.exs` files, but they may have some restrictions. You can [read the documentation](https://hexdocs.pm/mix/1.9.0/Mix.Tasks.Release.html#module-runtime-configuration) for more information. Summing up ---------- Throughout the guide, we have built a very simple distributed key-value store as an opportunity to explore many constructs like generic servers, supervisors, tasks, agents, applications and more. Not only that, we have written tests for the whole application, got familiar with ExUnit, and learned how to use the Mix build tool to accomplish a wide range of tasks. If you are looking for a distributed key-value store to use in production, you should definitely look into [Riak](http://basho.com/products/riak-kv/), which also runs in the Erlang VM. In Riak, the buckets are replicated, to avoid data loss, and instead of a router, they use [consistent hashing](https://en.wikipedia.org/wiki/Consistent_hashing) to map a bucket to a node. A consistent hashing algorithm helps reduce the amount of data that needs to be migrated when new storage nodes are added to your live system. Of course, Elixir can be used for much more than distributed key-value stores. Embedded systems, data-processing and data-ingestion, web applications, streaming systems, and others are many of the different domains Elixir excels at. We hope this guide has prepared you to explore any of those domains or any future domain you may desire to bring Elixir into. Happy coding!
programming_docs
elixir Agent Mix and OTP Agent ===== > This chapter is part of the *Mix and OTP guide* and it depends on previous chapters in this guide. For more information, [read the introduction guide](introduction-to-mix) or check out the chapter index in the sidebar. > > In this chapter, we will learn how to keep and share state between multiple entities. If you have previous programming experience, you may think of globally shared variables, but the model we will learn here is quite different. The next chapters will generalize the concepts introduced here. If you have skipped the Getting Started guide or read it long ago, be sure to re-read the [Processes](../processes) chapter. We will use it as a starting point. The trouble with state ---------------------- Elixir is an immutable language where nothing is shared by default. If we want to share information, which can be read and modified from multiple places, we have two main options in Elixir: * Using Processes and message passing * [ETS (Erlang Term Storage)](http://www.erlang.org/doc/man/ets.html) We covered processes in the Getting Started guide. ETS is a new topic that we will explore in later chapters. When it comes to processes though, we rarely hand-roll our own, instead we use the abstractions available in Elixir and OTP: * [Agent](https://hexdocs.pm/elixir/Agent.html) - Simple wrappers around state. * [GenServer](https://hexdocs.pm/elixir/GenServer.html) - “Generic servers” (processes) that encapsulate state, provide sync and async calls, support code reloading, and more. * [Task](https://hexdocs.pm/elixir/Task.html) - Asynchronous units of computation that allow spawning a process and potentially retrieving its result at a later time. We will explore most of these abstractions in this guide. Keep in mind that they are all implemented on top of processes using the basic features provided by the VM, like `send`, `receive`, `spawn` and `link`. Here we will use Agents, and create a module named `KV.Bucket`, responsible for storing our key-value entries in a way that allows them to be read and modified by other processes. Agents ------ [Agents](https://hexdocs.pm/elixir/Agent.html) are simple wrappers around state. If all you want from a process is to keep state, agents are a great fit. Let’s start an `iex` session inside the project with: ``` $ iex -S mix ``` And play a bit with agents: ``` iex> {:ok, agent} = Agent.start_link fn -> [] end {:ok, #PID<0.57.0>} iex> Agent.update(agent, fn list -> ["eggs" | list] end) :ok iex> Agent.get(agent, fn list -> list end) ["eggs"] iex> Agent.stop(agent) :ok ``` We started an agent with an initial state of an empty list. We updated the agent’s state, adding our new item to the head of the list. The second argument of [`Agent.update/3`](https://hexdocs.pm/elixir/Agent.html#update/3) is a function that takes the agent’s current state as input and returns its desired new state. Finally, we retrieved the whole list. The second argument of [`Agent.get/3`](https://hexdocs.pm/elixir/Agent.html#get/3) is a function that takes the state as input and returns the value that [`Agent.get/3`](https://hexdocs.pm/elixir/Agent.html#get/3) itself will return. Once we are done with the agent, we can call [`Agent.stop/3`](https://hexdocs.pm/elixir/Agent.html#stop/3) to terminate the agent process. The `Agent.update/3` function accepts as a second argument any function that receives one argument and returns a value: ``` iex> {:ok, agent} = Agent.start_link fn -> [] end {:ok, #PID<0.338.0>} iex> Agent.update(agent, fn _list -> 123 end) :ok iex> Agent.update(agent, fn content -> %{a: content} end) :ok iex> Agent.update(agent, fn content -> [12 | [content]] end) :ok iex> Agent.update(agent, fn list -> [:nop | list] end) :ok iex> Agent.get(agent, fn content -> content end) [:nop, 12, %{a: 123}] iex> ``` As you can see, we can modify the agent state in any way we want. Therefore, we most likely don’t want to access the Agent API throughout many different places in our code. Instead, we want to encapsulate all Agent-related functionality in a single module, which we will call `KV.Bucket`. Before we implement it, let’s write some tests which will outline the API exposed by our module. Create a file at `test/kv/bucket_test.exs` (remember the `.exs` extension) with the following: ``` defmodule KV.BucketTest do use ExUnit.Case, async: true test "stores values by key" do {:ok, bucket} = KV.Bucket.start_link([]) assert KV.Bucket.get(bucket, "milk") == nil KV.Bucket.put(bucket, "milk", 3) assert KV.Bucket.get(bucket, "milk") == 3 end end ``` `use ExUnit.Case` is responsible for setting up our module for testing and imports many test-related functionality, such as the `test/2` macro. Our first test starts a new `KV.Bucket` by calling the `start_link/1` and passing an empty list of options. Then we perform some `get/2` and `put/3` operations on it, asserting the result. Also note the `async: true` option passed to `ExUnit.Case`. This option makes the test case run in parallel with other `:async` test cases by using multiple cores in our machine. This is extremely useful to speed up our test suite. However, `:async` must *only* be set if the test case does not rely on or change any global values. For example, if the test requires writing to the filesystem or access a database, keep it synchronous (omit the `:async` option) to avoid race conditions between tests. Async or not, our new test should obviously fail, as none of the functionality is implemented in the module being tested: ``` ** (UndefinedFunctionError) function KV.Bucket.start_link/1 is undefined (module KV.Bucket is not available) ``` In order to fix the failing test, let’s create a file at `lib/kv/bucket.ex` with the contents below. Feel free to give a try at implementing the `KV.Bucket` module yourself using agents before peeking at the implementation below. ``` defmodule KV.Bucket do use Agent @doc """ Starts a new bucket. """ def start_link(_opts) do Agent.start_link(fn -> %{} end) end @doc """ Gets a value from the `bucket` by `key`. """ def get(bucket, key) do Agent.get(bucket, &Map.get(&1, key)) end @doc """ Puts the `value` for the given `key` in the `bucket`. """ def put(bucket, key, value) do Agent.update(bucket, &Map.put(&1, key, value)) end end ``` The first step in our implementation is to call `use Agent`. Then we define a `start_link/1` function, which will effectively start the agent. It is a convention to define a `start_link/1` function that always accepts a list of options. We don’t plan on using any options right now, but we might later on. We then proceed to call `Agent.start_link/1`, which receives an anonymous function that returns the Agent’s initial state. We are keeping a map inside the agent to store our keys and values. Getting and putting values on the map is done with the Agent API and the capture operator `&`, introduced in [the Getting Started guide](../modules-and-functions#function-capturing). The agent passes its state to the anonymous function via the `&1` argument when `Agent.get/2` and `Agent.update/2` are called. Now that the `KV.Bucket` module has been defined, our test should pass! You can try it yourself by running: `mix test`. Test setup with ExUnit callbacks -------------------------------- Before moving on and adding more features to `KV.Bucket`, let’s talk about ExUnit callbacks. As you may expect, all `KV.Bucket` tests will require a bucket agent to be up and running. Luckily, ExUnit supports callbacks that allow us to skip such repetitive tasks. Let’s rewrite the test case to use callbacks: ``` defmodule KV.BucketTest do use ExUnit.Case, async: true setup do {:ok, bucket} = KV.Bucket.start_link([]) %{bucket: bucket} end test "stores values by key", %{bucket: bucket} do assert KV.Bucket.get(bucket, "milk") == nil KV.Bucket.put(bucket, "milk", 3) assert KV.Bucket.get(bucket, "milk") == 3 end end ``` We have first defined a setup callback with the help of the `setup/1` macro. The `setup/1` macro defines a callback that is run before every test, in the same process as the test itself. Note that we need a mechanism to pass the `bucket` pid from the callback to the test. We do so by using the *test context*. When we return `%{bucket: bucket}` from the callback, ExUnit will merge this map into the test context. Since the test context is a map itself, we can pattern match the bucket out of it, providing access to the bucket inside the test: ``` test "stores values by key", %{bucket: bucket} do # `bucket` is now the bucket from the setup block end ``` You can read more about ExUnit cases in the [`ExUnit.Case` module documentation](https://hexdocs.pm/ex_unit/ExUnit.Case.html) and more about callbacks in [`ExUnit.Callbacks` docs](https://hexdocs.pm/ex_unit/ExUnit.Callbacks.html). Other agent actions ------------------- Besides getting a value and updating the agent state, agents allow us to get a value and update the agent state in one function call via `Agent.get_and_update/2`. Let’s implement a `KV.Bucket.delete/2` function that deletes a key from the bucket, returning its current value: ``` @doc """ Deletes `key` from `bucket`. Returns the current value of `key`, if `key` exists. """ def delete(bucket, key) do Agent.get_and_update(bucket, &Map.pop(&1, key)) end ``` Now it is your turn to write a test for the functionality above! Also, be sure to explore [the documentation for the `Agent` module](https://hexdocs.pm/elixir/Agent.html) to learn more about them. Client/Server in agents ----------------------- Before we move on to the next chapter, let’s discuss the client/server dichotomy in agents. Let’s expand the `delete/2` function we have just implemented: ``` def delete(bucket, key) do Agent.get_and_update(bucket, fn dict -> Map.pop(dict, key) end) end ``` Everything that is inside the function we passed to the agent happens in the agent process. In this case, since the agent process is the one receiving and responding to our messages, we say the agent process is the server. Everything outside the function is happening in the client. This distinction is important. If there are expensive actions to be done, you must consider if it will be better to perform these actions on the client or on the server. For example: ``` def delete(bucket, key) do Process.sleep(1000) # puts client to sleep Agent.get_and_update(bucket, fn dict -> Process.sleep(1000) # puts server to sleep Map.pop(dict, key) end) end ``` When a long action is performed on the server, all other requests to that particular server will wait until the action is done, which may cause some clients to timeout. In the next chapter, we will explore GenServers, where the segregation between clients and servers is made more apparent. elixir GenServer Mix and OTP GenServer ========= > This chapter is part of the *Mix and OTP guide* and it depends on previous chapters in this guide. For more information, [read the introduction guide](introduction-to-mix) or check out the chapter index in the sidebar. > > In the [previous chapter](agent), we used agents to represent our buckets. In the [introduction to mix](introduction-to-mix), we specified we would like to name each bucket so we can do the following: ``` CREATE shopping OK PUT shopping milk 1 OK GET shopping milk 1 OK ``` In the session above we interacted with the “shopping” bucket. Since agents are processes, each bucket has a process identifier (pid), but buckets do not have a name. Back [in the Process chapter](../processes), we have learned that we can register processes in Elixir by giving them atom names: ``` iex> Agent.start_link(fn -> %{} end, name: :shopping) {:ok, #PID<0.43.0>} iex> KV.Bucket.put(:shopping, "milk", 1) :ok iex> KV.Bucket.get(:shopping, "milk") 1 ``` However, naming dynamic processes with atoms is a terrible idea! If we use atoms, we would need to convert the bucket name (often received from an external client) to atoms, and **we should never convert user input to atoms**. This is because atoms are not garbage collected. Once an atom is created, it is never reclaimed. Generating atoms from user input would mean the user can inject enough different names to exhaust our system memory! In practice, it is more likely you will reach the Erlang VM limit for the maximum number of atoms before you run out of memory, which will bring your system down regardless. Instead of abusing the built-in name facility, we will create our own *process registry* that associates the bucket name to the bucket process. The registry needs to guarantee that it is always up to date. For example, if one of the bucket processes crashes due to a bug, the registry must notice this change and avoid serving stale entries. In Elixir, we say the registry needs to *monitor* each bucket. Because our *registry* needs to be able to receive and handle ad-hoc messages from the system, the `Agent` API is not enough. We will use a [GenServer](https://hexdocs.pm/elixir/GenServer.html) to create a registry process that can monitor the bucket processes. GenServer provides industrial strength functionality for building servers in both Elixir and OTP. Please read [the GenServer module documentation](https://hexdocs.pm/elixir/GenServer.html) for an overview if you haven’t yet. Once you do so, we are ready to proceed. GenServer callbacks ------------------- A GenServer is a process that invokes a limited set of functions under specific conditions. When we used an `Agent`, we would keep both the client code and the server code side by side, like this: ``` def put(bucket, key, value) do Agent.update(bucket, &Map.put(&1, key, value)) end ``` Let’s break that code apart a bit: ``` def put(bucket, key, value) do # Here is the client code Agent.update(bucket, fn state -> # Here is the server code Map.put(state, key, value) end) # Back to the client code end ``` In the code above, we have a process, which we call “the client” sending a request to an agent, “the server”. The request contains an anonymous function, which must be executed by the server. In a GenServer, the code above would be two separate functions, roughly like this: ``` def put(bucket, key, value) do # Send the server a :put "instruction" GenServer.call(bucket, {:put, key, value}) end # Server callback def handle_call({:put, key, value}, _from, state) do {:reply, :ok, Map.put(state, key, value)} end ``` There is quite a bit more ceremony in the GenServer code but, as we will see, it brings some benefits too. For now, we will write only the server callbacks for our bucket registering logic, without providing a proper API, which we will do later. Create a new file at `lib/kv/registry.ex` with the following contents: ``` defmodule KV.Registry do use GenServer ## Missing Client API - will add this later ## Defining GenServer Callbacks @impl true def init(:ok) do {:ok, %{}} end @impl true def handle_call({:lookup, name}, _from, names) do {:reply, Map.fetch(names, name), names} end @impl true def handle_cast({:create, name}, names) do if Map.has_key?(names, name) do {:noreply, names} else {:ok, bucket} = KV.Bucket.start_link([]) {:noreply, Map.put(names, name, bucket)} end end end ``` There are two types of requests you can send to a GenServer: calls and casts. Calls are synchronous and the server **must** send a response back to such requests. While the server computes the response, the client is **waiting**. Casts are asynchronous: the server won’t send a response back and therefore the client won’t wait for one. Both requests are messages sent to the server, and will be handled in sequence. In the above implementation, we pattern-match on the `:create` messages, to be handled as cast, and on the `:lookup` messages, to be handled as call. In order to invoke the callbacks above, we need to go through the corresponding `GenServer` functions. Let’s start a registry, create a named bucket, and then look it up: ``` iex> {:ok, registry} = GenServer.start_link(KV.Registry, :ok) {:ok, #PID<0.136.0>} iex> GenServer.cast(registry, {:create, "shopping"}) :ok iex> {:ok, bk} = GenServer.call(registry, {:lookup, "shopping"}) {:ok, #PID<0.174.0>} ``` Our `KV.Registry` process received a cast with `{:create, "shopping"}` and a call with `{:lookup, "shopping"}`, in this sequence. `GenServer.cast` will immediately return, as soon as the message is sent to the `registry`. The `GenServer.call` on the other hand, is where we would be waiting for an answer, provided by the above `KV.Registry.handle_call` callback. You may also have noticed that we have added `@impl true` before each callback. The `@impl true` informs the compiler that our intention for the subsequent function definition is to define a callback. If by any chance we make a mistake in the function name or in the number of arguments, like we define a `handle_call/2`, the compiler would warn us there isn’t any `handle_call/2` to define, and would give us the complete list of known callbacks for the `GenServer` module. This is all good and well, but we still want to offer our users an API that allows us to hide our implementation details. The Client API -------------- A GenServer is implemented in two parts: the client API and the server callbacks. You can either combine both parts into a single module or you can separate them into a client module and a server module. The client is any process that invokes the client function. The server is always the process identifier or process name that we will explicitly pass as argument to the client API. Here we’ll use a single module for both the server callbacks and the client API. Edit the file at `lib/kv/registry.ex`, filling in the blanks for the client API: ``` ## Client API @doc """ Starts the registry. """ def start_link(opts) do GenServer.start_link(__MODULE__, :ok, opts) end @doc """ Looks up the bucket pid for `name` stored in `server`. Returns `{:ok, pid}` if the bucket exists, `:error` otherwise. """ def lookup(server, name) do GenServer.call(server, {:lookup, name}) end @doc """ Ensures there is a bucket associated with the given `name` in `server`. """ def create(server, name) do GenServer.cast(server, {:create, name}) end ``` The first function is `start_link/1`, which starts a new GenServer passing a list of options. `start_link/1` calls out to `GenServer.start_link/3`, which takes three arguments: 1. The module where the server callbacks are implemented, in this case `__MODULE__` (meaning the current module) 2. The initialization arguments, in this case the atom `:ok` 3. A list of options which can be used to specify things like the name of the server. For now, we forward the list of options that we receive on `start_link/1` to `GenServer.start_link/3` The next two functions, `lookup/2` and `create/2`, are responsible for sending these requests to the server. In this case, we have used `{:lookup, name}` and `{:create, name}` respectively. Requests are often specified as tuples, like this, in order to provide more than one “argument” in that first argument slot. It’s common to specify the action being requested as the first element of a tuple, and arguments for that action in the remaining elements. Note that the requests must match the first argument to `handle_call/3` or `handle_cast/2`. That’s it for the client API. On the server side, we can implement a variety of callbacks to guarantee the server initialization, termination, and handling of requests. Those callbacks are optional and for now, we have only implemented the ones we care about. Let’s recap. The first is the `init/1` callback, that receives the second argument given to `GenServer.start_link/3` and returns `{:ok, state}`, where state is a new map. We can already notice how the `GenServer` API makes the client/server segregation more apparent. `start_link/3` happens in the client, while `init/1` is the respective callback that runs on the server. For `call/2` requests, we implement a `handle_call/3` callback that receives the `request`, the process from which we received the request (`_from`), and the current server state (`names`). The `handle_call/3` callback returns a tuple in the format `{:reply, reply, new_state}`. The first element of the tuple, `:reply`, indicates that the server should send a reply back to the client. The second element, `reply`, is what will be sent to the client while the third, `new_state` is the new server state. For `cast/2` requests, we implement a `handle_cast/2` callback that receives the `request` and the current server state (`names`). The `handle_cast/2` callback returns a tuple in the format `{:noreply, new_state}`. Note that in a real application we would have probably implemented the callback for `:create` with a synchronous call instead of an asynchronous cast. We are doing it this way to illustrate how to implement a cast callback. There are other tuple formats both `handle_call/3` and `handle_cast/2` callbacks may return. There are also other callbacks like `terminate/2` and `code_change/3` that we could implement. You are welcome to explore the [full GenServer documentation](https://hexdocs.pm/elixir/GenServer.html) to learn more about those. For now, let’s write some tests to guarantee our GenServer works as expected. Testing a GenServer ------------------- Testing a GenServer is not much different from testing an agent. We will spawn the server on a setup callback and use it throughout our tests. Create a file at `test/kv/registry_test.exs` with the following: ``` defmodule KV.RegistryTest do use ExUnit.Case, async: true setup do registry = start_supervised!(KV.Registry) %{registry: registry} end test "spawns buckets", %{registry: registry} do assert KV.Registry.lookup(registry, "shopping") == :error KV.Registry.create(registry, "shopping") assert {:ok, bucket} = KV.Registry.lookup(registry, "shopping") KV.Bucket.put(bucket, "milk", 1) assert KV.Bucket.get(bucket, "milk") == 1 end end ``` Our test case first asserts there’s no buckets in our registry, creates a named bucket, looks it up, and asserts it behaves as a bucket. There is one important difference between the `setup` block we wrote for `KV.Registry` and the one we wrote for `KV.Bucket`. Instead of starting the registry by hand by calling `KV.Registry.start_link/1`, we instead called [the `start_supervised!/2` function](https://hexdocs.pm/ex_unit/ExUnit.Callbacks.html#start_supervised/2), passing the `KV.Registry` module. The `start_supervised!` function was injected into our test module by `use ExUnit.Case`. It does the job of starting the `KV.Registry` process, by calling its `start_link/1` function. The advantage of using `start_supervised!` is that ExUnit will guarantee that the registry process will be shutdown **before** the next test starts. In other words, it helps guarantee that the state of one test is not going to interfere with the next one in case they depend on shared resources. When starting processes during your tests, we should always prefer to use `start_supervised!`. We recommend you to change the `setup` block in `bucket_test.exs` to use `start_supervised!` too. Run the tests and they should all pass! The need for monitoring ----------------------- Everything we have done so far could have been implemented with an `Agent`. In this section, we will see one of many things that we can achieve with a GenServer that is not possible with an Agent. Let’s start with a test that describes how we want the registry to behave if a bucket stops or crashes: ``` test "removes buckets on exit", %{registry: registry} do KV.Registry.create(registry, "shopping") {:ok, bucket} = KV.Registry.lookup(registry, "shopping") Agent.stop(bucket) assert KV.Registry.lookup(registry, "shopping") == :error end ``` The test above will fail on the last assertion as the bucket name remains in the registry even after we stop the bucket process. In order to fix this bug, we need the registry to monitor every bucket it spawns. Once we set up a monitor, the registry will receive a notification every time a bucket process exits, allowing us to clean the registry up. Let’s first play with monitors by starting a new console with `iex -S mix`: ``` iex> {:ok, pid} = KV.Bucket.start_link([]) {:ok, #PID<0.66.0>} iex> Process.monitor(pid) #Reference<0.0.0.551> iex> Agent.stop(pid) :ok iex> flush() {:DOWN, #Reference<0.0.0.551>, :process, #PID<0.66.0>, :normal} ``` Note `Process.monitor(pid)` returns a unique reference that allows us to match upcoming messages to that monitoring reference. After we stop the agent, we can `flush/0` all messages and notice a `:DOWN` message arrived, with the exact reference returned by `monitor`, notifying that the bucket process exited with reason `:normal`. Let’s reimplement the server callbacks to fix the bug and make the test pass. First, we will modify the GenServer state to two dictionaries: one that contains `name -> pid` and another that holds `ref -> name`. Then we need to monitor the buckets on `handle_cast/2` as well as implement a `handle_info/2` callback to handle the monitoring messages. The full server callbacks implementation is shown below: ``` ## Server callbacks @impl true def init(:ok) do names = %{} refs = %{} {:ok, {names, refs}} end @impl true def handle_call({:lookup, name}, _from, state) do {names, _} = state {:reply, Map.fetch(names, name), state} end @impl true def handle_cast({:create, name}, {names, refs}) do if Map.has_key?(names, name) do {:noreply, {names, refs}} else {:ok, bucket} = KV.Bucket.start_link([]) ref = Process.monitor(bucket) refs = Map.put(refs, ref, name) names = Map.put(names, name, bucket) {:noreply, {names, refs}} end end @impl true def handle_info({:DOWN, ref, :process, _pid, _reason}, {names, refs}) do {name, refs} = Map.pop(refs, ref) names = Map.delete(names, name) {:noreply, {names, refs}} end @impl true def handle_info(_msg, state) do {:noreply, state} end ``` Observe that we were able to considerably change the server implementation without changing any of the client API. That’s one of the benefits of explicitly segregating the server and the client. Finally, different from the other callbacks, we have defined a “catch-all” clause for `handle_info/2` that discards any unknown message. To understand why, let’s move on to the next section. `call`, `cast` or `info`? -------------------------- So far we have used three callbacks: `handle_call/3`, `handle_cast/2` and `handle_info/2`. Here is what we should consider when deciding when to use each: 1. `handle_call/3` must be used for synchronous requests. This should be the default choice as waiting for the server reply is a useful backpressure mechanism. 2. `handle_cast/2` must be used for asynchronous requests, when you don’t care about a reply. A cast does not even guarantee the server has received the message and, for this reason, should be used sparingly. For example, the `create/2` function we have defined in this chapter should have used `call/2`. We have used `cast/2` for didactic purposes. 3. `handle_info/2` must be used for all other messages a server may receive that are not sent via `GenServer.call/2` or `GenServer.cast/2`, including regular messages sent with `send/2`. The monitoring `:DOWN` messages are an example of this. Since any message, including the ones sent via `send/2`, go to `handle_info/2`, there is a chance unexpected messages will arrive to the server. Therefore, if we don’t define the catch-all clause, those messages could cause our registry to crash, because no clause would match. We don’t need to worry about such cases for `handle_call/3` and `handle_cast/2` though. Calls and casts are only done via the `GenServer` API, so an unknown message is quite likely a developer mistake. To help developers remember the differences between call, cast and info, the supported return values and more, we have a tiny [GenServer cheat sheet](https://elixir-lang.org/cheatsheets/gen-server.pdf). Monitors or links? ------------------ We have previously learned about links in the [Process chapter](../processes). Now, with the registry complete, you may be wondering: when should we use monitors and when should we use links? Links are bi-directional. If you link two processes and one of them crashes, the other side will crash too (unless it is trapping exits). A monitor is uni-directional: only the monitoring process will receive notifications about the monitored one. In other words: use links when you want linked crashes, and monitors when you just want to be informed of crashes, exits, and so on. Returning to our `handle_cast/2` implementation, you can see the registry is both linking and monitoring the buckets: ``` {:ok, bucket} = KV.Bucket.start_link([]) ref = Process.monitor(bucket) ``` This is a bad idea, as we don’t want the registry to crash when a bucket crashes. The proper fix is to actually not link the bucket to the registry. Instead, we will link each bucket to a special type of process called Supervisors, which are explicitly designed to handle failures and crashes. We will learn more about them in the next chapter.
programming_docs
elixir Dependencies and umbrella projects Mix and OTP Dependencies and umbrella projects ================================== > This chapter is part of the *Mix and OTP guide* and it depends on previous chapters in this guide. For more information, [read the introduction guide](introduction-to-mix) or check out the chapter index in the sidebar. > > In this chapter, we will discuss how to manage dependencies in Mix. Our `kv` application is complete, so it’s time to implement the server that will handle the requests we defined in the first chapter: ``` CREATE shopping OK PUT shopping milk 1 OK PUT shopping eggs 3 OK GET shopping milk 1 OK DELETE shopping eggs OK ``` However, instead of adding more code to the `kv` application, we are going to build the TCP server as another application that is a client of the `kv` application. Since the whole runtime and Elixir ecosystem are geared towards applications, it makes sense to break our projects into smaller applications that work together rather than building a big, monolithic app. Before creating our new application, we must discuss how Mix handles dependencies. In practice, there are two kinds of dependencies we usually work with: internal and external dependencies. Mix supports mechanisms to work with both of them. External dependencies --------------------- External dependencies are the ones not tied to your business domain. For example, if you need an HTTP API for your distributed KV application, you can use the [Plug](https://github.com/elixir-lang/plug) project as an external dependency. Installing external dependencies is simple. Most commonly, we use the [Hex Package Manager](https://hex.pm), by listing the dependency inside the deps function in our `mix.exs` file: ``` def deps do [{:plug, "~> 1.0"}] end ``` This dependency refers to the latest version of Plug in the 1.x.x version series that has been pushed to Hex. This is indicated by the `~>` preceding the version number. For more information on specifying version requirements, see the [documentation for the Version module](https://hexdocs.pm/elixir/Version.html). Typically, stable releases are pushed to Hex. If you want to depend on an external dependency still in development, Mix is able to manage Git dependencies too: ``` def deps do [{:plug, git: "git://github.com/elixir-lang/plug.git"}] end ``` You will notice that when you add a dependency to your project, Mix generates a `mix.lock` file that guarantees *repeatable builds*. The lock file must be checked in to your version control system, to guarantee that everyone who uses the project will use the same dependency versions as you. Mix provides many tasks for working with dependencies, which can be seen in `mix help`: ``` $ mix help mix deps # Lists dependencies and their status mix deps.clean # Deletes the given dependencies' files mix deps.compile # Compiles dependencies mix deps.get # Gets all out of date dependencies mix deps.tree # Prints the dependency tree mix deps.unlock # Unlocks the given dependencies mix deps.update # Updates the given dependencies ``` The most common tasks are `mix deps.get` and `mix deps.update`. Once fetched, dependencies are automatically compiled for you. You can read more about deps by typing `mix help deps`, and in the [documentation for the Mix.Tasks.Deps module](https://hexdocs.pm/mix/Mix.Tasks.Deps.html). Internal dependencies --------------------- Internal dependencies are the ones that are specific to your project. They usually don’t make sense outside the scope of your project/company/organization. Most of the time, you want to keep them private, whether due to technical, economic or business reasons. If you have an internal dependency, Mix supports two methods to work with them: Git repositories or umbrella projects. For example, if you push the `kv` project to a Git repository, you’ll need to list it in your deps code in order to use it: ``` def deps do [{:kv, git: "https://github.com/YOUR_ACCOUNT/kv.git"}] end ``` If the repository is private though, you may need to specify the private URL `[email protected]:YOUR_ACCOUNT/kv.git`. In any case, Mix will be able to fetch it for you as long as you have the proper credentials. Using Git repositories for internal dependencies is somewhat discouraged in Elixir. Remember that the runtime and the Elixir ecosystem already provide the concept of applications. As such, we expect you to frequently break your code into applications that can be organized logically, even within a single project. However, if you push every application as a separate project to a Git repository, your projects may become very hard to maintain as you will spend a lot of time managing those Git repositories rather than writing your code. For this reason, Mix supports “umbrella projects”. Umbrella projects are used to build applications that run together in a single repository. That is exactly the style we are going to explore in the next sections. Let’s create a new Mix project. We are going to creatively name it `kv_umbrella`, and this new project will have both the existing `kv` application and the new `kv_server` application inside. The directory structure will look like this: ``` + kv_umbrella + apps + kv + kv_server ``` The interesting thing about this approach is that Mix has many conveniences for working with such projects, such as the ability to compile and test all applications inside `apps` with a single command. However, even though they are all listed together inside `apps`, they are still decoupled from each other, so you can build, test and deploy each application in isolation if you want to. So let’s get started! Umbrella projects ----------------- Let’s start a new project using `mix new`. This new project will be named `kv_umbrella` and we need to pass the `--umbrella` option when creating it. Do not create this new project inside the existing `kv` project! ``` $ mix new kv_umbrella --umbrella * creating README.md * creating .formatter.exs * creating .gitignore * creating mix.exs * creating apps * creating config * creating config/config.exs ``` From the printed information, we can see far fewer files are generated. The generated `mix.exs` file is different too. Let’s take a look (comments have been removed): ``` defmodule KvUmbrella.MixProject do use Mix.Project def project do [ apps_path: "apps", start_permanent: Mix.env() == :prod, deps: deps() ] end defp deps do [] end end ``` What makes this project different from the previous one is the `apps_path: "apps"` entry in the project definition. This means this project will act as an umbrella. Such projects do not have source files nor tests, although they can have their own dependencies. Each child application must be defined inside the `apps` directory. Let’s move inside the apps directory and start building `kv_server`. This time, we are going to pass the `--sup` flag, which will tell Mix to generate a supervision tree automatically for us, instead of building one manually as we did in previous chapters: ``` $ cd kv_umbrella/apps $ mix new kv_server --module KVServer --sup ``` The generated files are similar to the ones we first generated for `kv`, with a few differences. Let’s open up `mix.exs`: ``` defmodule KVServer.MixProject do use Mix.Project def project do [ app: :kv_server, version: "0.1.0", build_path: "../../_build", config_path: "../../config/config.exs", deps_path: "../../deps", lockfile: "../../mix.lock", elixir: "~> 1.10", start_permanent: Mix.env() == :prod, deps: deps() ] end # Run "mix help compile.app" to learn about applications def application do [ extra_applications: [:logger], mod: {KVServer.Application, []} ] end # Run "mix help deps" to learn about dependencies defp deps do [ # {:dep_from_hexpm, "~> 0.3.0"}, # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}, # {:sibling_app_in_umbrella, in_umbrella: true}, ] end end ``` First of all, since we generated this project inside `kv_umbrella/apps`, Mix automatically detected the umbrella structure and added four lines to the project definition: ``` build_path: "../../_build", config_path: "../../config/config.exs", deps_path: "../../deps", lockfile: "../../mix.lock", ``` Those options mean all dependencies will be checked out to `kv_umbrella/deps`, and they will share the same build, config and lock files. We haven’t talked about configuration yet, but from here we can build the intuition that all configuration and dependencies are shared across all projects in an umbrella, and it is not per application. The second change is in the `application` function inside `mix.exs`: ``` def application do [ extra_applications: [:logger], mod: {KVServer.Application, []} ] end ``` Because we passed the `--sup` flag, Mix automatically added `mod: {KVServer.Application, []}`, specifying that `KVServer.Application` is our application callback module. `KVServer.Application` will start our application supervision tree. In fact, let’s open up `lib/kv_server/application.ex`: ``` defmodule KVServer.Application do # See https://hexdocs.pm/elixir/Application.html # for more information on OTP Applications @moduledoc false use Application def start(_type, _args) do # List all child processes to be supervised children = [ # Starts a worker by calling: KVServer.Worker.start_link(arg) # {KVServer.Worker, arg}, ] # See https://hexdocs.pm/elixir/Supervisor.html # for other strategies and supported options opts = [strategy: :one_for_one, name: KVServer.Supervisor] Supervisor.start_link(children, opts) end end ``` Notice that it defines the application callback function, `start/2`, and instead of defining a supervisor named `KVServer.Supervisor` that uses the `Supervisor` module, it conveniently defined the supervisor inline! You can read more about such supervisors by reading [the Supervisor module documentation](https://hexdocs.pm/elixir/Supervisor.html). We can already try out our first umbrella child. We could run tests inside the `apps/kv_server` directory, but that wouldn’t be much fun. Instead, go to the root of the umbrella project and run `mix test`: ``` $ mix test ``` And it works! Since we want `kv_server` to eventually use the functionality we defined in `kv`, we need to add `kv` as a dependency to our application. Dependencies within an umbrella project --------------------------------------- Dependencies between applications in an umbrella project must still be explicitly defined and Mix makes it easy to do so. Open up `apps/kv_server/mix.exs` and change the `deps/0` function to the following: ``` defp deps do [{:kv, in_umbrella: true}] end ``` The line above makes `:kv` available as a dependency inside `:kv_server` and automatically starts the `:kv` application before the server starts. Finally, copy the `kv` application we have built so far to the `apps` directory in our new umbrella project. The final directory structure should match the structure we mentioned earlier: ``` + kv_umbrella + apps + kv + kv_server ``` We now need to modify `apps/kv/mix.exs` to contain the umbrella entries we have seen in `apps/kv_server/mix.exs`. Open up `apps/kv/mix.exs` and add to the `project/0` function: ``` build_path: "../../_build", config_path: "../../config/config.exs", deps_path: "../../deps", lockfile: "../../mix.lock", ``` Now you can run tests for both projects from the umbrella root with `mix test`. Sweet! Don’t drink the kool aid ------------------------ Umbrella projects are a convenience to help you organize and manage multiple applications. While it provides a degree of separation between applications, those applications are not fully decoupled, as they share the same configuration and the same dependencies. The pattern of keeping multiple applications in the same repository is known as “mono-repo”. Umbrella projects maximize this pattern by providing conveniences to compile, test and run multiple applications at once. If you find yourself in a position where you want to use different configurations in each application for the same dependency or use different dependency versions, then it is likely your codebase has grown beyond what umbrellas can provide. The good news is that breaking an umbrella apart is quite straightforward, as you simply need to move applications outside of the umbrella project’s `apps/` directory. In the worst case scenario, you can discard the umbrella project and all related configuration (`build_path`, `config_path`, `deps_path` and `lockfile`) and still leverage the “mono-repo” pattern by keeping all applications together in the same repository. Each application will have its own dependencies and configuration. Dependencies between those applications can still be explicitly listed by using the `:path` option (in contrast to `:git`). Summing up ---------- In this chapter, we have learned more about Mix dependencies and umbrella projects. While we may run `kv` without a server, our `kv_server` depends directly on `kv`. By breaking them into separate applications, we gain more control in how they are developed and tested. When using umbrella applications, it is important to have a clear boundary between them. Our upcoming `kv_server` must only access public APIs defined in `kv`. Think of your umbrella apps as any other dependency or even Elixir itself: you can only access what is public and documented. Reaching into private functionality in your dependencies is a poor practice that will eventually cause your code to break when a new version is up. Umbrella applications can also be used as a stepping stone for eventually extracting an application from your codebase. For example, imagine a web application that has to send “push notifications” to its users. The whole “push notifications system” can be developed as a separate application in the umbrella, with its own supervision tree and APIs. If you ever run into a situation where another project needs the push notifications system, the system can be moved to a private repository or a Hex package. Developers may also use umbrella projects to break large business domains apart. The caution here is to make sure the domains don’t depend on each other (also known as cyclic dependencies). If you run into such situations, it means those applications are not as isolated from each other as you originally thought, and you have architectural and design issues to solve. Finally, keep in mind that applications in an umbrella project all share the same configurations and dependencies. If two applications in your umbrella need to configure the same dependency in drastically different ways or even use different versions, you have probably outgrown the benefits brought by umbrellas. Remember you can break the umbrella and still leverage the benefits behind “mono-repos”. With our umbrella project up and running, it is time to start writing our server. puppeteer Puppeteer Documentation Puppeteer Documentation ======================= Overview -------- Puppeteer is a Node library which provides a high-level API to control Chromium or Chrome over the DevTools Protocol. The Puppeteer API is hierarchical and mirrors the browser structure. > **NOTE** On the following diagram, faded entities are not currently represented in Puppeteer. > > * [`Puppeteer`](#class-puppeteer) communicates with the browser using [DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/). * [`Browser`](#class-browser) instance can own multiple browser contexts. * [`BrowserContext`](#class-browsercontext) instance defines a browsing session and can own multiple pages. * [`Page`](#class-page) has at least one frame: main frame. There might be other frames created by [iframe](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe) or [frame](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/frame) tags. * [`Frame`](#class-frame) has at least one execution context - the default execution context - where the frame's JavaScript is executed. A Frame might have additional execution contexts that are associated with [extensions](https://developer.chrome.com/extensions). * [`Worker`](#class-worker) has a single execution context and facilitates interacting with [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API). (Diagram source: [link](https://docs.google.com/drawings/d/1Q_AM6KYs9kbyLZF-Lpp5mtpAWth73Cq8IKCsWYgi8MM/edit?usp=sharing)) puppeteer vs puppeteer-core --------------------------- Every release since v1.7.0 we publish two packages: * [puppeteer](https://www.npmjs.com/package/puppeteer) * [puppeteer-core](https://www.npmjs.com/package/puppeteer-core) `puppeteer` is a *product* for browser automation. When installed, it downloads a version of Chromium, which it then drives using `puppeteer-core`. Being an end-user product, `puppeteer` supports a bunch of convenient `PUPPETEER_*` env variables to tweak its behavior. `puppeteer-core` is a *library* to help drive anything that supports DevTools protocol. `puppeteer-core` doesn't download Chromium when installed. Being a library, `puppeteer-core` is fully driven through its programmatic interface and disregards all the `PUPPETEER_*` env variables. To sum up, the only differences between `puppeteer-core` and `puppeteer` are: * `puppeteer-core` doesn't automatically download Chromium when installed. * `puppeteer-core` ignores all `PUPPETEER_*` env variables. In most cases, you'll be fine using the `puppeteer` package. However, you should use `puppeteer-core` if: * you're building another end-user product or library atop of DevTools protocol. For example, one might build a PDF generator using `puppeteer-core` and write a custom `install.js` script that downloads [`headless_shell`](https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md) instead of Chromium to save disk space. * you're bundling Puppeteer to use in Chrome Extension / browser with the DevTools protocol where downloading an additional Chromium binary is unnecessary. * you're building a set of tools where `puppeteer-core` is one of the ingredients and you want to postpone `install.js` script execution until Chromium is about to be used. When using `puppeteer-core`, remember to change the *include* line: ``` const puppeteer = require('puppeteer-core'); ``` You will then need to call [`puppeteer.connect([options])`](#puppeteerconnectoptions) or [`puppeteer.launch([options])`](#puppeteerlaunchoptions) with an explicit `executablePath` option. Environment Variables --------------------- Puppeteer looks for certain [environment variables](https://en.wikipedia.org/wiki/Environment_variable) to aid its operations. If Puppeteer doesn't find them in the environment during the installation step, a lowercased variant of these variables will be used from the [npm config](https://docs.npmjs.com/cli/config). * `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` - defines HTTP proxy settings that are used to download and run Chromium. * `PUPPETEER_SKIP_CHROMIUM_DOWNLOAD` - do not download bundled Chromium during installation step. * `PUPPETEER_DOWNLOAD_HOST` - overwrite URL prefix that is used to download Chromium. Note: this includes protocol and might even include path prefix. Defaults to `https://storage.googleapis.com`. * `PUPPETEER_DOWNLOAD_PATH` - overwrite the path for the downloads folder. Defaults to `<root>/.local-chromium`, where `<root>` is puppeteer's package root. * `PUPPETEER_CHROMIUM_REVISION` - specify a certain version of Chromium you'd like Puppeteer to use. See [puppeteer.launch([options])](#puppeteerlaunchoptions) on how executable path is inferred. **BEWARE**: Puppeteer is only [guaranteed to work](https://github.com/puppeteer/puppeteer/#q-why-doesnt-puppeteer-vxxx-work-with-chromium-vyyy) with the bundled Chromium, use at your own risk. * `PUPPETEER_EXECUTABLE_PATH` - specify an executable path to be used in `puppeteer.launch`. See [puppeteer.launch([options])](#puppeteerlaunchoptions) on how the executable path is inferred. **BEWARE**: Puppeteer is only [guaranteed to work](https://github.com/puppeteer/puppeteer/#q-why-doesnt-puppeteer-vxxx-work-with-chromium-vyyy) with the bundled Chromium, use at your own risk. * `PUPPETEER_PRODUCT` - specify which browser you'd like Puppeteer to use. Must be one of `chrome` or `firefox`. This can also be used during installation to fetch the recommended browser binary. Setting `product` programmatically in [puppeteer.launch([options])](#puppeteerlaunchoptions) supersedes this environment variable. The product is exposed in [`puppeteer.product`](#puppeteerproduct) > **NOTE** PUPPETEER\_\* env variables are not accounted for in the [`puppeteer-core`](https://www.npmjs.com/package/puppeteer-core) package. > > Working with Chrome Extensions ------------------------------ Puppeteer can be used for testing Chrome Extensions. > **NOTE** Extensions in Chrome / Chromium currently only work in non-headless mode. > > The following is code for getting a handle to the [background page](https://developer.chrome.com/extensions/background_pages) of an extension whose source is located in `./my-extension`: ``` const puppeteer = require('puppeteer'); (async () => { const pathToExtension = require('path').join(__dirname, 'my-extension'); const browser = await puppeteer.launch({ headless: false, args: [ `--disable-extensions-except=${pathToExtension}`, `--load-extension=${pathToExtension}` ] }); const targets = await browser.targets(); const backgroundPageTarget = targets.find(target => target.type() === 'background_page'); const backgroundPage = await backgroundPageTarget.page(); // Test the background page as you would any other page. await browser.close(); })(); ``` > **NOTE** It is not yet possible to test extension popups or content scripts. > > class: Puppeteer ---------------- Puppeteer module provides a method to launch a Chromium instance. The following is a typical example of using Puppeteer to drive automation: ``` const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto('https://www.google.com'); // other actions... await browser.close(); })(); ``` ### puppeteer.clearCustomQueryHandlers() Clears all registered handlers. ### puppeteer.connect(options) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `browserWSEndpoint` <?[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> a [browser websocket endpoint](#browserwsendpoint) to connect to. + `browserURL` <?[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> a browser url to connect to, in format `http://${host}:${port}`. Use interchangeably with `browserWSEndpoint` to let Puppeteer fetch it from [metadata endpoint](https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target). + `ignoreHTTPSErrors` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether to ignore HTTPS errors during navigation. Defaults to `false`. + `defaultViewport` <?[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Sets a consistent viewport for each page. Defaults to an 800x600 viewport. `null` disables the default viewport. - `width` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> page width in pixels. - `height` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> page height in pixels. - `deviceScaleFactor` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Specify device scale factor (can be thought of as dpr). Defaults to `1`. - `isMobile` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether the `meta viewport` tag is taken into account. Defaults to `false`. - `hasTouch`<[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Specifies if viewport supports touch events. Defaults to `false` - `isLandscape` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Specifies if viewport is in landscape mode. Defaults to `false`. + `slowMo` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Slows down Puppeteer operations by the specified amount of milliseconds. Useful so that you can see what is going on. + `transport` <[ConnectionTransport](https://github.com/puppeteer/puppeteer/blob/v7.1.0/src/WebSocketTransport.js "ConnectionTransport")> **Experimental** Specify a custom transport object for Puppeteer to use. + `product` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Possible values are: `chrome`, `firefox`. Defaults to `chrome`. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Browser](#class-browser "Browser")>> This methods attaches Puppeteer to an existing browser instance. ### puppeteer.createBrowserFetcher([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `host` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A download host to be used. Defaults to `https://storage.googleapis.com`. If the `product` is `firefox`, this defaults to `https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central`. + `path` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A path for the downloads folder. Defaults to `<root>/.local-chromium`, where `<root>` is puppeteer's package root. If the `product` is `firefox`, this defaults to `<root>/.local-firefox`. + `platform` <"linux"|"mac"|"win32"|"win64"> [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String") for the current platform. Possible values are: `mac`, `win32`, `win64`, `linux`. Defaults to the current platform. + `product` <"chrome"|"firefox"> [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String") for the product to run. Possible values are: `chrome`, `firefox`. Defaults to `chrome`. * returns: <[BrowserFetcher](#class-browserfetcher "BrowserFetcher")> ### puppeteer.customQueryHandlerNames() * returns: <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")> A list with the names of all registered custom query handlers. ### puppeteer.defaultArgs([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Set of configurable options to set on the browser. Can have the following fields: + `headless` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether to run browser in [headless mode](https://developers.google.com/web/updates/2017/04/headless-chrome). Defaults to `true` unless the `devtools` option is `true`. + `args` <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>> Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/). + `userDataDir` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Path to a [User Data Directory](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md). + `devtools` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether to auto-open a DevTools panel for each tab. If this option is `true`, the `headless` option will be set `false`. * returns: <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>> The default flags that Chromium will be launched with. ### puppeteer.devices * returns: <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Returns a list of devices to be used with [`page.emulate(options)`](#pageemulateoptions). Actual list of devices can be found in [`src/common/DeviceDescriptors.ts`](https://github.com/puppeteer/puppeteer/blob/main/src/common/DeviceDescriptors.ts). ``` const puppeteer = require('puppeteer'); const iPhone = puppeteer.devices['iPhone 6']; (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.emulate(iPhone); await page.goto('https://www.google.com'); // other actions... await browser.close(); })(); ``` ### puppeteer.errors * returns: <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `TimeoutError` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")> A class of [TimeoutError](#class-timeouterror "TimeoutError"). Puppeteer methods might throw errors if they are unable to fulfill a request. For example, [page.waitForSelector(selector[, options])](#pagewaitforselectorselector-options) might fail if the selector doesn't match any nodes during the given timeframe. For certain types of errors Puppeteer uses specific error classes. These classes are available via [`puppeteer.errors`](#puppeteererrors) An example of handling a timeout error: ``` try { await page.waitForSelector('.foo'); } catch (e) { if (e instanceof puppeteer.errors.TimeoutError) { // Do something if this is a timeout. } } ``` > **NOTE** The old way (Puppeteer versions <= v1.14.0) errors can be obtained with `require('puppeteer/Errors')`. > > ### puppeteer.executablePath() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A path where Puppeteer expects to find the bundled browser. The browser binary might not be there if the download was skipped with [`PUPPETEER_SKIP_DOWNLOAD`](#environment-variables). > **NOTE** `puppeteer.executablePath()` is affected by the `PUPPETEER_EXECUTABLE_PATH` and `PUPPETEER_CHROMIUM_REVISION` env variables. See [Environment Variables](#environment-variables) for details. > > ### puppeteer.launch([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Set of configurable options to set on the browser. Can have the following fields: + `product` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Which browser to launch. At this time, this is either `chrome` or `firefox`. See also `PUPPETEER_PRODUCT`. + `ignoreHTTPSErrors` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether to ignore HTTPS errors during navigation. Defaults to `false`. + `headless` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether to run browser in [headless mode](https://developers.google.com/web/updates/2017/04/headless-chrome). Defaults to `true` unless the `devtools` option is `true`. + `executablePath` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Path to a browser executable to run instead of the bundled Chromium. If `executablePath` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). **BEWARE**: Puppeteer is only [guaranteed to work](https://github.com/puppeteer/puppeteer/#q-why-doesnt-puppeteer-vxxx-work-with-chromium-vyyy) with the bundled Chromium, use at your own risk. + `slowMo` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Slows down Puppeteer operations by the specified amount of milliseconds. Useful so that you can see what is going on. + `defaultViewport` <?[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Sets a consistent viewport for each page. Defaults to an 800x600 viewport. `null` disables the default viewport. - `width` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> page width in pixels. - `height` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> page height in pixels. - `deviceScaleFactor` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Specify device scale factor (can be thought of as dpr). Defaults to `1`. - `isMobile` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether the `meta viewport` tag is taken into account. Defaults to `false`. - `hasTouch`<[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Specifies if viewport supports touch events. Defaults to `false` - `isLandscape` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Specifies if viewport is in landscape mode. Defaults to `false`. + `args` <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>> Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/), and here is the list of [Firefox flags](https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options). + `ignoreDefaultArgs` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")|[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>> If `true`, then do not use [`puppeteer.defaultArgs()`](#puppeteerdefaultargsoptions). If an array is given, then filter out the given default arguments. Dangerous option; use with care. Defaults to `false`. + `handleSIGINT` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Close the browser process on Ctrl-C. Defaults to `true`. + `handleSIGTERM` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Close the browser process on SIGTERM. Defaults to `true`. + `handleSIGHUP` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Close the browser process on SIGHUP. Defaults to `true`. + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. + `dumpio` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether to pipe the browser process stdout and stderr into `process.stdout` and `process.stderr`. Defaults to `false`. + `userDataDir` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Path to a [User Data Directory](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md). + `env` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Specify environment variables that will be visible to the browser. Defaults to `process.env`. + `devtools` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether to auto-open a DevTools panel for each tab. If this option is `true`, the `headless` option will be set `false`. + `pipe` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Connects to the browser over a pipe instead of a WebSocket. Defaults to `false`. + `extraPrefsFirefox` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Additional [preferences](https://developer.mozilla.org/en-US/docs/Mozilla/Preferences/Preference_reference) that can be passed to Firefox (see `PUPPETEER_PRODUCT`) * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Browser](#class-browser "Browser")>> Promise which resolves to browser instance. You can use `ignoreDefaultArgs` to filter out `--mute-audio` from default arguments: ``` const browser = await puppeteer.launch({ ignoreDefaultArgs: ['--mute-audio'] }); ``` > **NOTE** Puppeteer can also be used to control the Chrome browser, but it works best with the version of Chromium it is bundled with. There is no guarantee it will work with any other version. Use `executablePath` option with extreme caution. > > If Google Chrome (rather than Chromium) is preferred, a [Chrome Canary](https://www.google.com/chrome/browser/canary.html) or [Dev Channel](https://www.chromium.org/getting-involved/dev-channel) build is suggested. > > In [puppeteer.launch([options])](#puppeteerlaunchoptions) above, any mention of Chromium also applies to Chrome. > > See [`this article`](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for a description of the differences between Chromium and Chrome. [`This article`](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md) describes some differences for Linux users. > > ### puppeteer.networkConditions * returns: <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Returns a list of network conditions to be used with [`page.emulateNetworkConditions(networkConditions)`](#pageemulatenetworkconditionsnetworkconditions). Actual list of conditions can be found in [`src/common/NetworkConditions.ts`](https://github.com/puppeteer/puppeteer/blob/main/src/common/NetworkConditions.ts). ``` const puppeteer = require('puppeteer'); const slow3G = puppeteer.networkConditions['Slow 3G']; (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.emulateNetworkConditions(slow3G); await page.goto('https://www.google.com'); // other actions... await browser.close(); })(); ``` ### puppeteer.product * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> returns the name of the browser that is under automation (`"chrome"` or `"firefox"`) The product is set by the `PUPPETEER_PRODUCT` environment variable or the `product` option in [puppeteer.launch([options])](#puppeteerlaunchoptions) and defaults to `chrome`. Firefox support is experimental and requires to install Puppeteer via `PUPPETEER_PRODUCT=firefox npm i puppeteer`. ### puppeteer.registerCustomQueryHandler(name, queryHandler) * `name` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> The name that the custom query handler will be registered under. * `queryHandler` <[CustomQueryHandler](#interface-customqueryhandler "CustomQueryHandler")> The [custom query handler](#interface-customqueryhandler) to register. Registers a [custom query handler](#interface-customqueryhandler). After registration, the handler can be used everywhere where a selector is expected by prepending the selection string with `<name>/`. The name is only allowed to consist of lower- and upper case latin letters. Example: ``` puppeteer.registerCustomQueryHandler('getByClass', { queryOne: (element, selector) => { return element.querySelector(`.${selector}`); }, queryAll: (element, selector) => { return element.querySelectorAll(`.${selector}`); }, }); const aHandle = await page.$('getByClass/…'); ``` ### puppeteer.unregisterCustomQueryHandler(name) * `name` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> The name of the query handler to unregister. class: BrowserFetcher --------------------- BrowserFetcher can download and manage different versions of Chromium and Firefox. BrowserFetcher operates on revision strings that specify a precise version of Chromium, e.g. `"533271"`. Revision strings can be obtained from [omahaproxy.appspot.com](http://omahaproxy.appspot.com/). In the Firefox case, BrowserFetcher downloads Firefox Nightly and operates on version numbers such as `"75"`. An example of using BrowserFetcher to download a specific version of Chromium and running Puppeteer against it: ``` const browserFetcher = puppeteer.createBrowserFetcher(); const revisionInfo = await browserFetcher.download('533271'); const browser = await puppeteer.launch({executablePath: revisionInfo.executablePath}) ``` > **NOTE** BrowserFetcher is not designed to work concurrently with other instances of BrowserFetcher that share the same downloads directory. > > ### browserFetcher.canDownload(revision) * `revision` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> a revision to check availability. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")>> returns `true` if the revision could be downloaded from the host. The method initiates a HEAD request to check if the revision is available. ### browserFetcher.download(revision[, progressCallback]) * `revision` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> a revision to download. * `progressCallback` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number"), [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number"))> A function that will be called with two arguments: + `downloadedBytes` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> how many bytes have been downloaded + `totalBytes` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> how large is the total download. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> Resolves with revision information when the revision is downloaded and extracted + `revision` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> the revision the info was created from + `folderPath` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> path to the extracted revision folder + `executablePath` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> path to the revision executable + `url` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> URL this revision can be downloaded from + `local` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> whether the revision is locally available on disk The method initiates a GET request to download the revision from the host. ### browserFetcher.host() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> The download host being used. ### browserFetcher.localRevisions() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>>> A list of all revisions (for the current `product`) available locally on disk. ### browserFetcher.platform() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> One of `mac`, `linux`, `win32` or `win64`. ### browserFetcher.product() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> One of `chrome` or `firefox`. ### browserFetcher.remove(revision) * `revision` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> a revision to remove for the current `product`. The method will throw if the revision has not been downloaded. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Resolves when the revision has been removed. ### browserFetcher.revisionInfo(revision) * `revision` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> a revision to get info for. * returns: <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `revision` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> the revision the info was created from + `folderPath` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> path to the extracted revision folder + `executablePath` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> path to the revision executable + `url` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> URL this revision can be downloaded from + `local` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> whether the revision is locally available on disk + `product` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> one of `chrome` or `firefox` > **NOTE** Many BrowserFetcher methods, like `remove` and `revisionInfo` are affected by the choice of `product`. See [puppeteer.createBrowserFetcher([options])](#puppeteercreatebrowserfetcheroptions). > > class: Browser -------------- * extends: [EventEmitter](#class-eventemitter) A Browser is created when Puppeteer connects to a Chromium instance, either through [`puppeteer.launch`](#puppeteerlaunchoptions) or [`puppeteer.connect`](#puppeteerconnectoptions). An example of using a [Browser](#class-browser "Browser") to create a [Page](#class-page "Page"): ``` const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto('https://example.com'); await browser.close(); })(); ``` An example of disconnecting from and reconnecting to a [Browser](#class-browser "Browser"): ``` const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); // Store the endpoint to be able to reconnect to Chromium const browserWSEndpoint = browser.wsEndpoint(); // Disconnect puppeteer from Chromium browser.disconnect(); // Use the endpoint to reestablish a connection const browser2 = await puppeteer.connect({browserWSEndpoint}); // Close Chromium await browser2.close(); })(); ``` ### event: 'disconnected' Emitted when Puppeteer gets disconnected from the Chromium instance. This might happen because of one of the following: * Chromium is closed or crashed * The [`browser.disconnect`](#browserdisconnect) method was called ### event: 'targetchanged' * <[Target](#class-target "Target")> Emitted when the url of a target changes. > **NOTE** This includes target changes in incognito browser contexts. > > ### event: 'targetcreated' * <[Target](#class-target "Target")> Emitted when a target is created, for example when a new page is opened by [`window.open`](https://developer.mozilla.org/en-US/docs/Web/API/Window/open) or [`browser.newPage`](#browsernewpage). > **NOTE** This includes target creations in incognito browser contexts. > > ### event: 'targetdestroyed' * <[Target](#class-target "Target")> Emitted when a target is destroyed, for example when a page is closed. > **NOTE** This includes target destructions in incognito browser contexts. > > ### browser.browserContexts() * returns: <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[BrowserContext](#class-browsercontext "BrowserContext")>> Returns an array of all open browser contexts. In a newly created browser, this will return a single instance of [BrowserContext](#class-browsercontext "BrowserContext"). ### browser.close() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Closes Chromium and all of its pages (if any were opened). The [Browser](#class-browser "Browser") object itself is considered to be disposed and cannot be used anymore. ### browser.createIncognitoBrowserContext() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[BrowserContext](#class-browsercontext "BrowserContext")>> Creates a new incognito browser context. This won't share cookies/cache with other browser contexts. ``` (async () => { const browser = await puppeteer.launch(); // Create a new incognito browser context. const context = await browser.createIncognitoBrowserContext(); // Create a new page in a pristine context. const page = await context.newPage(); // Do stuff await page.goto('https://example.com'); })(); ``` ### browser.defaultBrowserContext() * returns: <[BrowserContext](#class-browsercontext "BrowserContext")> Returns the default browser context. The default browser context can not be closed. ### browser.disconnect() Disconnects Puppeteer from the browser, but leaves the Chromium process running. After calling `disconnect`, the [Browser](#class-browser "Browser") object is considered disposed and cannot be used anymore. ### browser.isConnected() * returns: <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Indicates that the browser is connected. ### browser.newPage() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Page](#class-page "Page")>> Promise which resolves to a new [Page](#class-page "Page") object. The [Page](#class-page "Page") is created in a default browser context. ### browser.pages() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Page](#class-page "Page")>>> Promise which resolves to an array of all open pages. Non visible pages, such as `"background_page"`, will not be listed here. You can find them using [target.page()](#targetpage). An array of all pages inside the Browser. In case of multiple browser contexts, the method will return an array with all the pages in all browser contexts. ### browser.process() * returns: <?[ChildProcess](https://nodejs.org/api/child_process.html "ChildProcess")> Spawned browser process. Returns `null` if the browser instance was created with [`puppeteer.connect`](#puppeteerconnectoptions) method. ### browser.target() * returns: <[Target](#class-target "Target")> A target associated with the browser. ### browser.targets() * returns: <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Target](#class-target "Target")>> An array of all active targets inside the Browser. In case of multiple browser contexts, the method will return an array with all the targets in all browser contexts. ### browser.userAgent() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>> Promise which resolves to the browser's original user agent. > **NOTE** Pages can override browser user agent with [page.setUserAgent](#pagesetuseragentuseragent) > > ### browser.version() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>> For headless Chromium, this is similar to `HeadlessChrome/61.0.3153.0`. For non-headless, this is similar to `Chrome/61.0.3153.0`. > **NOTE** the format of browser.version() might change with future releases of Chromium. > > ### browser.waitForTarget(predicate[, options]) * `predicate` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([Target](#class-target "Target")):[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> A function to be run for every target * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Maximum wait time in milliseconds. Pass `0` to disable the timeout. Defaults to 30 seconds. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Target](#class-target "Target")>> Promise which resolves to the first target found that matches the `predicate` function. This searches for a target in all browser contexts. An example of finding a target for a page opened via `window.open`: ``` await page.evaluate(() => window.open('https://www.example.com/')); const newWindowTarget = await browser.waitForTarget(target => target.url() === 'https://www.example.com/'); ``` ### browser.wsEndpoint() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Browser websocket url. Browser websocket endpoint which can be used as an argument to [puppeteer.connect](#puppeteerconnectoptions). The format is `ws://${host}:${port}/devtools/browser/<id>` You can find the `webSocketDebuggerUrl` from `http://${host}:${port}/json/version`. Learn more about the [devtools protocol](https://chromedevtools.github.io/devtools-protocol) and the [browser endpoint](https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target). class: BrowserContext --------------------- * extends: [EventEmitter](#class-eventemitter) BrowserContexts provide a way to operate multiple independent browser sessions. When a browser is launched, it has a single BrowserContext used by default. The method `browser.newPage()` creates a page in the default browser context. If a page opens another page, e.g. with a `window.open` call, the popup will belong to the parent page's browser context. Puppeteer allows creation of "incognito" browser contexts with `browser.createIncognitoBrowserContext()` method. "Incognito" browser contexts don't write any browsing data to disk. ``` // Create a new incognito browser context const context = await browser.createIncognitoBrowserContext(); // Create a new page inside context. const page = await context.newPage(); // ... do stuff with page ... await page.goto('https://example.com'); // Dispose context once it's no longer needed. await context.close(); ``` ### event: 'targetchanged' * <[Target](#class-target "Target")> Emitted when the url of a target inside the browser context changes. ### event: 'targetcreated' * <[Target](#class-target "Target")> Emitted when a new target is created inside the browser context, for example when a new page is opened by [`window.open`](https://developer.mozilla.org/en-US/docs/Web/API/Window/open) or [`browserContext.newPage`](#browsercontextnewpage). ### event: 'targetdestroyed' * <[Target](#class-target "Target")> Emitted when a target inside the browser context is destroyed, for example when a page is closed. ### browserContext.browser() * returns: <[Browser](#class-browser "Browser")> The browser this browser context belongs to. ### browserContext.clearPermissionOverrides() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Clears all permission overrides for the browser context. ``` const context = browser.defaultBrowserContext(); context.overridePermissions('https://example.com', ['clipboard-read']); // do stuff .. context.clearPermissionOverrides(); ``` ### browserContext.close() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Closes the browser context. All the targets that belong to the browser context will be closed. > **NOTE** only incognito browser contexts can be closed. > > ### browserContext.isIncognito() * returns: <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Returns whether BrowserContext is incognito. The default browser context is the only non-incognito browser context. > **NOTE** the default browser context cannot be closed. > > ### browserContext.newPage() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Page](#class-page "Page")>> Creates a new page in the browser context. ### browserContext.overridePermissions(origin, permissions) * `origin` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> The [origin](https://developer.mozilla.org/en-US/docs/Glossary/Origin "Origin") to grant permissions to, e.g. "<https://example.com>". * `permissions` <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>> An array of permissions to grant. All permissions that are not listed here will be automatically denied. Permissions can be one of the following values: + `'geolocation'` + `'midi'` + `'midi-sysex'` (system-exclusive midi) + `'notifications'` + `'push'` + `'camera'` + `'microphone'` + `'background-sync'` + `'ambient-light-sensor'` + `'accelerometer'` + `'gyroscope'` + `'magnetometer'` + `'accessibility-events'` + `'clipboard-read'` + `'clipboard-write'` + `'payment-handler'` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> ``` const context = browser.defaultBrowserContext(); await context.overridePermissions('https://html5demos.com', ['geolocation']); ``` ### browserContext.pages() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Page](#class-page "Page")>>> Promise which resolves to an array of all open pages. Non visible pages, such as `"background_page"`, will not be listed here. You can find them using [target.page()](#targetpage). An array of all pages inside the browser context. ### browserContext.targets() * returns: <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Target](#class-target "Target")>> An array of all active targets inside the browser context. ### browserContext.waitForTarget(predicate[, options]) * `predicate` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([Target](#class-target "Target")):[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> A function to be run for every target * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Maximum wait time in milliseconds. Pass `0` to disable the timeout. Defaults to 30 seconds. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Target](#class-target "Target")>> Promise which resolves to the first target found that matches the `predicate` function. This searches for a target in this specific browser context. An example of finding a target for a page opened via `window.open`: ``` await page.evaluate(() => window.open('https://www.example.com/')); const newWindowTarget = await browserContext.waitForTarget(target => target.url() === 'https://www.example.com/'); ``` class: Page ----------- * extends: [EventEmitter](#class-eventemitter) Page provides methods to interact with a single tab or [extension background page](https://developer.chrome.com/extensions/background_pages) in Chromium. One [Browser](#class-browser "Browser") instance might have multiple [Page](#class-page "Page") instances. This example creates a page, navigates it to a URL, and then saves a screenshot: ``` const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto('https://example.com'); await page.screenshot({path: 'screenshot.png'}); await browser.close(); })(); ``` The Page class emits various events (described below) which can be handled using any of the [`EventEmitter`](#class-eventemitter) methods, such as `on`, `once` or `off`. This example logs a message for a single page `load` event: ``` page.once('load', () => console.log('Page loaded!')); ``` To unsubscribe from events use the `off` method: ``` function logRequest(interceptedRequest) { console.log('A request was made:', interceptedRequest.url()); } page.on('request', logRequest); // Sometime later... page.off('request', logRequest); ``` ### event: 'close' Emitted when the page closes. ### event: 'console' * <[ConsoleMessage](#class-consolemessage "ConsoleMessage")> Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. Also emitted if the page throws an error or a warning. The arguments passed into `console.log` appear as arguments on the event handler. An example of handling `console` event: ``` page.on('console', msg => { for (let i = 0; i < msg.args().length; ++i) console.log(`${i}: ${msg.args()[i]}`); }); page.evaluate(() => console.log('hello', 5, {foo: 'bar'})); ``` ### event: 'dialog' * <[Dialog](#class-dialog "Dialog")> Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Puppeteer can respond to the dialog via [Dialog](#class-dialog "Dialog")'s [accept](#dialogacceptprompttext) or [dismiss](#dialogdismiss) methods. ### event: 'domcontentloaded' Emitted when the JavaScript [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) event is dispatched. ### event: 'error' * <[Error](https://nodejs.org/api/errors.html#errors_class_error "Error")> Emitted when the page crashes. > **NOTE** `error` event has a special meaning in Node, see [error events](https://nodejs.org/api/events.html#events_error_events) for details. > > ### event: 'frameattached' * <[Frame](#class-frame "Frame")> Emitted when a frame is attached. ### event: 'framedetached' * <[Frame](#class-frame "Frame")> Emitted when a frame is detached. ### event: 'framenavigated' * <[Frame](#class-frame "Frame")> Emitted when a frame is navigated to a new url. ### event: 'load' Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched. ### event: 'metrics' * <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `title` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> The title passed to `console.timeStamp`. + `metrics` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Object containing metrics as key/value pairs. The values of metrics are of <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> type. Emitted when the JavaScript code makes a call to `console.timeStamp`. For the list of metrics see `page.metrics`. ### event: 'pageerror' * <[Error](https://nodejs.org/api/errors.html#errors_class_error "Error")> The exception message Emitted when an uncaught exception happens within the page. ### event: 'popup' * <[Page](#class-page "Page")> Page corresponding to "popup" window Emitted when the page opens a new tab or window. ``` const [popup] = await Promise.all([ new Promise(resolve => page.once('popup', resolve)), page.click('a[target=_blank]'), ]); ``` ``` const [popup] = await Promise.all([ new Promise(resolve => page.once('popup', resolve)), page.evaluate(() => window.open('https://example.com')), ]); ``` ### event: 'request' * <[HTTPRequest](#class-httprequest "HTTPRequest")> Emitted when a page issues a request. The [HTTPRequest](#class-httprequest "HTTPRequest") object is read-only. In order to intercept and mutate requests, see `page.setRequestInterception`. ### event: 'requestfailed' * <[HTTPRequest](#class-httprequest "HTTPRequest")> Emitted when a request fails, for example by timing out. > **NOTE** HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete with [`'requestfinished'`](#event-requestfinished) event and not with [`'requestfailed'`](#event-requestfailed). > > ### event: 'requestfinished' * <[HTTPRequest](#class-httprequest "HTTPRequest")> Emitted when a request finishes successfully. ### event: 'response' * <[HTTPResponse](#class-httpresponse "HTTPResponse")> Emitted when a [HTTPResponse](#class-httpresponse "HTTPResponse") is received. ### event: 'workercreated' * <[WebWorker](#class-webworker "Worker")> Emitted when a dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is spawned by the page. ### event: 'workerdestroyed' * <[WebWorker](#class-webworker "Worker")> Emitted when a dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is terminated. ### page.$(selector) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to query page for * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[ElementHandle](#class-elementhandle "ElementHandle")>> The method runs `document.querySelector` within the page. If no element matches the selector, the return value resolves to `null`. Shortcut for [page.mainFrame().$(selector)](#frameselector). ### page.$$(selector) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to query page for * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[ElementHandle](#class-elementhandle "ElementHandle")>>> The method runs `document.querySelectorAll` within the page. If no elements match the selector, the return value resolves to `[]`. Shortcut for [page.mainFrame().$$(selector)](#frameselector-1). ### page.$$eval(selector, pageFunction[, ...args]) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to query page for * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Element](https://developer.mozilla.org/en-US/docs/Web/API/element "Element")>)> Function to be evaluated in browser context * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")>> Promise which resolves to the return value of `pageFunction` This method runs `Array.from(document.querySelectorAll(selector))` within the page and passes it as the first argument to `pageFunction`. If `pageFunction` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `page.$$eval` would wait for the promise to resolve and return its value. Examples: ``` const divCount = await page.$$eval('div', divs => divs.length); ``` ``` const options = await page.$$eval('div > span.options', options => options.map(option => option.textContent)); ``` ### page.$eval(selector, pageFunction[, ...args]) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to query page for * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([Element](https://developer.mozilla.org/en-US/docs/Web/API/element "Element"))> Function to be evaluated in browser context * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")>> Promise which resolves to the return value of `pageFunction` This method runs `document.querySelector` within the page and passes it as the first argument to `pageFunction`. If there's no element matching `selector`, the method throws an error. If `pageFunction` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `page.$eval` would wait for the promise to resolve and return its value. Examples: ``` const searchValue = await page.$eval('#search', el => el.value); const preloadHref = await page.$eval('link[rel=preload]', el => el.href); const html = await page.$eval('.main-container', e => e.outerHTML); ``` Shortcut for [page.mainFrame().$eval(selector, pageFunction)](#frameevalselector-pagefunction-args). ### page.$x(expression) * `expression` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Expression to [evaluate](https://developer.mozilla.org/en-US/docs/Web/API/Document/evaluate). * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[ElementHandle](#class-elementhandle "ElementHandle")>>> The method evaluates the XPath expression relative to the page document as its context node. If there are no such elements, the method resolves to an empty array. Shortcut for [page.mainFrame().$x(expression)](#framexexpression) ### page.accessibility * returns: <[Accessibility](#class-accessibility "Accessibility")> ### page.addScriptTag(options) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `url` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> URL of a script to be added. + `path` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). + `content` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Raw JavaScript content to be injected into frame. + `type` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Script type. Use 'module' in order to load a Javascript ES6 module. See [script](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) for more details. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[ElementHandle](#class-elementhandle "ElementHandle")>> which resolves to the added tag when the script's onload fires or when the script content was injected into frame. Adds a `<script>` tag into the page with the desired url or content. Shortcut for [page.mainFrame().addScriptTag(options)](#frameaddscripttagoptions). ### page.addStyleTag(options) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `url` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> URL of the `<link>` tag. + `path` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). + `content` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Raw CSS content to be injected into frame. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[ElementHandle](#class-elementhandle "ElementHandle")>> which resolves to the added tag when the stylesheet's onload fires or when the CSS content was injected into frame. Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the content. Shortcut for [page.mainFrame().addStyleTag(options)](#frameaddstyletagoptions). ### page.authenticate(credentials) * `credentials` <?[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `username` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> + `password` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Provide credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication). To disable authentication, pass `null`. ### page.bringToFront() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Brings page to front (activates tab). ### page.browser() * returns: <[Browser](#class-browser "Browser")> Get the browser the page belongs to. ### page.browserContext() * returns: <[BrowserContext](#class-browsercontext "BrowserContext")> Get the browser context that the page belongs to. ### page.click(selector[, options]) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked. * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `button` <"left"|"right"|"middle"> Defaults to `left`. + `clickCount` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> defaults to 1. See [UIEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail"). + `delay` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves when the element matching `selector` is successfully clicked. The Promise will be rejected if there is no element matching `selector`. This method fetches an element with `selector`, scrolls it into view if needed, and then uses [page.mouse](#pagemouse) to click in the center of the element. If there's no element matching `selector`, the method throws an error. Bear in mind that if `click()` triggers a navigation event and there's a separate `page.waitForNavigation()` promise to be resolved, you may end up with a race condition that yields unexpected results. The correct pattern for click and wait for navigation is the following: ``` const [response] = await Promise.all([ page.waitForNavigation(waitOptions), page.click(selector, clickOptions), ]); ``` Shortcut for [page.mainFrame().click(selector[, options])](#frameclickselector-options). ### page.close([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `runBeforeUnload` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Defaults to `false`. Whether to run the [before unload](https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload) page handlers. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> By default, `page.close()` **does not** run beforeunload handlers. > **NOTE** if `runBeforeUnload` is passed as true, a `beforeunload` dialog might be summoned and should be handled manually via page's ['dialog'](#event-dialog) event. > > ### page.content() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>> Gets the full HTML contents of the page, including the doctype. ### page.cookies([...urls]) * `...urls` <...[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>>> + `name` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> + `value` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> + `domain` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> + `path` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> + `expires` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Unix time in seconds. + `size` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> + `httpOnly` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> + `secure` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> + `session` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> + `sameSite` <"Strict"|"Lax"|"Extended"|"None"> If no URLs are specified, this method returns cookies for the current page URL. If URLs are specified, only cookies for those URLs are returned. ### page.coverage * returns: <[Coverage](#class-coverage "Coverage")> ### page.deleteCookie(...cookies) * `...cookies` <...[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `name` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> **required** + `url` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> + `domain` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> + `path` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> ### page.emulate(options) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `viewport` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> - `width` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> page width in pixels. - `height` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> page height in pixels. - `deviceScaleFactor` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Specify device scale factor (can be thought of as dpr). Defaults to `1`. - `isMobile` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether the `meta viewport` tag is taken into account. Defaults to `false`. - `hasTouch`<[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Specifies if viewport supports touch events. Defaults to `false` - `isLandscape` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Specifies if viewport is in landscape mode. Defaults to `false`. + `userAgent` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Emulates given device metrics and user agent. This method is a shortcut for calling two methods: * [page.setUserAgent(userAgent)](#pagesetuseragentuseragent) * [page.setViewport(viewport)](#pagesetviewportviewport) To aid emulation, puppeteer provides a list of device descriptors which can be obtained via the [`puppeteer.devices`](#puppeteerdevices). `page.emulate` will resize the page. A lot of websites don't expect phones to change size, so you should emulate before navigating to the page. ``` const puppeteer = require('puppeteer'); const iPhone = puppeteer.devices['iPhone 6']; (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.emulate(iPhone); await page.goto('https://www.google.com'); // other actions... await browser.close(); })(); ``` List of all available devices is available in the source code: [src/common/DeviceDescriptors.ts](https://github.com/puppeteer/puppeteer/blob/main/src/common/DeviceDescriptors.ts). ### page.emulateIdleState(overrides) * `overrides` <?[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> If not set, clears emulation + `isUserActive` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> **required** + `isScreenUnlocked` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> **required** * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> ### page.emulateMediaFeatures(features) * `features` <?[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> Given an array of media feature objects, emulates CSS media features on the page. Each media feature object must have the following properties: + `name` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> The CSS media feature name. Supported names are `'prefers-colors-scheme'`, `'prefers-reduced-motion'`, and `'color-gamut'`. + `value` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> The value for the given CSS media feature. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> ``` await page.emulateMediaFeatures([{ name: 'prefers-color-scheme', value: 'dark' }]); await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches); // → true await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches); // → false await page.emulateMediaFeatures([{ name: 'prefers-reduced-motion', value: 'reduce' }]); await page.evaluate(() => matchMedia('(prefers-reduced-motion: reduce)').matches); // → true await page.evaluate(() => matchMedia('(prefers-reduced-motion: no-preference)').matches); // → false await page.emulateMediaFeatures([ { name: 'prefers-color-scheme', value: 'dark' }, { name: 'prefers-reduced-motion', value: 'reduce' }, ]); await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches); // → true await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches); // → false await page.evaluate(() => matchMedia('(prefers-reduced-motion: reduce)').matches); // → true await page.evaluate(() => matchMedia('(prefers-reduced-motion: no-preference)').matches); // → false await page.emulateMediaFeatures([ { name: 'color-gamut', value: 'p3' }, ]); await page.evaluate(() => matchMedia('(color-gamut: srgb)').matches); // → true await page.evaluate(() => matchMedia('(color-gamut: p3)').matches); // → true await page.evaluate(() => matchMedia('(color-gamut: rec2020)').matches); // → false ``` ### page.emulateMediaType(type) * `type` <?[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Changes the CSS media type of the page. The only allowed values are `'screen'`, `'print'` and `null`. Passing `null` disables CSS media emulation. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> ``` await page.evaluate(() => matchMedia('screen').matches); // → true await page.evaluate(() => matchMedia('print').matches); // → false await page.emulateMediaType('print'); await page.evaluate(() => matchMedia('screen').matches); // → false await page.evaluate(() => matchMedia('print').matches); // → true await page.emulateMediaType(null); await page.evaluate(() => matchMedia('screen').matches); // → true await page.evaluate(() => matchMedia('print').matches); // → false ``` ### page.emulateNetworkConditions(networkConditions) * `networkConditions` <?[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Passing `null` disables network condition emulation. + `download` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Download speed (bytes/s), `-1` to disable + `upload` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Upload speed (bytes/s), `-1` to disable + `latency` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Latency (ms), `0` to disable * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> > **NOTE** This does not affect WebSockets and WebRTC PeerConnections (see <https://crbug.com/563644>) > > ``` const puppeteer = require('puppeteer'); const slow3G = puppeteer.networkConditions['Slow 3G']; (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.emulateNetworkConditions(slow3G); await page.goto('https://www.google.com'); // other actions... await browser.close(); })(); ``` ### page.emulateTimezone(timezoneId) * `timezoneId` <?[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Changes the timezone of the page. See [ICU’s `metaZones.txt`](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1) for a list of supported timezone IDs. Passing `null` disables timezone emulation. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> ### page.emulateVisionDeficiency(type) * `type` <?[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Simulates the given vision deficiency on the page. Supported vision deficiency types are `'achromatopsia'`, `'deuteranopia'`, `'protanopia'`, `'tritanopia'`, `'blurredVision'`, and `'none'`. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> ``` const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto('https://v8.dev/blog/10-years'); await page.emulateVisionDeficiency('achromatopsia'); await page.screenshot({ path: 'achromatopsia.png' }); await page.emulateVisionDeficiency('deuteranopia'); await page.screenshot({ path: 'deuteranopia.png' }); await page.emulateVisionDeficiency('blurredVision'); await page.screenshot({ path: 'blurred-vision.png' }); await browser.close(); })(); ``` ### page.evaluate(pageFunction[, ...args]) * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")|[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Function to be evaluated in the page context * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")>> Promise which resolves to the return value of `pageFunction` If the function passed to the `page.evaluate` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `page.evaluate` would wait for the promise to resolve and return its value. If the function passed to the `page.evaluate` returns a non-[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable") value, then `page.evaluate` resolves to `undefined`. DevTools Protocol also supports transferring some additional values that are not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`, and bigint literals. Passing arguments to `pageFunction`: ``` const result = await page.evaluate(x => { return Promise.resolve(8 * x); }, 7); console.log(result); // prints "56" ``` A string can also be passed in instead of a function: ``` console.log(await page.evaluate('1 + 2')); // prints "3" const x = 10; console.log(await page.evaluate(`1 + ${x}`)); // prints "11" ``` [ElementHandle](#class-elementhandle "ElementHandle") instances can be passed as arguments to the `page.evaluate`: ``` const bodyHandle = await page.$('body'); const html = await page.evaluate(body => body.innerHTML, bodyHandle); await bodyHandle.dispose(); ``` Shortcut for [page.mainFrame().evaluate(pageFunction, ...args)](#frameevaluatepagefunction-args). ### page.evaluateHandle(pageFunction[, ...args]) * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")|[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Function to be evaluated in the page context * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[JSHandle](#class-jshandle "JSHandle")|[ElementHandle](#class-elementhandle "ElementHandle")>> Promise which resolves to the return value of `pageFunction` as an in-page object. The only difference between `page.evaluate` and `page.evaluateHandle` is that `page.evaluateHandle` returns in-page object (JSHandle). If the function passed to the `page.evaluateHandle` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `page.evaluateHandle` would wait for the promise to resolve and return its value. A string can also be passed in instead of a function: ``` const aHandle = await page.evaluateHandle('document'); // Handle for the 'document' ``` [JSHandle](#class-jshandle "JSHandle") instances can be passed as arguments to the `page.evaluateHandle`: ``` const aHandle = await page.evaluateHandle(() => document.body); const resultHandle = await page.evaluateHandle(body => body.innerHTML, aHandle); console.log(await resultHandle.jsonValue()); await resultHandle.dispose(); ``` This function will return a [JSHandle](#class-jshandle "JSHandle") by default, however if your `pageFunction` returns an HTML element you will get back an `ElementHandle`: ``` const button = await page.evaluateHandle(() => document.querySelector('button')) // button is an ElementHandle, so you can call methods such as click: await button.click(); ``` Shortcut for [page.mainFrame().executionContext().evaluateHandle(pageFunction, ...args)](#executioncontextevaluatehandlepagefunction-args). ### page.evaluateOnNewDocument(pageFunction[, ...args]) * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")|[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Function to be evaluated in browser context * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Adds a function which would be invoked in one of the following scenarios: * whenever the page is navigated * whenever the child frame is attached or navigated. In this case, the function is invoked in the context of the newly attached frame The function is invoked after the document was created but before any of its scripts were run. This is useful to amend the JavaScript environment, e.g. to seed `Math.random`. An example of overriding the navigator.languages property before the page loads: ``` // preload.js // overwrite the `languages` property to use a custom getter Object.defineProperty(navigator, "languages", { get: function() { return ["en-US", "en", "bn"]; } }); // In your puppeteer script, assuming the preload.js file is in same folder of our script const preloadFile = fs.readFileSync('./preload.js', 'utf8'); await page.evaluateOnNewDocument(preloadFile); ``` ### page.exposeFunction(name, puppeteerFunction) * `name` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Name of the function on the window object * `puppeteerFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")> Callback function which will be called in Puppeteer's context. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> The method adds a function called `name` on the page's `window` object. When called, the function executes `puppeteerFunction` in node.js and returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise") which resolves to the return value of `puppeteerFunction`. If the `puppeteerFunction` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), it will be awaited. > **NOTE** Functions installed via `page.exposeFunction` survive navigations. > > An example of adding an `md5` function into the page: ``` const puppeteer = require('puppeteer'); const crypto = require('crypto'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); page.on('console', msg => console.log(msg.text())); await page.exposeFunction('md5', text => crypto.createHash('md5').update(text).digest('hex') ); await page.evaluate(async () => { // use window.md5 to compute hashes const myString = 'PUPPETEER'; const myHash = await window.md5(myString); console.log(`md5 of ${myString} is ${myHash}`); }); await browser.close(); })(); ``` An example of adding a `window.readfile` function into the page: ``` const puppeteer = require('puppeteer'); const fs = require('fs'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); page.on('console', msg => console.log(msg.text())); await page.exposeFunction('readfile', async filePath => { return new Promise((resolve, reject) => { fs.readFile(filePath, 'utf8', (err, text) => { if (err) reject(err); else resolve(text); }); }); }); await page.evaluate(async () => { // use window.readfile to read contents of a file const content = await window.readfile('/etc/hosts'); console.log(content); }); await browser.close(); })(); ``` ### page.focus(selector) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") of an element to focus. If there are multiple elements satisfying the selector, the first will be focused. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves when the element matching `selector` is successfully focused. The promise will be rejected if there is no element matching `selector`. This method fetches an element with `selector` and focuses it. If there's no element matching `selector`, the method throws an error. Shortcut for [page.mainFrame().focus(selector)](#framefocusselector). ### page.frames() * returns: <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Frame](#class-frame "Frame")>> An array of all frames attached to the page. ### page.goBack([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Navigation parameters which might have the following properties: + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. + `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: - `load` - consider navigation to be finished when the `load` event is fired. - `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. - `networkidle2` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[HTTPResponse](#class-httpresponse "HTTPResponse")>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. If can not go back, resolves to `null`. Navigate to the previous page in history. ### page.goForward([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Navigation parameters which might have the following properties: + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. + `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: - `load` - consider navigation to be finished when the `load` event is fired. - `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. - `networkidle2` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[HTTPResponse](#class-httpresponse "HTTPResponse")>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. If can not go forward, resolves to `null`. Navigate to the next page in history. ### page.goto(url[, options]) * `url` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> URL to navigate page to. The url should include scheme, e.g. `https://`. * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Navigation parameters which might have the following properties: + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. + `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: - `load` - consider navigation to be finished when the `load` event is fired. - `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. - `networkidle2` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms. + `referer` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Referer header value. If provided it will take preference over the referer header value set by [page.setExtraHTTPHeaders()](#pagesetextrahttpheadersheaders). * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[HTTPResponse](#class-httpresponse "HTTPResponse")>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. `page.goto` will throw an error if: * there's an SSL error (e.g. in case of self-signed certificates). * target URL is invalid. * the `timeout` is exceeded during navigation. * the remote server does not respond or is unreachable. * the main resource failed to load. `page.goto` will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling [response.status()](#httpresponsestatus). > **NOTE** `page.goto` either throws an error or returns a main resource response. The only exceptions are navigation to `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`. > > > **NOTE** Headless mode doesn't support navigation to a PDF document. See the [upstream issue](https://bugs.chromium.org/p/chromium/issues/detail?id=761295). > > Shortcut for [page.mainFrame().goto(url, options)](#framegotourl-options) ### page.hover(selector) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to search for element to hover. If there are multiple elements satisfying the selector, the first will be hovered. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves when the element matching `selector` is successfully hovered. Promise gets rejected if there's no element matching `selector`. This method fetches an element with `selector`, scrolls it into view if needed, and then uses [page.mouse](#pagemouse) to hover over the center of the element. If there's no element matching `selector`, the method throws an error. Shortcut for [page.mainFrame().hover(selector)](#framehoverselector). ### page.isClosed() * returns: <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Indicates that the page has been closed. ### page.isJavaScriptEnabled() * returns: <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Returns `true` if the page has JavaScript enabled, `false` otherwise. ### page.keyboard * returns: <[Keyboard](#class-keyboard "Keyboard")> ### page.mainFrame() * returns: <[Frame](#class-frame "Frame")> The page's main frame. Page is guaranteed to have a main frame which persists during navigations. ### page.metrics() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> Object containing metrics as key/value pairs. + `Timestamp` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> The timestamp when the metrics sample was taken. + `Documents` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Number of documents in the page. + `Frames` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Number of frames in the page. + `JSEventListeners` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Number of events in the page. + `Nodes` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Number of DOM nodes in the page. + `LayoutCount` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Total number of full or partial page layout. + `RecalcStyleCount` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Total number of page style recalculations. + `LayoutDuration` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Combined durations of all page layouts. + `RecalcStyleDuration` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Combined duration of all page style recalculations. + `ScriptDuration` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Combined duration of JavaScript execution. + `TaskDuration` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Combined duration of all tasks performed by the browser. + `JSHeapUsedSize` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Used JavaScript heap size. + `JSHeapTotalSize` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Total JavaScript heap size. > **NOTE** All timestamps are in monotonic time: monotonically increasing time in seconds since an arbitrary point in the past. > > ### page.mouse * returns: <[Mouse](#class-mouse "Mouse")> ### page.pdf([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Options object which might have the following properties: + `path` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> The file path to save the PDF to. If `path` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). If no path is provided, the PDF won't be saved to the disk. + `scale` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Scale of the webpage rendering. Defaults to `1`. Scale amount must be between 0.1 and 2. + `displayHeaderFooter` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Display header and footer. Defaults to `false`. + `headerTemplate` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them: - `date` formatted print date - `title` document title - `url` document location - `pageNumber` current page number - `totalPages` total pages in the document + `footerTemplate` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> HTML template for the print footer. Should use the same format as the `headerTemplate`. + `printBackground` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Print background graphics. Defaults to `false`. + `landscape` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Paper orientation. Defaults to `false`. + `pageRanges` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages. + `format` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Paper format. If set, takes priority over `width` or `height` options. Defaults to 'Letter'. + `width` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Paper width, accepts values labeled with units. + `height` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Paper height, accepts values labeled with units. + `margin` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Paper margins, defaults to none. - `top` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Top margin, accepts values labeled with units. - `right` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Right margin, accepts values labeled with units. - `bottom` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Bottom margin, accepts values labeled with units. - `left` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Left margin, accepts values labeled with units. + `preferCSSPageSize` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Give any CSS `@page` size declared in the page priority over what is declared in `width` and `height` or `format` options. Defaults to `false`, which will scale the content to fit the paper size. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Buffer](https://nodejs.org/api/buffer.html#buffer_class_buffer "Buffer")>> Promise which resolves with PDF buffer. > **NOTE** Generating a pdf is currently only supported in Chrome headless. > > `page.pdf()` generates a pdf of the page with `print` css media. To generate a pdf with `screen` media, call [page.emulateMediaType('screen')](#pageemulatemediatypetype) before calling `page.pdf()`: > **NOTE** By default, `page.pdf()` generates a pdf with modified colors for printing. Use the [`-webkit-print-color-adjust`](https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-print-color-adjust) property to force rendering of exact colors. > > ``` // Generates a PDF with 'screen' media type. await page.emulateMediaType('screen'); await page.pdf({path: 'page.pdf'}); ``` The `width`, `height`, and `margin` options accept values labeled with units. Unlabeled values are treated as pixels. A few examples: * `page.pdf({width: 100})` - prints with width set to 100 pixels * `page.pdf({width: '100px'})` - prints with width set to 100 pixels * `page.pdf({width: '10cm'})` - prints with width set to 10 centimeters. All possible units are: * `px` - pixel * `in` - inch * `cm` - centimeter * `mm` - millimeter The `format` options are: * `Letter`: 8.5in x 11in * `Legal`: 8.5in x 14in * `Tabloid`: 11in x 17in * `Ledger`: 17in x 11in * `A0`: 33.1in x 46.8in * `A1`: 23.4in x 33.1in * `A2`: 16.54in x 23.4in * `A3`: 11.7in x 16.54in * `A4`: 8.27in x 11.7in * `A5`: 5.83in x 8.27in * `A6`: 4.13in x 5.83in > **NOTE** `headerTemplate` and `footerTemplate` markup have the following limitations: > > 1. Script tags inside templates are not evaluated. > 2. Page styles are not visible inside templates. > > ### page.queryObjects(prototypeHandle) * `prototypeHandle` <[JSHandle](#class-jshandle "JSHandle")> A handle to the object prototype. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[JSHandle](#class-jshandle "JSHandle")>> Promise which resolves to a handle to an array of objects with this prototype. The method iterates the JavaScript heap and finds all the objects with the given prototype. ``` // Create a Map object await page.evaluate(() => window.map = new Map()); // Get a handle to the Map object prototype const mapPrototype = await page.evaluateHandle(() => Map.prototype); // Query all map instances into an array const mapInstances = await page.queryObjects(mapPrototype); // Count amount of map objects in heap const count = await page.evaluate(maps => maps.length, mapInstances); await mapInstances.dispose(); await mapPrototype.dispose(); ``` Shortcut for [page.mainFrame().executionContext().queryObjects(prototypeHandle)](#executioncontextqueryobjectsprototypehandle). ### page.reload([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Navigation parameters which might have the following properties: + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. + `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: - `load` - consider navigation to be finished when the `load` event is fired. - `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. - `networkidle2` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[HTTPResponse](#class-httpresponse "HTTPResponse")>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. ### page.screenshot([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Options object which might have the following properties: + `path` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> The file path to save the image to. The screenshot type will be inferred from file extension. If `path` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). If no path is provided, the image won't be saved to the disk. + `type` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Specify screenshot type, can be either `jpeg` or `png`. Defaults to 'png'. + `quality` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> The quality of the image, between 0-100. Not applicable to `png` images. + `fullPage` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> When true, takes a screenshot of the full scrollable page. Defaults to `false`. + `clip` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> An object which specifies clipping region of the page. Should have the following fields: - `x` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> x-coordinate of top-left corner of clip area - `y` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> y-coordinate of top-left corner of clip area - `width` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> width of clipping area - `height` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> height of clipping area + `omitBackground` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Hides default white background and allows capturing screenshots with transparency. Defaults to `false`. + `encoding` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> The encoding of the image, can be either `base64` or `binary`. Defaults to `binary`. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[Buffer](https://nodejs.org/api/buffer.html#buffer_class_buffer "Buffer")>> Promise which resolves to buffer or a base64 string (depending on the value of `encoding`) with captured screenshot. > **NOTE** Screenshots take at least 1/6 second on OS X. See <https://crbug.com/741689> for discussion. > > ### page.select(selector, ...values) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to query page for * `...values` <...[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Values of options to select. If the `<select>` has the `multiple` attribute, all values are considered, otherwise only the first one is taken into account. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>>> An array of option values that have been successfully selected. Triggers a `change` and `input` event once all the provided options have been selected. If there's no `<select>` element matching `selector`, the method throws an error. ``` page.select('select#colors', 'blue'); // single selection page.select('select#colors', 'red', 'green', 'blue'); // multiple selections ``` Shortcut for [page.mainFrame().select()](#frameselectselector-values) ### page.setBypassCSP(enabled) * `enabled` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> sets bypassing of page's Content-Security-Policy. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Toggles bypassing page's Content-Security-Policy. > **NOTE** CSP bypassing happens at the moment of CSP initialization rather then evaluation. Usually this means that `page.setBypassCSP` should be called before navigating to the domain. > > ### page.setCacheEnabled([enabled]) * `enabled` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> sets the `enabled` state of the cache. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Toggles ignoring cache for each request based on the enabled state. By default, caching is enabled. ### page.setContent(html[, options]) * `html` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> HTML markup to assign to the page. * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Parameters which might have the following properties: + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Maximum time in milliseconds for resources to load, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. + `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider setting markup succeeded, defaults to `load`. Given an array of event strings, setting content is considered to be successful after all events have been fired. Events can be either: - `load` - consider setting content to be finished when the `load` event is fired. - `domcontentloaded` - consider setting content to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider setting content to be finished when there are no more than 0 network connections for at least `500` ms. - `networkidle2` - consider setting content to be finished when there are no more than 2 network connections for at least `500` ms. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> ### page.setCookie(...cookies) * `...cookies` <...[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `name` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> **required** + `value` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> **required** + `url` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> + `domain` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> + `path` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> + `expires` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Unix time in seconds. + `httpOnly` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> + `secure` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> + `sameSite` <"Strict"|"Lax"> * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> ``` await page.setCookie(cookieObject1, cookieObject2); ``` ### page.setDefaultNavigationTimeout(timeout) * `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Maximum navigation time in milliseconds This setting will change the default maximum navigation time for the following methods and related shortcuts: * [page.goBack([options])](#pagegobackoptions) * [page.goForward([options])](#pagegoforwardoptions) * [page.goto(url[, options])](#pagegotourl-options) * [page.reload([options])](#pagereloadoptions) * [page.setContent(html[, options])](#pagesetcontenthtml-options) * [page.waitForNavigation([options])](#pagewaitfornavigationoptions) > **NOTE** [`page.setDefaultNavigationTimeout`](#pagesetdefaultnavigationtimeouttimeout) takes priority over [`page.setDefaultTimeout`](#pagesetdefaulttimeouttimeout) > > ### page.setDefaultTimeout(timeout) * `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Maximum time in milliseconds This setting will change the default maximum time for the following methods and related shortcuts: * [page.goBack([options])](#pagegobackoptions) * [page.goForward([options])](#pagegoforwardoptions) * [page.goto(url[, options])](#pagegotourl-options) * [page.reload([options])](#pagereloadoptions) * [page.setContent(html[, options])](#pagesetcontenthtml-options) * [page.waitFor(selectorOrFunctionOrTimeout[, options[, ...args]])](#pagewaitforselectororfunctionortimeout-options-args) * [page.waitForFileChooser([options])](#pagewaitforfilechooseroptions) * [page.waitForFunction(pageFunction[, options[, ...args]])](#pagewaitforfunctionpagefunction-options-args) * [page.waitForNavigation([options])](#pagewaitfornavigationoptions) * [page.waitForRequest(urlOrPredicate[, options])](#pagewaitforrequesturlorpredicate-options) * [page.waitForResponse(urlOrPredicate[, options])](#pagewaitforresponseurlorpredicate-options) * [page.waitForSelector(selector[, options])](#pagewaitforselectorselector-options) * [page.waitForXPath(xpath[, options])](#pagewaitforxpathxpath-options) > **NOTE** [`page.setDefaultNavigationTimeout`](#pagesetdefaultnavigationtimeouttimeout) takes priority over [`page.setDefaultTimeout`](#pagesetdefaulttimeouttimeout) > > ### page.setExtraHTTPHeaders(headers) * `headers` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> An object containing additional HTTP headers to be sent with every request. All header values must be strings. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> The extra HTTP headers will be sent with every request the page initiates. > **NOTE** page.setExtraHTTPHeaders does not guarantee the order of headers in the outgoing requests. > > ### page.setGeolocation(options) * `options` <[GeolocationOptions](#geolocationoptions)> * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Sets the page's geolocation. ``` await page.setGeolocation({latitude: 59.95, longitude: 30.31667}); ``` > **NOTE** Consider using [browserContext.overridePermissions](#browsercontextoverridepermissionsorigin-permissions) to grant permissions for the page to read its geolocation. > > ### page.setJavaScriptEnabled(enabled) * `enabled` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether or not to enable JavaScript on the page. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> > **NOTE** changing this value won't affect scripts that have already been run. It will take full effect on the next [navigation](#pagegotourl-options). > > ### page.setOfflineMode(enabled) * `enabled` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> When `true`, enables offline mode for the page. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> ### page.setRequestInterception(value) * `value` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether to enable request interception. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Activating request interception enables `request.abort`, `request.continue` and `request.respond` methods. This provides the capability to modify network requests that are made by a page. Once request interception is enabled, every request will stall unless it's continued, responded or aborted. An example of a naïve request interceptor that aborts all image requests: ``` const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setRequestInterception(true); page.on('request', interceptedRequest => { if (interceptedRequest.url().endsWith('.png') || interceptedRequest.url().endsWith('.jpg')) interceptedRequest.abort(); else interceptedRequest.continue(); }); await page.goto('https://example.com'); await browser.close(); })(); ``` > **NOTE** Enabling request interception disables page caching. > > ### page.setUserAgent(userAgent) * `userAgent` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Specific user agent to use in this page * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves when the user agent is set. ### page.setViewport(viewport) * `viewport` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `width` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> page width in pixels. **required** + `height` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> page height in pixels. **required** + `deviceScaleFactor` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Specify device scale factor (can be thought of as dpr). Defaults to `1`. + `isMobile` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether the `meta viewport` tag is taken into account. Defaults to `false`. + `hasTouch`<[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Specifies if viewport supports touch events. Defaults to `false` + `isLandscape` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Specifies if viewport is in landscape mode. Defaults to `false`. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> > **NOTE** in certain cases, setting viewport will reload the page in order to set the `isMobile` or `hasTouch` properties. > > In the case of multiple pages in a single browser, each page can have its own viewport size. `page.setViewport` will resize the page. A lot of websites don't expect phones to change size, so you should set the viewport before navigating to the page. ``` const page = await browser.newPage(); await page.setViewport({ width: 640, height: 480, deviceScaleFactor: 1, }); await page.goto('https://example.com'); ``` ### page.tap(selector) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to search for element to tap. If there are multiple elements satisfying the selector, the first will be tapped. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> This method fetches an element with `selector`, scrolls it into view if needed, and then uses [page.touchscreen](#pagetouchscreen) to tap in the center of the element. If there's no element matching `selector`, the method throws an error. Shortcut for [page.mainFrame().tap(selector)](#frametapselector). ### page.target() * returns: <[Target](#class-target "Target")> a target this page was created from. ### page.title() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>> The page's title. Shortcut for [page.mainFrame().title()](#frametitle). ### page.touchscreen * returns: <[Touchscreen](#class-touchscreen "Touchscreen")> ### page.tracing * returns: <[Tracing](#class-tracing "Tracing")> ### page.type(selector, text[, options]) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") of an element to type into. If there are multiple elements satisfying the selector, the first will be used. * `text` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A text to type into a focused element. * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `delay` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Time to wait between key presses in milliseconds. Defaults to 0. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. To press a special key, like `Control` or `ArrowDown`, use [`keyboard.press`](#keyboardpresskey-options). ``` await page.type('#mytextarea', 'Hello'); // Types instantly await page.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a user ``` Shortcut for [page.mainFrame().type(selector, text[, options])](#frametypeselector-text-options). ### page.url() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> This is a shortcut for [page.mainFrame().url()](#frameurl) ### page.viewport() * returns: <?[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `width` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> page width in pixels. + `height` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> page height in pixels. + `deviceScaleFactor` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Specify device scale factor (can be though of as dpr). Defaults to `1`. + `isMobile` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether the `meta viewport` tag is taken into account. Defaults to `false`. + `hasTouch`<[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Specifies if viewport supports touch events. Defaults to `false` + `isLandscape` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Specifies if viewport is in landscape mode. Defaults to `false`. ### page.waitFor(selectorOrFunctionOrTimeout[, options[, ...args]]) * `selectorOrFunctionOrTimeout` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")|[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector"), predicate or timeout to wait for * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Optional waiting parameters + `visible` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> wait for element to be present in DOM and to be visible. Defaults to `false`. + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) method. + `hidden` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> wait for element to not be found in the DOM or to be hidden. Defaults to `false`. + `polling` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> An interval at which the `pageFunction` is executed, defaults to `raf`. If `polling` is a number, then it is treated as an interval in milliseconds at which the function would be executed. If `polling` is a string, then it can be one of the following values: - `raf` - to constantly execute `pageFunction` in `requestAnimationFrame` callback. This is the tightest polling mode which is suitable to observe styling changes. - `mutation` - to execute `pageFunction` on every DOM mutation. * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[JSHandle](#class-jshandle "JSHandle")>> Promise which resolves to a JSHandle of the success value **This method is deprecated**. You should use the more explicit API methods available: * `page.waitForSelector` * `page.waitForXPath` * `page.waitForFunction` * `page.waitForTimeout` This method behaves differently with respect to the type of the first parameter: * if `selectorOrFunctionOrTimeout` is a `string`, then the first argument is treated as a [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") or [xpath](https://developer.mozilla.org/en-US/docs/Web/XPath "xpath"), depending on whether or not it starts with '//', and the method is a shortcut for [page.waitForSelector](#pagewaitforselectorselector-options) or [page.waitForXPath](#pagewaitforxpathxpath-options) * if `selectorOrFunctionOrTimeout` is a `function`, then the first argument is treated as a predicate to wait for and the method is a shortcut for [page.waitForFunction()](#pagewaitforfunctionpagefunction-options-args). * if `selectorOrFunctionOrTimeout` is a `number`, then the first argument is treated as a timeout in milliseconds and the method returns a promise which resolves after the timeout * otherwise, an exception is thrown ``` // wait for selector await page.waitFor('.foo'); // wait for 1 second await page.waitFor(1000); // wait for predicate await page.waitFor(() => !!document.querySelector('.foo')); ``` To pass arguments from node.js to the predicate of `page.waitFor` function: ``` const selector = '.foo'; await page.waitFor(selector => !!document.querySelector(selector), {}, selector); ``` Shortcut for [page.mainFrame().waitFor(selectorOrFunctionOrTimeout[, options[, ...args]])](#framewaitforselectororfunctionortimeout-options-args). ### page.waitForFileChooser([options]) * `options` <[WaitTimeoutOptions](####WaitTimeoutOptions)> Optional waiting parameters * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[FileChooser](#class-filechooser "FileChooser")>> A promise that resolves after a page requests a file picker. > **NOTE** In non-headless Chromium, this method results in the native file picker dialog **not showing up** for the user. > > This method is typically coupled with an action that triggers file choosing. The following example clicks a button that issues a file chooser, and then responds with `/tmp/myfile.pdf` as if a user has selected this file. ``` const [fileChooser] = await Promise.all([ page.waitForFileChooser(), page.click('#upload-file-button'), // some button that triggers file selection ]); await fileChooser.accept(['/tmp/myfile.pdf']); ``` > **NOTE** This must be called *before* the file chooser is launched. It will not return a currently active file chooser. > > ### page.waitForFunction(pageFunction[, options[, ...args]]) * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")|[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Function to be evaluated in browser context * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Optional waiting parameters + `polling` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> An interval at which the `pageFunction` is executed, defaults to `raf`. If `polling` is a number, then it is treated as an interval in milliseconds at which the function would be executed. If `polling` is a string, then it can be one of the following values: - `raf` - to constantly execute `pageFunction` in `requestAnimationFrame` callback. This is the tightest polling mode which is suitable to observe styling changes. - `mutation` - to execute `pageFunction` on every DOM mutation. + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) method. * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[JSHandle](#class-jshandle "JSHandle")>> Promise which resolves when the `pageFunction` returns a truthy value. It resolves to a JSHandle of the truthy value. The `waitForFunction` can be used to observe viewport size change: ``` const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); const watchDog = page.waitForFunction('window.innerWidth < 100'); await page.setViewport({width: 50, height: 50}); await watchDog; await browser.close(); })(); ``` To pass arguments from node.js to the predicate of `page.waitForFunction` function: ``` const selector = '.foo'; await page.waitForFunction(selector => !!document.querySelector(selector), {}, selector); ``` The predicate of `page.waitForFunction` can be asynchronous too: ``` const username = 'github-username'; await page.waitForFunction(async username => { const githubResponse = await fetch(`https://api.github.com/users/${username}`); const githubUser = await githubResponse.json(); // show the avatar const img = document.createElement('img'); img.src = githubUser.avatar_url; // wait 3 seconds await new Promise((resolve, reject) => setTimeout(resolve, 3000)); img.remove(); }, {}, username); ``` Shortcut for [page.mainFrame().waitForFunction(pageFunction[, options[, ...args]])](#framewaitforfunctionpagefunction-options-args). ### page.waitForNavigation([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Navigation parameters which might have the following properties: + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. + `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: - `load` - consider navigation to be finished when the `load` event is fired. - `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. - `networkidle2` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[HTTPResponse](#class-httpresponse "HTTPResponse")>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to History API usage, the navigation will resolve with `null`. This resolves when the page navigates to a new URL or reloads. It is useful for when you run code which will indirectly cause the page to navigate. Consider this example: ``` const [response] = await Promise.all([ page.waitForNavigation(), // The promise resolves after navigation has finished page.click('a.my-link'), // Clicking the link will indirectly cause a navigation ]); ``` **NOTE** Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is considered a navigation. Shortcut for [page.mainFrame().waitForNavigation(options)](#framewaitfornavigationoptions). ### page.waitForRequest(urlOrPredicate[, options]) * `urlOrPredicate` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")> A URL or predicate to wait for. * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Optional waiting parameters + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) method. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[HTTPRequest](#class-httprequest "HTTPRequest")>> Promise which resolves to the matched request. ``` const firstRequest = await page.waitForRequest('http://example.com/resource'); const finalRequest = await page.waitForRequest(request => request.url() === 'http://example.com' && request.method() === 'GET'); return firstRequest.url(); ``` ### page.waitForResponse(urlOrPredicate[, options]) * `urlOrPredicate` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")> A URL or predicate to wait for. * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Optional waiting parameters + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) method. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[HTTPResponse](#class-httpresponse "HTTPResponse")>> Promise which resolves to the matched response. ``` const firstResponse = await page.waitForResponse('https://example.com/resource'); const finalResponse = await page.waitForResponse(response => response.url() === 'https://example.com' && response.status() === 200); const finalResponse = await page.waitForResponse(async response => { return (await response.text()).includes('<html>') }) return finalResponse.ok(); ``` ### page.waitForSelector(selector[, options]) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") of an element to wait for * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Optional waiting parameters + `visible` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> wait for element to be present in DOM and to be visible, i.e. to not have `display: none` or `visibility: hidden` CSS properties. Defaults to `false`. + `hidden` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> wait for element to not be found in the DOM or to be hidden, i.e. have `display: none` or `visibility: hidden` CSS properties. Defaults to `false`. + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) method. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[ElementHandle](#class-elementhandle "ElementHandle")>> Promise which resolves when element specified by selector string is added to DOM. Resolves to `null` if waiting for `hidden: true` and selector is not found in DOM. Wait for the `selector` to appear in page. If at the moment of calling the method the `selector` already exists, the method will return immediately. If the selector doesn't appear after the `timeout` milliseconds of waiting, the function will throw. This method works across navigations: ``` const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); let currentURL; page .waitForSelector('img') .then(() => console.log('First URL with image: ' + currentURL)); for (currentURL of ['https://example.com', 'https://google.com', 'https://bbc.com']) { await page.goto(currentURL); } await browser.close(); })(); ``` Shortcut for [page.mainFrame().waitForSelector(selector[, options])](#framewaitforselectorselector-options). ### page.waitForTimeout(milliseconds) * `milliseconds` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> The number of milliseconds to wait for. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves after the timeout has completed. Pauses script execution for the given number of milliseconds before continuing: ``` const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); page.waitForTimeout(1000) .then(() => console.log('Waited a second!')); await browser.close(); })(); ``` ### page.waitForXPath(xpath[, options]) * `xpath` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [xpath](https://developer.mozilla.org/en-US/docs/Web/XPath "xpath") of an element to wait for * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Optional waiting parameters + `visible` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> wait for element to be present in DOM and to be visible, i.e. to not have `display: none` or `visibility: hidden` CSS properties. Defaults to `false`. + `hidden` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> wait for element to not be found in the DOM or to be hidden, i.e. have `display: none` or `visibility: hidden` CSS properties. Defaults to `false`. + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) method. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[ElementHandle](#class-elementhandle "ElementHandle")>> Promise which resolves when element specified by xpath string is added to DOM. Resolves to `null` if waiting for `hidden: true` and xpath is not found in DOM. Wait for the `xpath` to appear in page. If at the moment of calling the method the `xpath` already exists, the method will return immediately. If the xpath doesn't appear after the `timeout` milliseconds of waiting, the function will throw. This method works across navigations: ``` const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); let currentURL; page .waitForXPath('//img') .then(() => console.log('First URL with image: ' + currentURL)); for (currentURL of ['https://example.com', 'https://google.com', 'https://bbc.com']) { await page.goto(currentURL); } await browser.close(); })(); ``` Shortcut for [page.mainFrame().waitForXPath(xpath[, options])](#framewaitforxpathxpath-options). ### page.workers() * returns: <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[WebWorker](#class-webworker "Worker")>> This method returns all of the dedicated [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) associated with the page. > **NOTE** This does not contain ServiceWorkers > > ### GeolocationOptions * `latitude` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Latitude between -90 and 90. * `longitude` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Longitude between -180 and 180. * `accuracy` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Optional non-negative accuracy value. ### WaitTimeoutOptions * `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) method. class: WebWorker ---------------- The WebWorker class represents a [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API). The events `workercreated` and `workerdestroyed` are emitted on the page object to signal the worker lifecycle. ``` page.on('workercreated', worker => console.log('Worker created: ' + worker.url())); page.on('workerdestroyed', worker => console.log('Worker destroyed: ' + worker.url())); console.log('Current workers:'); for (const worker of page.workers()) console.log(' ' + worker.url()); ``` ### webWorker.evaluate(pageFunction[, ...args]) * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")|[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Function to be evaluated in the worker context * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")>> Promise which resolves to the return value of `pageFunction` If the function passed to the `worker.evaluate` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `worker.evaluate` would wait for the promise to resolve and return its value. If the function passed to the `worker.evaluate` returns a non-[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable") value, then `worker.evaluate` resolves to `undefined`. DevTools Protocol also supports transferring some additional values that are not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`, and bigint literals. Shortcut for [(await worker.executionContext()).evaluate(pageFunction, ...args)](#executioncontextevaluatepagefunction-args). ### webWorker.evaluateHandle(pageFunction[, ...args]) * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")|[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Function to be evaluated in the page context * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[JSHandle](#class-jshandle "JSHandle")|[ElementHandle](#class-elementhandle "ElementHandle")>> Promise which resolves to the return value of `pageFunction` as an in-page object. The only difference between `worker.evaluate` and `worker.evaluateHandle` is that `worker.evaluateHandle` returns in-page object (JSHandle). If the function passed to the `worker.evaluateHandle` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `worker.evaluateHandle` would wait for the promise to resolve and return its value. If the function returns an element, the returned handle is an [ElementHandle](#class-elementhandle "ElementHandle"). Shortcut for [(await worker.executionContext()).evaluateHandle(pageFunction, ...args)](#executioncontextevaluatehandlepagefunction-args). ### webWorker.executionContext() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[ExecutionContext](#class-executioncontext "ExecutionContext")>> ### webWorker.url() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> class: Accessibility -------------------- The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or [switches](https://en.wikipedia.org/wiki/Switch_access). Accessibility is a very platform-specific thing. On different platforms, there are different screen readers that might have wildly different output. Blink - Chrome's rendering engine - has a concept of "accessibility tree", which is then translated into different platform-specific APIs. Accessibility namespace gives users access to the Blink Accessibility Tree. Most of the accessibility tree gets filtered out when converting from Blink AX Tree to Platform-specific AX-Tree or by assistive technologies themselves. By default, Puppeteer tries to approximate this filtering, exposing only the "interesting" nodes of the tree. ### accessibility.snapshot([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `interestingOnly` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Prune uninteresting nodes from the tree. Defaults to `true`. + `root` <[ElementHandle](#class-elementhandle "ElementHandle")> The root DOM element for the snapshot. Defaults to the whole page. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> An [AXNode](#accessibilitysnapshotoptions "AXNode") object with the following properties: + `role` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> The [role](https://www.w3.org/TR/wai-aria/#usage_intro). + `name` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A human readable name for the node. + `value` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> The current value of the node. + `description` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> An additional human readable description of the node. + `keyshortcuts` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Keyboard shortcuts associated with this node. + `roledescription` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A human readable alternative to the role. + `valuetext` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A description of the current value. + `disabled` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether the node is disabled. + `expanded` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether the node is expanded or collapsed. + `focused` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether the node is focused. + `modal` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether the node is [modal](https://en.wikipedia.org/wiki/Modal_window). + `multiline` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether the node text input supports multiline. + `multiselectable` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether more than one child can be selected. + `readonly` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether the node is read only. + `required` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether the node is required. + `selected` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether the node is selected in its parent node. + `checked` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")|"mixed"> Whether the checkbox is checked, or "mixed". + `pressed` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")|"mixed"> Whether the toggle button is checked, or "mixed". + `level` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> The level of a heading. + `valuemin` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> The minimum value in a node. + `valuemax` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> The maximum value in a node. + `autocomplete` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> What kind of autocomplete is supported by a control. + `haspopup` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> What kind of popup is currently being shown for a node. + `invalid` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Whether and in what way this node's value is invalid. + `orientation` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Whether the node is oriented horizontally or vertically. + `children` <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> Child [AXNode](#accessibilitysnapshotoptions "AXNode")s of this node, if any. Captures the current state of the accessibility tree. The returned object represents the root accessible node of the page. > **NOTE** The Chromium accessibility tree contains nodes that go unused on most platforms and by most screen readers. Puppeteer will discard them as well for an easier to process tree, unless `interestingOnly` is set to `false`. > > An example of dumping the entire accessibility tree: ``` const snapshot = await page.accessibility.snapshot(); console.log(snapshot); ``` An example of logging the focused node's name: ``` const snapshot = await page.accessibility.snapshot(); const node = findFocusedNode(snapshot); console.log(node && node.name); function findFocusedNode(node) { if (node.focused) return node; for (const child of node.children || []) { const foundNode = findFocusedNode(child); return foundNode; } return null; } ``` class: Keyboard --------------- Keyboard provides an api for managing a virtual keyboard. The high level api is [`keyboard.type`](#keyboardtypetext-options), which takes raw characters and generates proper keydown, keypress/input, and keyup events on your page. For finer control, you can use [`keyboard.down`](#keyboarddownkey-options), [`keyboard.up`](#keyboardupkey), and [`keyboard.sendCharacter`](#keyboardsendcharacterchar) to manually fire events as if they were generated from a real keyboard. An example of holding down `Shift` in order to select and delete some text: ``` await page.keyboard.type('Hello World!'); await page.keyboard.press('ArrowLeft'); await page.keyboard.down('Shift'); for (let i = 0; i < ' World'.length; i++) await page.keyboard.press('ArrowLeft'); await page.keyboard.up('Shift'); await page.keyboard.press('Backspace'); // Result text will end up saying 'Hello!' ``` An example of pressing `A` ``` await page.keyboard.down('Shift'); await page.keyboard.press('KeyA'); await page.keyboard.up('Shift'); ``` > **NOTE** On MacOS, keyboard shortcuts like `⌘ A` -> Select All do not work. See [#1313](https://github.com/puppeteer/puppeteer/issues/1313) > > ### keyboard.down(key[, options]) * `key` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Name of key to press, such as `ArrowLeft`. See [USKeyboardLayout](https://github.com/puppeteer/puppeteer/blob/v7.1.0/src/common/USKeyboardLayout.ts "USKeyboardLayout") for a list of all key names. * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `text` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> If specified, generates an input event with this text. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Dispatches a `keydown` event. If `key` is a single character and no modifier keys besides `Shift` are being held down, a `keypress`/`input` event will also generated. The `text` option can be specified to force an input event to be generated. If `key` is a modifier key, `Shift`, `Meta`, `Control`, or `Alt`, subsequent key presses will be sent with that modifier active. To release the modifier key, use [`keyboard.up`](#keyboardupkey). After the key is pressed once, subsequent calls to [`keyboard.down`](#keyboarddownkey-options) will have [repeat](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat) set to true. To release the key, use [`keyboard.up`](#keyboardupkey). > **NOTE** Modifier keys DO influence `keyboard.down`. Holding down `Shift` will type the text in upper case. > > ### keyboard.press(key[, options]) * `key` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Name of key to press, such as `ArrowLeft`. See [USKeyboardLayout](https://github.com/puppeteer/puppeteer/blob/v7.1.0/src/common/USKeyboardLayout.ts "USKeyboardLayout") for a list of all key names. * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `text` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> If specified, generates an input event with this text. + `delay` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> If `key` is a single character and no modifier keys besides `Shift` are being held down, a `keypress`/`input` event will also generated. The `text` option can be specified to force an input event to be generated. > **NOTE** Modifier keys DO affect `keyboard.press`. Holding down `Shift` will type the text in upper case. > > Shortcut for [`keyboard.down`](#keyboarddownkey-options) and [`keyboard.up`](#keyboardupkey). ### keyboard.sendCharacter(char) * `char` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Character to send into the page. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Dispatches a `keypress` and `input` event. This does not send a `keydown` or `keyup` event. ``` page.keyboard.sendCharacter('嗨'); ``` > **NOTE** Modifier keys DO NOT affect `keyboard.sendCharacter`. Holding down `Shift` will not type the text in upper case. > > ### keyboard.type(text[, options]) * `text` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A text to type into a focused element. * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `delay` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Time to wait between key presses in milliseconds. Defaults to 0. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. To press a special key, like `Control` or `ArrowDown`, use [`keyboard.press`](#keyboardpresskey-options). ``` await page.keyboard.type('Hello'); // Types instantly await page.keyboard.type('World', {delay: 100}); // Types slower, like a user ``` > **NOTE** Modifier keys DO NOT affect `keyboard.type`. Holding down `Shift` will not type the text in upper case. > > ### keyboard.up(key) * `key` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Name of key to release, such as `ArrowLeft`. See [USKeyboardLayout](https://github.com/puppeteer/puppeteer/blob/v7.1.0/src/common/USKeyboardLayout.ts "USKeyboardLayout") for a list of all key names. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Dispatches a `keyup` event. class: Mouse ------------ The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport. Every `page` object has its own Mouse, accessible with [`page.mouse`](#pagemouse). ``` // Using ‘page.mouse’ to trace a 100x100 square. await page.mouse.move(0, 0); await page.mouse.down(); await page.mouse.move(0, 100); await page.mouse.move(100, 100); await page.mouse.move(100, 0); await page.mouse.move(0, 0); await page.mouse.up(); ``` Note that the mouse events trigger synthetic `MouseEvent`s. This means that it does not fully replicate the functionality of what a normal user would be able to do with their mouse. For example, dragging and selecting text is not possible using `page.mouse`. Instead, you can use the [`DocumentOrShadowRoot.getSelection()`](https://developer.mozilla.org/en-US/docs/Web/API/DocumentOrShadowRoot/getSelection) functionality implemented in the platform. For example, if you want to select all content between nodes: ``` await page.evaluate((from, to) => { const selection = from.getRootNode().getSelection(); const range = document.createRange(); range.setStartBefore(from); range.setEndAfter(to); selection.removeAllRanges(); selection.addRange(range); }, fromJSHandle, toJSHandle); ``` If you then would want to copy-paste your selection, you can use the clipboard api: ``` // The clipboard api does not allow you to copy, unless the tab is focused. await page.bringToFront(); await page.evaluate(() => { // Copy the selected content to the clipboard document.execCommand('copy'); // Obtain the content of the clipboard as a string return navigator.clipboard.readText(); }); ``` Note that if you want access to the clipboard API, you have to give it permission to do so: ``` await browser.defaultBrowserContext().overridePermissions('<your origin>', ['clipboard-read', 'clipboard-write']); ``` ### mouse.click(x, y[, options]) * `x` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> * `y` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `button` <"left"|"right"|"middle"> Defaults to `left`. + `clickCount` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> defaults to 1. See [UIEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail"). + `delay` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Shortcut for [`mouse.move`](#mousemovex-y-options), [`mouse.down`](#mousedownoptions) and [`mouse.up`](#mouseupoptions). ### mouse.down([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `button` <"left"|"right"|"middle"> Defaults to `left`. + `clickCount` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> defaults to 1. See [UIEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail"). * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Dispatches a `mousedown` event. ### mouse.move(x, y[, options]) * `x` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> * `y` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `steps` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> defaults to 1. Sends intermediate `mousemove` events. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Dispatches a `mousemove` event. ### mouse.up([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `button` <"left"|"right"|"middle"> Defaults to `left`. + `clickCount` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> defaults to 1. See [UIEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail"). * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Dispatches a `mouseup` event. ### mouse.wheel([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `deltaX` X delta in CSS pixels for mouse wheel event (default: 0). Positive values emulate a scroll right and negative values a scroll left event. + `deltaY` Y delta in CSS pixels for mouse wheel event (default: 0). Positive values emulate a scroll down and negative values a scroll up event. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Dispatches a `mousewheel` event. Examples: ``` await page.goto('https://mdn.mozillademos.org/en-US/docs/Web/API/Element/wheel_event$samples/Scaling_an_element_via_the_wheel?revision=1587366'); const elem = await page.$('div'); const boundingBox = await elem.boundingBox(); await page.mouse.move( boundingBox.x + boundingBox.width / 2, boundingBox.y + boundingBox.height / 2 ); await page.mouse.wheel({ deltaY: -100 }) ``` class: Touchscreen ------------------ ### touchscreen.tap(x, y) * `x` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> * `y` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Dispatches a `touchstart` and `touchend` event. class: Tracing -------------- You can use [`tracing.start`](#tracingstartoptions) and [`tracing.stop`](#tracingstop) to create a trace file which can be opened in Chrome DevTools or [timeline viewer](https://chromedevtools.github.io/timeline-viewer/). ``` await page.tracing.start({path: 'trace.json'}); await page.goto('https://www.google.com'); await page.tracing.stop(); ``` ### tracing.start([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `path` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A path to write the trace file to. + `screenshots` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> captures screenshots in the trace. + `categories` <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>> specify custom categories to use instead of default. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Only one trace can be active at a time per browser. ### tracing.stop() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Buffer](https://nodejs.org/api/buffer.html#buffer_class_buffer "Buffer")>> Promise which resolves to buffer with trace data. class: FileChooser ------------------ [FileChooser](#class-filechooser "FileChooser") objects are returned via the ['page.waitForFileChooser'](#pagewaitforfilechooseroptions) method. File choosers let you react to the page requesting for a file. An example of using [FileChooser](#class-filechooser "FileChooser"): ``` const [fileChooser] = await Promise.all([ page.waitForFileChooser(), page.click('#upload-file-button'), // some button that triggers file selection ]); await fileChooser.accept(['/tmp/myfile.pdf']); ``` > **NOTE** In browsers, only one file chooser can be opened at a time. All file choosers must be accepted or canceled. Not doing so will prevent subsequent file choosers from appearing. > > ### fileChooser.accept(filePaths) * `filePaths` <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>> Accept the file chooser request with given paths. If some of the `filePaths` are relative paths, then they are resolved relative to the [current working directory](https://nodejs.org/api/process.html#process_process_cwd). * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> ### fileChooser.cancel() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Closes the file chooser without selecting any files. ### fileChooser.isMultiple() * returns: <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether file chooser allow for [multiple](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#attr-multiple) file selection. class: Dialog ------------- [Dialog](#class-dialog "Dialog") objects are dispatched by page via the ['dialog'](#event-dialog) event. An example of using `Dialog` class: ``` const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); page.on('dialog', async dialog => { console.log(dialog.message()); await dialog.dismiss(); await browser.close(); }); page.evaluate(() => alert('1')); })(); ``` ### dialog.accept([promptText]) * `promptText` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A text to enter in prompt. Does not cause any effects if the dialog's `type` is not prompt. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves when the dialog has been accepted. ### dialog.defaultValue() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> If dialog is prompt, returns default prompt value. Otherwise, returns empty string. ### dialog.dismiss() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves when the dialog has been dismissed. ### dialog.message() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A message displayed in the dialog. ### dialog.type() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Dialog's type, can be one of `alert`, `beforeunload`, `confirm` or `prompt`. class: ConsoleMessage --------------------- [ConsoleMessage](#class-consolemessage "ConsoleMessage") objects are dispatched by page via the ['console'](#event-console) event. ### consoleMessage.args() * returns: <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[JSHandle](#class-jshandle "JSHandle")>> ### consoleMessage.location() * returns: <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `url` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> URL of the resource if known or `undefined` otherwise. + `lineNumber` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> 0-based line number in the resource if known or `undefined` otherwise. + `columnNumber` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> 0-based column number in the resource if known or `undefined` otherwise. ### consoleMessage.stackTrace() * returns: <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> + `url` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> URL of the resource if known or `undefined` otherwise. + `lineNumber` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> 0-based line number in the resource if known or `undefined` otherwise. + `columnNumber` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> 0-based column number in the resource if known or `undefined` otherwise. ### consoleMessage.text() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> ### consoleMessage.type() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> One of the following values: `'log'`, `'debug'`, `'info'`, `'error'`, `'warning'`, `'dir'`, `'dirxml'`, `'table'`, `'trace'`, `'clear'`, `'startGroup'`, `'startGroupCollapsed'`, `'endGroup'`, `'assert'`, `'profile'`, `'profileEnd'`, `'count'`, `'timeEnd'`. class: Frame ------------ At every point of time, page exposes its current frame tree via the [page.mainFrame()](#pagemainframe) and [frame.childFrames()](#framechildframes) methods. [Frame](#class-frame "Frame") object's lifecycle is controlled by three events, dispatched on the page object: * ['frameattached'](#event-frameattached) - fired when the frame gets attached to the page. A Frame can be attached to the page only once. * ['framenavigated'](#event-framenavigated) - fired when the frame commits navigation to a different URL. * ['framedetached'](#event-framedetached) - fired when the frame gets detached from the page. A Frame can be detached from the page only once. An example of dumping frame tree: ``` const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto('https://www.google.com/chrome/browser/canary.html'); dumpFrameTree(page.mainFrame(), ''); await browser.close(); function dumpFrameTree(frame, indent) { console.log(indent + frame.url()); for (const child of frame.childFrames()) { dumpFrameTree(child, indent + ' '); } } })(); ``` An example of getting text from an iframe element: ``` const frame = page.frames().find(frame => frame.name() === 'myframe'); const text = await frame.$eval('.selector', element => element.textContent); console.log(text); ``` ### frame.$(selector) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to query frame for * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[ElementHandle](#class-elementhandle "ElementHandle")>> Promise which resolves to ElementHandle pointing to the frame element. The method queries frame for the selector. If there's no such element within the frame, the method resolves to `null`. ### frame.$$(selector) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to query frame for * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[ElementHandle](#class-elementhandle "ElementHandle")>>> Promise which resolves to ElementHandles pointing to the frame elements. The method runs `document.querySelectorAll` within the frame. If no elements match the selector, the return value resolves to `[]`. ### frame.$$eval(selector, pageFunction[, ...args]) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to query frame for * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Element](https://developer.mozilla.org/en-US/docs/Web/API/element "Element")>)> Function to be evaluated in browser context * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")>> Promise which resolves to the return value of `pageFunction` This method runs `Array.from(document.querySelectorAll(selector))` within the frame and passes it as the first argument to `pageFunction`. If `pageFunction` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `frame.$$eval` would wait for the promise to resolve and return its value. Examples: ``` const divsCounts = await frame.$$eval('div', divs => divs.length); ``` ### frame.$eval(selector, pageFunction[, ...args]) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to query frame for * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([Element](https://developer.mozilla.org/en-US/docs/Web/API/element "Element"))> Function to be evaluated in browser context * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")>> Promise which resolves to the return value of `pageFunction` This method runs `document.querySelector` within the frame and passes it as the first argument to `pageFunction`. If there's no element matching `selector`, the method throws an error. If `pageFunction` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `frame.$eval` would wait for the promise to resolve and return its value. Examples: ``` const searchValue = await frame.$eval('#search', el => el.value); const preloadHref = await frame.$eval('link[rel=preload]', el => el.href); const html = await frame.$eval('.main-container', e => e.outerHTML); ``` ### frame.$x(expression) * `expression` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Expression to [evaluate](https://developer.mozilla.org/en-US/docs/Web/API/Document/evaluate). * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[ElementHandle](#class-elementhandle "ElementHandle")>>> The method evaluates the XPath expression relative to the frame document as its context node. If there are no such elements, the method resolves to an empty array. ### frame.addScriptTag(options) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `url` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> URL of a script to be added. + `path` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). + `content` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Raw JavaScript content to be injected into frame. + `type` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Script type. Use 'module' in order to load a Javascript ES6 module. See [script](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) for more details. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[ElementHandle](#class-elementhandle "ElementHandle")>> which resolves to the added tag when the script's onload fires or when the script content was injected into frame. Adds a `<script>` tag into the page with the desired url or content. ### frame.addStyleTag(options) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `url` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> URL of the `<link>` tag. + `path` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). + `content` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Raw CSS content to be injected into frame. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[ElementHandle](#class-elementhandle "ElementHandle")>> which resolves to the added tag when the stylesheet's onload fires or when the CSS content was injected into frame. Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the content. ### frame.childFrames() * returns: <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Frame](#class-frame "Frame")>> ### frame.click(selector[, options]) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked. * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `button` <"left"|"right"|"middle"> Defaults to `left`. + `clickCount` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> defaults to 1. See [UIEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail"). + `delay` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves when the element matching `selector` is successfully clicked. The Promise will be rejected if there is no element matching `selector`. This method fetches an element with `selector`, scrolls it into view if needed, and then uses [page.mouse](#pagemouse) to click in the center of the element. If there's no element matching `selector`, the method throws an error. Bear in mind that if `click()` triggers a navigation event and there's a separate `page.waitForNavigation()` promise to be resolved, you may end up with a race condition that yields unexpected results. The correct pattern for click and wait for navigation is the following: ``` const [response] = await Promise.all([ page.waitForNavigation(waitOptions), frame.click(selector, clickOptions), ]); ``` ### frame.content() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>> Gets the full HTML contents of the frame, including the doctype. ### frame.evaluate(pageFunction[, ...args]) * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")|[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Function to be evaluated in browser context * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")>> Promise which resolves to the return value of `pageFunction` If the function passed to the `frame.evaluate` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `frame.evaluate` would wait for the promise to resolve and return its value. If the function passed to the `frame.evaluate` returns a non-[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable") value, then `frame.evaluate` resolves to `undefined`. DevTools Protocol also supports transferring some additional values that are not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`, and bigint literals. ``` const result = await frame.evaluate(() => { return Promise.resolve(8 * 7); }); console.log(result); // prints "56" ``` A string can also be passed in instead of a function. ``` console.log(await frame.evaluate('1 + 2')); // prints "3" ``` [ElementHandle](#class-elementhandle "ElementHandle") instances can be passed as arguments to the `frame.evaluate`: ``` const bodyHandle = await frame.$('body'); const html = await frame.evaluate(body => body.innerHTML, bodyHandle); await bodyHandle.dispose(); ``` ### frame.evaluateHandle(pageFunction[, ...args]) * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")|[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Function to be evaluated in the page context * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[JSHandle](#class-jshandle "JSHandle")|[ElementHandle](#class-elementhandle "ElementHandle")>> Promise which resolves to the return value of `pageFunction` as an in-page object. The only difference between `frame.evaluate` and `frame.evaluateHandle` is that `frame.evaluateHandle` returns in-page object (JSHandle). If the function, passed to the `frame.evaluateHandle`, returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `frame.evaluateHandle` would wait for the promise to resolve and return its value. If the function returns an element, the returned handle is an [ElementHandle](#class-elementhandle "ElementHandle"). ``` const aWindowHandle = await frame.evaluateHandle(() => Promise.resolve(window)); aWindowHandle; // Handle for the window object. ``` A string can also be passed in instead of a function. ``` const aHandle = await frame.evaluateHandle('document'); // Handle for the 'document'. ``` [JSHandle](#class-jshandle "JSHandle") instances can be passed as arguments to the `frame.evaluateHandle`: ``` const aHandle = await frame.evaluateHandle(() => document.body); const resultHandle = await frame.evaluateHandle(body => body.innerHTML, aHandle); console.log(await resultHandle.jsonValue()); await resultHandle.dispose(); ``` ### frame.executionContext() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[ExecutionContext](#class-executioncontext "ExecutionContext")>> Returns promise that resolves to the frame's default execution context. ### frame.focus(selector) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") of an element to focus. If there are multiple elements satisfying the selector, the first will be focused. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves when the element matching `selector` is successfully focused. The promise will be rejected if there is no element matching `selector`. This method fetches an element with `selector` and focuses it. If there's no element matching `selector`, the method throws an error. ### frame.goto(url[, options]) * `url` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> URL to navigate frame to. The url should include scheme, e.g. `https://`. * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Navigation parameters which might have the following properties: + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. + `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: - `load` - consider navigation to be finished when the `load` event is fired. - `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. - `networkidle2` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms. + `referer` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Referer header value. If provided it will take preference over the referer header value set by [page.setExtraHTTPHeaders()](#pagesetextrahttpheadersheaders). * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[HTTPResponse](#class-httpresponse "HTTPResponse")>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. `frame.goto` will throw an error if: * there's an SSL error (e.g. in case of self-signed certificates). * target URL is invalid. * the `timeout` is exceeded during navigation. * the remote server does not respond or is unreachable. * the main resource failed to load. `frame.goto` will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling [response.status()](#httpresponsestatus). > **NOTE** `frame.goto` either throws an error or returns a main resource response. The only exceptions are navigation to `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`. > > > **NOTE** Headless mode doesn't support navigation to a PDF document. See the [upstream issue](https://bugs.chromium.org/p/chromium/issues/detail?id=761295). > > ### frame.hover(selector) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to search for element to hover. If there are multiple elements satisfying the selector, the first will be hovered. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves when the element matching `selector` is successfully hovered. Promise gets rejected if there's no element matching `selector`. This method fetches an element with `selector`, scrolls it into view if needed, and then uses [page.mouse](#pagemouse) to hover over the center of the element. If there's no element matching `selector`, the method throws an error. ### frame.isDetached() * returns: <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Returns `true` if the frame has been detached, or `false` otherwise. ### frame.name() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Returns frame's name attribute as specified in the tag. If the name is empty, returns the id attribute instead. > **NOTE** This value is calculated once when the frame is created, and will not update if the attribute is changed later. > > ### frame.parentFrame() * returns: <?[Frame](#class-frame "Frame")> Parent frame, if any. Detached frames and main frames return `null`. ### frame.select(selector, ...values) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to query frame for * `...values` <...[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Values of options to select. If the `<select>` has the `multiple` attribute, all values are considered, otherwise only the first one is taken into account. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>>> An array of option values that have been successfully selected. Triggers a `change` and `input` event once all the provided options have been selected. If there's no `<select>` element matching `selector`, the method throws an error. ``` frame.select('select#colors', 'blue'); // single selection frame.select('select#colors', 'red', 'green', 'blue'); // multiple selections ``` ### frame.setContent(html[, options]) * `html` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> HTML markup to assign to the page. * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Parameters which might have the following properties: + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Maximum time in milliseconds for resources to load, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. + `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider setting markup succeeded, defaults to `load`. Given an array of event strings, setting content is considered to be successful after all events have been fired. Events can be either: - `load` - consider setting content to be finished when the `load` event is fired. - `domcontentloaded` - consider setting content to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider setting content to be finished when there are no more than 0 network connections for at least `500` ms. - `networkidle2` - consider setting content to be finished when there are no more than 2 network connections for at least `500` ms. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> ### frame.tap(selector) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to search for element to tap. If there are multiple elements satisfying the selector, the first will be tapped. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> This method fetches an element with `selector`, scrolls it into view if needed, and then uses [page.touchscreen](#pagetouchscreen) to tap in the center of the element. If there's no element matching `selector`, the method throws an error. ### frame.title() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>> The page's title. ### frame.type(selector, text[, options]) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") of an element to type into. If there are multiple elements satisfying the selector, the first will be used. * `text` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A text to type into a focused element. * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `delay` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Time to wait between key presses in milliseconds. Defaults to 0. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. To press a special key, like `Control` or `ArrowDown`, use [`keyboard.press`](#keyboardpresskey-options). ``` await frame.type('#mytextarea', 'Hello'); // Types instantly await frame.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a user ``` ### frame.url() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Returns frame's url. ### frame.waitFor(selectorOrFunctionOrTimeout[, options[, ...args]]) * `selectorOrFunctionOrTimeout` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")|[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector"), predicate or timeout to wait for * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Optional waiting parameters * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[JSHandle](#class-jshandle "JSHandle")>> Promise which resolves to a JSHandle of the success value **This method is deprecated**. You should use the more explicit API methods available: * `frame.waitForSelector` * `frame.waitForXPath` * `frame.waitForFunction` * `frame.waitForTimeout` This method behaves differently with respect to the type of the first parameter: * if `selectorOrFunctionOrTimeout` is a `string`, then the first argument is treated as a [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") or [xpath](https://developer.mozilla.org/en-US/docs/Web/XPath "xpath"), depending on whether or not it starts with '//', and the method is a shortcut for [frame.waitForSelector](#framewaitforselectorselector-options) or [frame.waitForXPath](#framewaitforxpathxpath-options) * if `selectorOrFunctionOrTimeout` is a `function`, then the first argument is treated as a predicate to wait for and the method is a shortcut for [frame.waitForFunction()](#framewaitforfunctionpagefunction-options-args). * if `selectorOrFunctionOrTimeout` is a `number`, then the first argument is treated as a timeout in milliseconds and the method returns a promise which resolves after the timeout * otherwise, an exception is thrown ``` // wait for selector await page.waitFor('.foo'); // wait for 1 second await page.waitFor(1000); // wait for predicate await page.waitFor(() => !!document.querySelector('.foo')); ``` To pass arguments from node.js to the predicate of `page.waitFor` function: ``` const selector = '.foo'; await page.waitFor(selector => !!document.querySelector(selector), {}, selector); ``` ### frame.waitForFunction(pageFunction[, options[, ...args]]) * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")|[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Function to be evaluated in browser context * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Optional waiting parameters + `polling` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> An interval at which the `pageFunction` is executed, defaults to `raf`. If `polling` is a number, then it is treated as an interval in milliseconds at which the function would be executed. If `polling` is a string, then it can be one of the following values: - `raf` - to constantly execute `pageFunction` in `requestAnimationFrame` callback. This is the tightest polling mode which is suitable to observe styling changes. - `mutation` - to execute `pageFunction` on every DOM mutation. + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) method. * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[JSHandle](#class-jshandle "JSHandle")>> Promise which resolves when the `pageFunction` returns a truthy value. It resolves to a JSHandle of the truthy value. The `waitForFunction` can be used to observe viewport size change: ``` const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); const watchDog = page.mainFrame().waitForFunction('window.innerWidth < 100'); page.setViewport({width: 50, height: 50}); await watchDog; await browser.close(); })(); ``` To pass arguments from node.js to the predicate of `page.waitForFunction` function: ``` const selector = '.foo'; await page.waitForFunction(selector => !!document.querySelector(selector), {}, selector); ``` ### frame.waitForNavigation([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Navigation parameters which might have the following properties: + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. + `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: - `load` - consider navigation to be finished when the `load` event is fired. - `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. - `networkidle2` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[HTTPResponse](#class-httpresponse "HTTPResponse")>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to History API usage, the navigation will resolve with `null`. This resolves when the frame navigates to a new URL. It is useful for when you run code which will indirectly cause the frame to navigate. Consider this example: ``` const [response] = await Promise.all([ frame.waitForNavigation(), // The navigation promise resolves after navigation has finished frame.click('a.my-link'), // Clicking the link will indirectly cause a navigation ]); ``` **NOTE** Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is considered a navigation. ### frame.waitForSelector(selector[, options]) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") of an element to wait for * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Optional waiting parameters + `visible` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> wait for element to be present in DOM and to be visible, i.e. to not have `display: none` or `visibility: hidden` CSS properties. Defaults to `false`. + `hidden` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> wait for element to not be found in the DOM or to be hidden, i.e. have `display: none` or `visibility: hidden` CSS properties. Defaults to `false`. + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) method. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[ElementHandle](#class-elementhandle "ElementHandle")>> Promise which resolves when element specified by selector string is added to DOM. Resolves to `null` if waiting for `hidden: true` and selector is not found in DOM. Wait for the `selector` to appear in page. If at the moment of calling the method the `selector` already exists, the method will return immediately. If the selector doesn't appear after the `timeout` milliseconds of waiting, the function will throw. This method works across navigations: ``` const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); let currentURL; page.mainFrame() .waitForSelector('img') .then(() => console.log('First URL with image: ' + currentURL)); for (currentURL of ['https://example.com', 'https://google.com', 'https://bbc.com']) { await page.goto(currentURL); } await browser.close(); })(); ``` ### frame.waitForTimeout(milliseconds) * `milliseconds` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> The number of milliseconds to wait for. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves after the timeout has completed. Pauses script execution for the given number of seconds before continuing: ``` const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); page.mainFrame() .waitForTimeout(1000) .then(() => console.log('Waited a second!')); await browser.close(); })(); ``` ### frame.waitForXPath(xpath[, options]) * `xpath` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [xpath](https://developer.mozilla.org/en-US/docs/Web/XPath "xpath") of an element to wait for * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Optional waiting parameters + `visible` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> wait for element to be present in DOM and to be visible, i.e. to not have `display: none` or `visibility: hidden` CSS properties. Defaults to `false`. + `hidden` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> wait for element to not be found in the DOM or to be hidden, i.e. have `display: none` or `visibility: hidden` CSS properties. Defaults to `false`. + `timeout` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) method. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[ElementHandle](#class-elementhandle "ElementHandle")>> Promise which resolves when element specified by xpath string is added to DOM. Resolves to `null` if waiting for `hidden: true` and xpath is not found in DOM. Wait for the `xpath` to appear in page. If at the moment of calling the method the `xpath` already exists, the method will return immediately. If the xpath doesn't appear after the `timeout` milliseconds of waiting, the function will throw. This method works across navigations: ``` const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); let currentURL; page.mainFrame() .waitForXPath('//img') .then(() => console.log('First URL with image: ' + currentURL)); for (currentURL of ['https://example.com', 'https://google.com', 'https://bbc.com']) { await page.goto(currentURL); } await browser.close(); })(); ``` class: ExecutionContext ----------------------- The class represents a context for JavaScript execution. A [Page](#class-page "Page") might have many execution contexts: * each [frame](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe) has "default" execution context that is always created after frame is attached to DOM. This context is returned by the [`frame.executionContext()`](#frameexecutioncontext) method. * [Extensions](https://developer.chrome.com/extensions)'s content scripts create additional execution contexts. Besides pages, execution contexts can be found in [workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API). ### executionContext.evaluate(pageFunction[, ...args]) * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")|[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Function to be evaluated in `executionContext` * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")>> Promise which resolves to the return value of `pageFunction` If the function passed to the `executionContext.evaluate` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `executionContext.evaluate` would wait for the promise to resolve and return its value. If the function passed to the `executionContext.evaluate` returns a non-[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable") value, then `executionContext.evaluate` resolves to `undefined`. DevTools Protocol also supports transferring some additional values that are not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`, and bigint literals. ``` const executionContext = await page.mainFrame().executionContext(); const result = await executionContext.evaluate(() => Promise.resolve(8 * 7)); console.log(result); // prints "56" ``` A string can also be passed in instead of a function. ``` console.log(await executionContext.evaluate('1 + 2')); // prints "3" ``` [JSHandle](#class-jshandle "JSHandle") instances can be passed as arguments to the `executionContext.evaluate`: ``` const oneHandle = await executionContext.evaluateHandle(() => 1); const twoHandle = await executionContext.evaluateHandle(() => 2); const result = await executionContext.evaluate((a, b) => a + b, oneHandle, twoHandle); await oneHandle.dispose(); await twoHandle.dispose(); console.log(result); // prints '3'. ``` ### executionContext.evaluateHandle(pageFunction[, ...args]) * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")|[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Function to be evaluated in the `executionContext` * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[JSHandle](#class-jshandle "JSHandle")|[ElementHandle](#class-elementhandle "ElementHandle")>> Promise which resolves to the return value of `pageFunction` as an in-page object. The only difference between `executionContext.evaluate` and `executionContext.evaluateHandle` is that `executionContext.evaluateHandle` returns in-page object (JSHandle). If the function returns an element, the returned handle is an [ElementHandle](#class-elementhandle "ElementHandle"). If the function passed to the `executionContext.evaluateHandle` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `executionContext.evaluateHandle` would wait for the promise to resolve and return its value. ``` const context = await page.mainFrame().executionContext(); const aHandle = await context.evaluateHandle(() => Promise.resolve(self)); aHandle; // Handle for the global object. ``` A string can also be passed in instead of a function. ``` const aHandle = await context.evaluateHandle('1 + 2'); // Handle for the '3' object. ``` [JSHandle](#class-jshandle "JSHandle") instances can be passed as arguments to the `executionContext.evaluateHandle`: ``` const aHandle = await context.evaluateHandle(() => document.body); const resultHandle = await context.evaluateHandle(body => body.innerHTML, aHandle); console.log(await resultHandle.jsonValue()); // prints body's innerHTML await aHandle.dispose(); await resultHandle.dispose(); ``` ### executionContext.frame() * returns: <?[Frame](#class-frame "Frame")> Frame associated with this execution context. > **NOTE** Not every execution context is associated with a frame. For example, workers and extensions have execution contexts that are not associated with frames. > > ### executionContext.queryObjects(prototypeHandle) * `prototypeHandle` <[JSHandle](#class-jshandle "JSHandle")> A handle to the object prototype. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[JSHandle](#class-jshandle "JSHandle")>> A handle to an array of objects with this prototype The method iterates the JavaScript heap and finds all the objects with the given prototype. ``` // Create a Map object await page.evaluate(() => window.map = new Map()); // Get a handle to the Map object prototype const mapPrototype = await page.evaluateHandle(() => Map.prototype); // Query all map instances into an array const mapInstances = await page.queryObjects(mapPrototype); // Count amount of map objects in heap const count = await page.evaluate(maps => maps.length, mapInstances); await mapInstances.dispose(); await mapPrototype.dispose(); ``` class: JSHandle --------------- JSHandle represents an in-page JavaScript object. JSHandles can be created with the [page.evaluateHandle](#pageevaluatehandlepagefunction-args) method. ``` const windowHandle = await page.evaluateHandle(() => window); // ... ``` JSHandle prevents the referenced JavaScript object being garbage collected unless the handle is [disposed](#jshandledispose). JSHandles are auto-disposed when their origin frame gets navigated or the parent context gets destroyed. JSHandle instances can be used as arguments in [`page.$eval()`](#pageevalselector-pagefunction-args), [`page.evaluate()`](#pageevaluatepagefunction-args) and [`page.evaluateHandle`](#pageevaluatehandlepagefunction-args) methods. ### jsHandle.asElement() * returns: <?[ElementHandle](#class-elementhandle "ElementHandle")> Returns either `null` or the object handle itself, if the object handle is an instance of [ElementHandle](#class-elementhandle "ElementHandle"). ### jsHandle.dispose() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves when the object handle is successfully disposed. The `jsHandle.dispose` method stops referencing the element handle. ### jsHandle.evaluate(pageFunction[, ...args]) * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object"))> Function to be evaluated in browser context * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")>> Promise which resolves to the return value of `pageFunction` This method passes this handle as the first argument to `pageFunction`. If `pageFunction` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `handle.evaluate` would wait for the promise to resolve and return its value. Examples: ``` const tweetHandle = await page.$('.tweet .retweets'); expect(await tweetHandle.evaluate(node => node.innerText)).toBe('10'); ``` ### jsHandle.evaluateHandle(pageFunction[, ...args]) * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")|[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Function to be evaluated * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[JSHandle](#class-jshandle "JSHandle")|[ElementHandle](#class-elementhandle "ElementHandle")>> Promise which resolves to the return value of `pageFunction` as an in-page object. This method passes this handle as the first argument to `pageFunction`. The only difference between `jsHandle.evaluate` and `jsHandle.evaluateHandle` is that `executionContext.evaluateHandle` returns in-page object (JSHandle). If the function returns an element, the returned handle is an [ElementHandle](#class-elementhandle "ElementHandle"). If the function passed to the `jsHandle.evaluateHandle` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `jsHandle.evaluateHandle` would wait for the promise to resolve and return its value. See [Page.evaluateHandle](#pageevaluatehandlepagefunction-args) for more details. ### jsHandle.executionContext() * returns: <[ExecutionContext](#class-executioncontext "ExecutionContext")> Returns execution context the handle belongs to. ### jsHandle.getProperties() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map "Map")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String"), [JSHandle](#class-jshandle "JSHandle")>>> The method returns a map with property names as keys and JSHandle instances for the property values. ``` const handle = await page.evaluateHandle(() => ({window, document})); const properties = await handle.getProperties(); const windowHandle = properties.get('window'); const documentHandle = properties.get('document'); await handle.dispose(); ``` ### jsHandle.getProperty(propertyName) * `propertyName` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> property to get * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[JSHandle](#class-jshandle "JSHandle")>> Fetches a single property from the referenced object. ### jsHandle.jsonValue() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> Returns a JSON representation of the object. If the object has a [`toJSON`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#toJSON()_behavior) function, it **will not be called**. > **NOTE** The method will return an empty JSON object if the referenced object is not stringifiable. It will throw an error if the object has circular references. > > class: ElementHandle -------------------- * extends: [JSHandle](#class-jshandle "JSHandle") ElementHandle represents an in-page DOM element. ElementHandles can be created with the [page.$](#pageselector) method. ``` const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto('https://example.com'); const hrefElement = await page.$('a'); await hrefElement.click(); // ... })(); ``` ElementHandle prevents DOM element from garbage collection unless the handle is [disposed](#elementhandledispose). ElementHandles are auto-disposed when their origin frame gets navigated. ElementHandle instances can be used as arguments in [`page.$eval()`](#pageevalselector-pagefunction-args) and [`page.evaluate()`](#pageevaluatepagefunction-args) methods. ### elementHandle.$(selector) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to query element for * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[ElementHandle](#class-elementhandle "ElementHandle")>> The method runs `element.querySelector` within the page. If no element matches the selector, the return value resolves to `null`. ### elementHandle.$$(selector) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to query element for * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[ElementHandle](#class-elementhandle "ElementHandle")>>> The method runs `element.querySelectorAll` within the page. If no elements match the selector, the return value resolves to `[]`. ### elementHandle.$$eval(selector, pageFunction[, ...args]) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to query page for * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Element](https://developer.mozilla.org/en-US/docs/Web/API/element "Element")>)> Function to be evaluated in browser context * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")>> Promise which resolves to the return value of `pageFunction` This method runs `document.querySelectorAll` within the element and passes it as the first argument to `pageFunction`. If there's no element matching `selector`, the method throws an error. If `pageFunction` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `frame.$$eval` would wait for the promise to resolve and return its value. Examples: ``` <div class="feed"> <div class="tweet">Hello!</div> <div class="tweet">Hi!</div> </div> ``` ``` const feedHandle = await page.$('.feed'); expect(await feedHandle.$$eval('.tweet', nodes => nodes.map(n => n.innerText))).toEqual(['Hello!', 'Hi!']); ``` ### elementHandle.$eval(selector, pageFunction[, ...args]) * `selector` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector") to query page for * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([Element](https://developer.mozilla.org/en-US/docs/Web/API/element "Element"))> Function to be evaluated in browser context * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")>> Promise which resolves to the return value of `pageFunction` This method runs `document.querySelector` within the element and passes it as the first argument to `pageFunction`. If there's no element matching `selector`, the method throws an error. If `pageFunction` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `frame.$eval` would wait for the promise to resolve and return its value. Examples: ``` const tweetHandle = await page.$('.tweet'); expect(await tweetHandle.$eval('.like', node => node.innerText)).toBe('100'); expect(await tweetHandle.$eval('.retweets', node => node.innerText)).toBe('10'); ``` ### elementHandle.$x(expression) * `expression` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Expression to [evaluate](https://developer.mozilla.org/en-US/docs/Web/API/Document/evaluate). * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[ElementHandle](#class-elementhandle "ElementHandle")>>> The method evaluates the XPath expression relative to the `elementHandle` as its context node. If there are no such elements, the method resolves to an empty array. The `expression` should have the context node to be evaluated properly: ``` const [childHandle] = await parentHandle.$x('./div'); ``` ### elementHandle.asElement() * returns: <[ElementHandle](#class-elementhandle "ElementHandle")> ### elementHandle.boundingBox() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> + x <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> the x coordinate of the element in pixels. + y <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> the y coordinate of the element in pixels. + width <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> the width of the element in pixels. + height <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> the height of the element in pixels. This method returns the bounding box of the element (relative to the main frame), or `null` if the element is not visible. ### elementHandle.boxModel() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> + content <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> Content box. - x <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> - y <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> + padding <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> Padding box. - x <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> - y <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> + border <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> Border box. - x <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> - y <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> + margin <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> Margin box. - x <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> - y <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> + width <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Element's width. + height <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Element's height. This method returns boxes of the element, or `null` if the element is not visible. Boxes are represented as an array of points; each Point is an object `{x, y}`. Box points are sorted clock-wise. ### elementHandle.click([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `button` <"left"|"right"|"middle"> Defaults to `left`. + `clickCount` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> defaults to 1. See [UIEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail"). + `delay` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves when the element is successfully clicked. Promise gets rejected if the element is detached from DOM. This method scrolls element into view if needed, and then uses [page.mouse](#pagemouse) to click in the center of the element. If the element is detached from DOM, the method throws an error. ### elementHandle.contentFrame() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[Frame](#class-frame "Frame")>> Resolves to the content frame for element handles referencing iframe nodes, or null otherwise ### elementHandle.dispose() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves when the element handle is successfully disposed. The `elementHandle.dispose` method stops referencing the element handle. ### elementHandle.evaluate(pageFunction[, ...args]) * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object"))> Function to be evaluated in browser context * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")>> Promise which resolves to the return value of `pageFunction` This method passes this handle as the first argument to `pageFunction`. If `pageFunction` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `handle.evaluate` would wait for the promise to resolve and return its value. Examples: ``` const tweetHandle = await page.$('.tweet .retweets'); expect(await tweetHandle.evaluate(node => node.innerText)).toBe('10'); ``` ### elementHandle.evaluateHandle(pageFunction[, ...args]) * `pageFunction` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")|[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Function to be evaluated * `...args` <...[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")|[JSHandle](#class-jshandle "JSHandle")> Arguments to pass to `pageFunction` * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[JSHandle](#class-jshandle "JSHandle")|[ElementHandle](#class-elementhandle "ElementHandle")>> Promise which resolves to the return value of `pageFunction` as an in-page object. This method passes this handle as the first argument to `pageFunction`. The only difference between `elementHandle.evaluate` and `elementHandle.evaluateHandle` is that `executionContext.evaluateHandle` returns in-page object (JSHandle). If the function returns an element, the returned handle is an [ElementHandle](#class-elementhandle "ElementHandle"). If the function passed to the `elementHandle.evaluateHandle` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then `elementHandle.evaluateHandle` would wait for the promise to resolve and return its value. See [Page.evaluateHandle](#pageevaluatehandlepagefunction-args) for more details. ### elementHandle.executionContext() * returns: <[ExecutionContext](#class-executioncontext "ExecutionContext")> ### elementHandle.focus() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Calls [focus](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on the element. ### elementHandle.getProperties() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map "Map")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String"), [JSHandle](#class-jshandle "JSHandle")>>> The method returns a map with property names as keys and JSHandle instances for the property values. ``` const listHandle = await page.evaluateHandle(() => document.body.children); const properties = await listHandle.getProperties(); const children = []; for (const property of properties.values()) { const element = property.asElement(); if (element) children.push(element); } children; // holds elementHandles to all children of document.body ``` ### elementHandle.getProperty(propertyName) * `propertyName` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> property to get * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[JSHandle](#class-jshandle "JSHandle")>> Fetches a single property from the objectHandle. ### elementHandle.hover() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves when the element is successfully hovered. This method scrolls element into view if needed, and then uses [page.mouse](#pagemouse) to hover over the center of the element. If the element is detached from DOM, the method throws an error. ### elementHandle.isIntersectingViewport() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")>> Resolves to true if the element is visible in the current viewport. ### elementHandle.jsonValue() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> Returns a JSON representation of the object. The JSON is generated by running [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) on the object in page and consequent [`JSON.parse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) in puppeteer. > **NOTE** The method will throw if the referenced object is not stringifiable. > > ### elementHandle.press(key[, options]) * `key` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Name of key to press, such as `ArrowLeft`. See [USKeyboardLayout](https://github.com/puppeteer/puppeteer/blob/v7.1.0/src/common/USKeyboardLayout.ts "USKeyboardLayout") for a list of all key names. * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `text` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> If specified, generates an input event with this text. + `delay` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Focuses the element, and then uses [`keyboard.down`](#keyboarddownkey-options) and [`keyboard.up`](#keyboardupkey). If `key` is a single character and no modifier keys besides `Shift` are being held down, a `keypress`/`input` event will also be generated. The `text` option can be specified to force an input event to be generated. > **NOTE** Modifier keys DO affect `elementHandle.press`. Holding down `Shift` will type the text in upper case. > > ### elementHandle.screenshot([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Same options as in [page.screenshot](#pagescreenshotoptions). * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[Buffer](https://nodejs.org/api/buffer.html#buffer_class_buffer "Buffer")>> Promise which resolves to buffer or a base64 string (depending on the value of `options.encoding`) with captured screenshot. This method scrolls element into view if needed, and then uses [page.screenshot](#pagescreenshotoptions) to take a screenshot of the element. If the element is detached from DOM, the method throws an error. ### elementHandle.select(...values) * `...values` <...[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Values of options to select. If the `<select>` has the `multiple` attribute, all values are considered, otherwise only the first one is taken into account. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>>> An array of option values that have been successfully selected. Triggers a `change` and `input` event once all the provided options have been selected. If there's no `<select>` element matching `selector`, the method throws an error. ``` handle.select('blue'); // single selection handle.select('red', 'green', 'blue'); // multiple selections ``` ### elementHandle.tap() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves when the element is successfully tapped. Promise gets rejected if the element is detached from DOM. This method scrolls element into view if needed, and then uses [touchscreen.tap](#touchscreentapx-y) to tap in the center of the element. If the element is detached from DOM, the method throws an error. ### elementHandle.toString() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> ### elementHandle.type(text[, options]) * `text` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A text to type into a focused element. * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `delay` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Time to wait between key presses in milliseconds. Defaults to 0. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. To press a special key, like `Control` or `ArrowDown`, use [`elementHandle.press`](#elementhandlepresskey-options). ``` await elementHandle.type('Hello'); // Types instantly await elementHandle.type('World', {delay: 100}); // Types slower, like a user ``` An example of typing into a text field and then submitting the form: ``` const elementHandle = await page.$('input'); await elementHandle.type('some text'); await elementHandle.press('Enter'); ``` ### elementHandle.uploadFile(...filePaths) * `...filePaths` <...[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Sets the value of the file input to these paths. If some of the `filePaths` are relative paths, then they are resolved relative to the [current working directory](https://nodejs.org/api/process.html#process_process_cwd). * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> This method expects `elementHandle` to point to an [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input). class: HTTPRequest ------------------ Whenever the page sends a request, such as for a network resource, the following events are emitted by puppeteer's page: * [`'request'`](#event-request) emitted when the request is issued by the page. * [`'response'`](#event-response) emitted when/if the response is received for the request. * [`'requestfinished'`](#event-requestfinished) emitted when the response body is downloaded and the request is complete. If request fails at some point, then instead of `'requestfinished'` event (and possibly instead of 'response' event), the [`'requestfailed'`](#event-requestfailed) event is emitted. > **NOTE** HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete with `'requestfinished'` event. > > If request gets a 'redirect' response, the request is successfully finished with the 'requestfinished' event, and a new request is issued to a redirected url. ### httpRequest.abort([errorCode]) * `errorCode` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Optional error code. Defaults to `failed`, could be one of the following: + `aborted` - An operation was aborted (due to user action) + `accessdenied` - Permission to access a resource, other than the network, was denied + `addressunreachable` - The IP address is unreachable. This usually means that there is no route to the specified host or network. + `blockedbyclient` - The client chose to block the request. + `blockedbyresponse` - The request failed because the response was delivered along with requirements which are not met ('X-Frame-Options' and 'Content-Security-Policy' ancestor checks, for instance). + `connectionaborted` - A connection timed out as a result of not receiving an ACK for data sent. + `connectionclosed` - A connection was closed (corresponding to a TCP FIN). + `connectionfailed` - A connection attempt failed. + `connectionrefused` - A connection attempt was refused. + `connectionreset` - A connection was reset (corresponding to a TCP RST). + `internetdisconnected` - The Internet connection has been lost. + `namenotresolved` - The host name could not be resolved. + `timedout` - An operation timed out. + `failed` - A generic failure occurred. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Aborts request. To use this, request interception should be enabled with `page.setRequestInterception`. Exception is immediately thrown if the request interception is not enabled. ### httpRequest.continue([overrides]) * `overrides` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Optional request overwrites, which can be one of the following: + `url` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> If set, the request url will be changed. This is not a redirect. The request will be silently forwarded to the new url. For example, the address bar will show the original url. + `method` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> If set changes the request method (e.g. `GET` or `POST`) + `postData` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> If set changes the post data of request + `headers` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> If set changes the request HTTP headers. Header values will be converted to a string. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Continues request with optional request overrides. To use this, request interception should be enabled with `page.setRequestInterception`. Exception is immediately thrown if the request interception is not enabled. ``` await page.setRequestInterception(true); page.on('request', request => { // Override headers const headers = Object.assign({}, request.headers(), { foo: 'bar', // set "foo" header origin: undefined, // remove "origin" header }); request.continue({headers}); }); ``` ### httpRequest.failure() * returns: <?[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Object describing request failure, if any + `errorText` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Human-readable error message, e.g. `'net::ERR_FAILED'`. The method returns `null` unless this request was failed, as reported by `requestfailed` event. Example of logging all failed requests: ``` page.on('requestfailed', request => { console.log(request.url() + ' ' + request.failure().errorText); }); ``` ### httpRequest.frame() * returns: <?[Frame](#class-frame "Frame")> A [Frame](#class-frame "Frame") that initiated this request, or `null` if navigating to error pages. ### httpRequest.headers() * returns: <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> An object with HTTP headers associated with the request. All header names are lower-case. ### httpRequest.isNavigationRequest() * returns: <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether this request is driving frame's navigation. ### httpRequest.method() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Request's method (GET, POST, etc.) ### httpRequest.postData() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Request's post body, if any. ### httpRequest.redirectChain() * returns: <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[HTTPRequest](#class-httprequest "HTTPRequest")>> A `redirectChain` is a chain of requests initiated to fetch a resource. * If there are no redirects and the request was successful, the chain will be empty. * If a server responds with at least a single redirect, then the chain will contain all the requests that were redirected. `redirectChain` is shared between all the requests of the same chain. For example, if the website `http://example.com` has a single redirect to `https://example.com`, then the chain will contain one request: ``` const response = await page.goto('http://example.com'); const chain = response.request().redirectChain(); console.log(chain.length); // 1 console.log(chain[0].url()); // 'http://example.com' ``` If the website `https://google.com` has no redirects, then the chain will be empty: ``` const response = await page.goto('https://google.com'); const chain = response.request().redirectChain(); console.log(chain.length); // 0 ``` ### httpRequest.resourceType() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Contains the request's resource type as it was perceived by the rendering engine. ResourceType will be one of the following: `document`, `stylesheet`, `image`, `media`, `font`, `script`, `texttrack`, `xhr`, `fetch`, `eventsource`, `websocket`, `manifest`, `other`. ### httpRequest.respond(response) * `response` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Response that will fulfill this request + `status` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Response status code, defaults to `200`. + `headers` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Optional response headers. Header values will be converted to a string. + `contentType` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> If set, equals to setting `Content-Type` response header + `body` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[Buffer](https://nodejs.org/api/buffer.html#buffer_class_buffer "Buffer")> Optional response body * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Fulfills request with given response. To use this, request interception should be enabled with `page.setRequestInterception`. Exception is thrown if request interception is not enabled. An example of fulfilling all requests with 404 responses: ``` await page.setRequestInterception(true); page.on('request', request => { request.respond({ status: 404, contentType: 'text/plain', body: 'Not Found!' }); }); ``` > **NOTE** Mocking responses for dataURL requests is not supported. Calling `request.respond` for a dataURL request is a noop. > > ### httpRequest.response() * returns: <?[HTTPResponse](#class-httpresponse "HTTPResponse")> A matching [HTTPResponse](#class-httpresponse "HTTPResponse") object, or `null` if the response has not been received yet. ### httpRequest.url() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> URL of the request. class: HTTPResponse ------------------- [HTTPResponse](#class-httpresponse "HTTPResponse") class represents responses which are received by page. ### httpResponse.buffer() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Buffer](https://nodejs.org/api/buffer.html#buffer_class_buffer "Buffer")>> Promise which resolves to a buffer with response body. ### httpResponse.frame() * returns: <?[Frame](#class-frame "Frame")> A [Frame](#class-frame "Frame") that initiated this response, or `null` if navigating to error pages. ### httpResponse.fromCache() * returns: <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> True if the response was served from either the browser's disk cache or memory cache. ### httpResponse.fromServiceWorker() * returns: <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> True if the response was served by a service worker. ### httpResponse.headers() * returns: <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> An object with HTTP headers associated with the response. All header names are lower-case. ### httpResponse.json() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> Promise which resolves to a JSON representation of response body. This method will throw if the response body is not parsable via `JSON.parse`. ### httpResponse.ok() * returns: <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Contains a boolean stating whether the response was successful (status in the range 200-299) or not. ### httpResponse.remoteAddress() * returns: <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> + `ip` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> the IP address of the remote server + `port` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> the port used to connect to the remote server ### httpResponse.request() * returns: <[HTTPRequest](#class-httprequest "HTTPRequest")> A matching [HTTPRequest](#class-httprequest "HTTPRequest") object. ### httpResponse.securityDetails() * returns: <?[SecurityDetails](#class-securitydetails "SecurityDetails")> Security details if the response was received over the secure connection, or `null` otherwise. ### httpResponse.status() * returns: <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> Contains the status code of the response (e.g., 200 for a success). ### httpResponse.statusText() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Contains the status text of the response (e.g. usually an "OK" for a success). ### httpResponse.text() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>> Promise which resolves to a text representation of response body. ### httpResponse.url() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Contains the URL of the response. class: SecurityDetails ---------------------- [SecurityDetails](#class-securitydetails "SecurityDetails") class represents the security details when response was received over the secure connection. ### securityDetails.issuer() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> A string with the name of issuer of the certificate. ### securityDetails.protocol() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> String with the security protocol, eg. "TLS 1.2". ### securityDetails.subjectAlternativeNames() * returns: <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>> Returns the list of SANs (subject alternative names) of the certificate. ### securityDetails.subjectName() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Name of the subject to which the certificate was issued to. ### securityDetails.validFrom() * returns: <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> [UnixTime](https://en.wikipedia.org/wiki/Unix_time "Unix Time") stating the start of validity of the certificate. ### securityDetails.validTo() * returns: <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> [UnixTime](https://en.wikipedia.org/wiki/Unix_time "Unix Time") stating the end of validity of the certificate. class: Target ------------- ### target.browser() * returns: <[Browser](#class-browser "Browser")> Get the browser the target belongs to. ### target.browserContext() * returns: <[BrowserContext](#class-browsercontext "BrowserContext")> The browser context the target belongs to. ### target.createCDPSession() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[CDPSession](#class-cdpsession "CDPSession")>> Creates a Chrome Devtools Protocol session attached to the target. ### target.opener() * returns: <?[Target](#class-target "Target")> Get the target that opened this target. Top-level targets return `null`. ### target.page() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[Page](#class-page "Page")>> If the target is not of type `"page"` or `"background_page"`, returns `null`. ### target.type() * returns: <"page"|"background\_page"|"service\_worker"|"shared\_worker"|"other"|"browser"> Identifies what kind of target this is. Can be `"page"`, [`"background_page"`](https://developer.chrome.com/extensions/background_pages), `"service_worker"`, `"shared_worker"`, `"browser"` or `"other"`. ### target.url() * returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> ### target.worker() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<?[WebWorker](#class-webworker "Worker")>> If the target is not of type `"service_worker"` or `"shared_worker"`, returns `null`. class: CDPSession ----------------- * extends: [EventEmitter](#class-eventemitter) The `CDPSession` instances are used to talk raw Chrome Devtools Protocol: * protocol methods can be called with `session.send` method. * protocol events can be subscribed to with `session.on` method. Useful links: * Documentation on DevTools Protocol can be found here: [DevTools Protocol Viewer](https://chromedevtools.github.io/devtools-protocol/). * Getting Started with DevTools Protocol: <https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md> ``` const client = await page.target().createCDPSession(); await client.send('Animation.enable'); client.on('Animation.animationCreated', () => console.log('Animation created!')); const response = await client.send('Animation.getPlaybackRate'); console.log('playback rate is ' + response.playbackRate); await client.send('Animation.setPlaybackRate', { playbackRate: response.playbackRate / 2 }); ``` ### cdpSession.detach() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Detaches the cdpSession from the target. Once detached, the cdpSession object won't emit any events and can't be used to send messages. ### cdpSession.send(method[, ...paramArgs]) * `method` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> protocol method name * `...paramArgs` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Optional method parameters * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> class: Coverage --------------- Coverage gathers information about parts of JavaScript and CSS that were used by the page. An example of using JavaScript and CSS coverage to get percentage of initially executed code: ``` // Enable both JavaScript and CSS coverage await Promise.all([ page.coverage.startJSCoverage(), page.coverage.startCSSCoverage() ]); // Navigate to page await page.goto('https://example.com'); // Disable both JavaScript and CSS coverage const [jsCoverage, cssCoverage] = await Promise.all([ page.coverage.stopJSCoverage(), page.coverage.stopCSSCoverage(), ]); let totalBytes = 0; let usedBytes = 0; const coverage = [...jsCoverage, ...cssCoverage]; for (const entry of coverage) { totalBytes += entry.text.length; for (const range of entry.ranges) usedBytes += range.end - range.start - 1; } console.log(`Bytes used: ${usedBytes / totalBytes * 100}%`); ``` *To output coverage in a form consumable by [Istanbul](https://github.com/istanbuljs), see [puppeteer-to-istanbul](https://github.com/istanbuljs/puppeteer-to-istanbul).* ### coverage.startCSSCoverage([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Set of configurable options for coverage + `resetOnNavigation` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether to reset coverage on every navigation. Defaults to `true`. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise that resolves when coverage is started ### coverage.startJSCoverage([options]) * `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Set of configurable options for coverage + `resetOnNavigation` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether to reset coverage on every navigation. Defaults to `true`. + `reportAnonymousScripts` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> Whether anonymous scripts generated by the page should be reported. Defaults to `false`. * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise that resolves when coverage is started > **NOTE** Anonymous scripts are ones that don't have an associated url. These are scripts that are dynamically created on the page using `eval` or `new Function`. If `reportAnonymousScripts` is set to `true`, anonymous scripts will have `__puppeteer_evaluation_script__` as their URL. > > ### coverage.stopCSSCoverage() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>>> Promise that resolves to the array of coverage reports for all stylesheets + `url` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> StyleSheet URL + `text` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> StyleSheet content + `ranges` <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> StyleSheet ranges that were used. Ranges are sorted and non-overlapping. - `start` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> A start offset in text, inclusive - `end` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> An end offset in text, exclusive > **NOTE** CSS Coverage doesn't include dynamically injected style tags without sourceURLs. > > ### coverage.stopJSCoverage() * returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>>> Promise that resolves to the array of coverage reports for all scripts + `url` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Script URL + `text` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> Script content + `ranges` <[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> Script ranges that were executed. Ranges are sorted and non-overlapping. - `start` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> A start offset in text, inclusive - `end` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> An end offset in text, exclusive > **NOTE** JavaScript Coverage doesn't include anonymous scripts by default. However, scripts with sourceURLs are reported. > > class: TimeoutError ------------------- * extends: [Error](https://nodejs.org/api/errors.html#errors_class_error "Error") TimeoutError is emitted whenever certain operations are terminated due to timeout, e.g. [page.waitForSelector(selector[, options])](#pagewaitforselectorselector-options) or [puppeteer.launch([options])](#puppeteerlaunchoptions). class: EventEmitter ------------------- A small EventEmitter class backed by [Mitt](https://github.com/developit/mitt/). ### eventEmitter.addListener(event, handler) * `event` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type "Symbol")> the event to remove the handler from. * `handler` <[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")> the event listener that will be added. * returns: `this` so you can chain method calls This method is identical to `on` and maintained for compatibility with Node's EventEmitter. We recommend using `on` by default. ### eventEmitter.emit(event, [eventData]) * `event` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type "Symbol")> the event to trigger. * `eventData` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> additional data to send with the event. * returns: `boolean`; `true` if there are any listeners for the event, `false` if there are none. ### eventEmitter.listenerCount(event) * `event` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type "Symbol")> the event to check for listeners. * returns: <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> the number of listeners for the given event. ### eventEmitter.off(event, handler) * `event` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type "Symbol")> the event to remove the handler from. * `handler` <[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")> the event listener that will be removed. * returns: `this` so you can chain method calls ### eventEmitter.on(event, handler) * `event` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type "Symbol")> the event to add the handler to. * `handler` <[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")> the event listener that will be added. * returns: `this` so you can chain method calls ### eventEmitter.once(event, handler) * `event` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type "Symbol")> the event to add the handler to. * `handler` <[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")> the event listener that will be added. * returns: `this` so you can chain method calls ### eventEmitter.removeAllListeners([event]) * `event` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type "Symbol")> optional argument to remove all listeners for the given event. If it's not given this method will remove all listeners for all events. * returns: `this` so you can chain method calls ### eventEmitter.removeListener(event, handler) * `event` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")|[symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type "Symbol")> the event to remove the handler from. * `handler` <[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")> the event listener that will be removed. * returns: `this` so you can chain method calls This method is identical to `off` and maintained for compatibility with Node's EventEmitter. We recommend using `off` by default. interface: CustomQueryHandler ----------------------------- Contains two functions `queryOne` and `queryAll` that can be [registered](#puppeteerregistercustomqueryhandlername-queryhandler) as alternative querying strategies. The functions `queryOne` and `queryAll` are executed in the page context. `queryOne` should take an `Element` and a selector string as argument and return a single `Element` or `null` if no element is found. `queryAll` takes the same arguments but should instead return a `NodeList<Element>` or `Array<Element>` with all the elements that match the given query selector.
programming_docs
flask Welcome to Flask Welcome to Flask ================ Welcome to Flask’s documentation. Get started with [Installation](installation/index) and then get an overview with the [Quickstart](quickstart/index). There is also a more detailed [Tutorial](https://flask.palletsprojects.com/en/2.2.x/tutorial/) that shows how to create a small but complete application with Flask. Common patterns are described in the [Patterns for Flask](patterns/index) section. The rest of the docs describe each component of Flask in detail, with a full reference in the [API](api/index) section. Flask depends on the [Jinja](https://www.palletsprojects.com/p/jinja/) template engine and the [Werkzeug](https://www.palletsprojects.com/p/werkzeug/) WSGI toolkit. The documentation for these libraries can be found at: * [Jinja documentation](https://jinja.palletsprojects.com/) * [Werkzeug documentation](https://werkzeug.palletsprojects.com/) User’s Guide ------------ Flask provides configuration and conventions, with sensible defaults, to get started. This section of the documentation explains the different parts of the Flask framework and how they can be used, customized, and extended. Beyond Flask itself, look for community-maintained extensions to add even more functionality. * [Installation](installation/index) + [Python Version](installation/index#python-version) + [Dependencies](installation/index#dependencies) + [Virtual environments](installation/index#virtual-environments) + [Install Flask](installation/index#install-flask) * [Quickstart](quickstart/index) + [A Minimal Application](quickstart/index#a-minimal-application) + [Debug Mode](quickstart/index#debug-mode) + [HTML Escaping](quickstart/index#html-escaping) + [Routing](quickstart/index#routing) + [Static Files](quickstart/index#static-files) + [Rendering Templates](quickstart/index#rendering-templates) + [Accessing Request Data](quickstart/index#accessing-request-data) + [Redirects and Errors](quickstart/index#redirects-and-errors) + [About Responses](quickstart/index#about-responses) + [Sessions](quickstart/index#sessions) + [Message Flashing](quickstart/index#message-flashing) + [Logging](quickstart/index#logging) + [Hooking in WSGI Middleware](quickstart/index#hooking-in-wsgi-middleware) + [Using Flask Extensions](quickstart/index#using-flask-extensions) + [Deploying to a Web Server](quickstart/index#deploying-to-a-web-server) * [Tutorial](https://flask.palletsprojects.com/en/2.2.x/tutorial/) + [Project Layout](https://flask.palletsprojects.com/en/2.2.x/tutorial/layout/) + [Application Setup](https://flask.palletsprojects.com/en/2.2.x/tutorial/factory/) + [Define and Access the Database](https://flask.palletsprojects.com/en/2.2.x/tutorial/database/) + [Blueprints and Views](https://flask.palletsprojects.com/en/2.2.x/tutorial/views/) + [Templates](https://flask.palletsprojects.com/en/2.2.x/tutorial/templates/) + [Static Files](https://flask.palletsprojects.com/en/2.2.x/tutorial/static/) + [Blog Blueprint](https://flask.palletsprojects.com/en/2.2.x/tutorial/blog/) + [Make the Project Installable](https://flask.palletsprojects.com/en/2.2.x/tutorial/install/) + [Test Coverage](https://flask.palletsprojects.com/en/2.2.x/tutorial/tests/) + [Deploy to Production](https://flask.palletsprojects.com/en/2.2.x/tutorial/deploy/) + [Keep Developing!](https://flask.palletsprojects.com/en/2.2.x/tutorial/next/) * [Templates](templating/index) + [Jinja Setup](templating/index#jinja-setup) + [Standard Context](templating/index#standard-context) + [Controlling Autoescaping](templating/index#controlling-autoescaping) + [Registering Filters](templating/index#registering-filters) + [Context Processors](templating/index#context-processors) + [Streaming](templating/index#streaming) * [Testing Flask Applications](testing/index) + [Identifying Tests](testing/index#identifying-tests) + [Fixtures](testing/index#fixtures) + [Sending Requests with the Test Client](testing/index#sending-requests-with-the-test-client) + [Following Redirects](testing/index#following-redirects) + [Accessing and Modifying the Session](testing/index#accessing-and-modifying-the-session) + [Running Commands with the CLI Runner](testing/index#running-commands-with-the-cli-runner) + [Tests that depend on an Active Context](testing/index#tests-that-depend-on-an-active-context) * [Handling Application Errors](errorhandling/index) + [Error Logging Tools](errorhandling/index#error-logging-tools) + [Error Handlers](errorhandling/index#error-handlers) + [Custom Error Pages](errorhandling/index#custom-error-pages) + [Blueprint Error Handlers](errorhandling/index#blueprint-error-handlers) + [Returning API Errors as JSON](errorhandling/index#returning-api-errors-as-json) + [Logging](errorhandling/index#logging) + [Debugging](errorhandling/index#debugging) * [Debugging Application Errors](debugging/index) + [In Production](debugging/index#in-production) + [The Built-In Debugger](debugging/index#the-built-in-debugger) + [External Debuggers](debugging/index#external-debuggers) * [Logging](logging/index) + [Basic Configuration](logging/index#basic-configuration) + [Email Errors to Admins](logging/index#email-errors-to-admins) + [Injecting Request Information](logging/index#injecting-request-information) + [Other Libraries](logging/index#other-libraries) * [Configuration Handling](config/index) + [Configuration Basics](config/index#configuration-basics) + [Debug Mode](config/index#debug-mode) + [Builtin Configuration Values](config/index#builtin-configuration-values) + [Configuring from Python Files](config/index#configuring-from-python-files) + [Configuring from Data Files](config/index#configuring-from-data-files) + [Configuring from Environment Variables](config/index#configuring-from-environment-variables) + [Configuration Best Practices](config/index#configuration-best-practices) + [Development / Production](config/index#development-production) + [Instance Folders](config/index#instance-folders) * [Signals](signals/index) + [Subscribing to Signals](signals/index#subscribing-to-signals) + [Creating Signals](signals/index#creating-signals) + [Sending Signals](signals/index#sending-signals) + [Signals and Flask’s Request Context](signals/index#signals-and-flask-s-request-context) + [Decorator Based Signal Subscriptions](signals/index#decorator-based-signal-subscriptions) + [Core Signals](signals/index#core-signals) * [Class-based Views](views/index) + [Basic Reusable View](views/index#basic-reusable-view) + [URL Variables](views/index#url-variables) + [View Lifetime and `self`](views/index#view-lifetime-and-self) + [View Decorators](views/index#view-decorators) + [Method Hints](views/index#method-hints) + [Method Dispatching and APIs](views/index#method-dispatching-and-apis) * [The Application Context](appcontext/index) + [Purpose of the Context](appcontext/index#purpose-of-the-context) + [Lifetime of the Context](appcontext/index#lifetime-of-the-context) + [Manually Push a Context](appcontext/index#manually-push-a-context) + [Storing Data](appcontext/index#storing-data) + [Events and Signals](appcontext/index#events-and-signals) * [The Request Context](reqcontext/index) + [Purpose of the Context](reqcontext/index#purpose-of-the-context) + [Lifetime of the Context](reqcontext/index#lifetime-of-the-context) + [Manually Push a Context](reqcontext/index#manually-push-a-context) + [How the Context Works](reqcontext/index#how-the-context-works) + [Callbacks and Errors](reqcontext/index#callbacks-and-errors) + [Notes On Proxies](reqcontext/index#notes-on-proxies) * [Modular Applications with Blueprints](blueprints/index) + [Why Blueprints?](blueprints/index#why-blueprints) + [The Concept of Blueprints](blueprints/index#the-concept-of-blueprints) + [My First Blueprint](blueprints/index#my-first-blueprint) + [Registering Blueprints](blueprints/index#registering-blueprints) + [Nesting Blueprints](blueprints/index#nesting-blueprints) + [Blueprint Resources](blueprints/index#blueprint-resources) + [Building URLs](blueprints/index#building-urls) + [Blueprint Error Handlers](blueprints/index#blueprint-error-handlers) * [Extensions](extensions/index) + [Finding Extensions](extensions/index#finding-extensions) + [Using Extensions](extensions/index#using-extensions) + [Building Extensions](extensions/index#building-extensions) * [Command Line Interface](cli/index) + [Application Discovery](cli/index#application-discovery) + [Run the Development Server](cli/index#run-the-development-server) + [Open a Shell](cli/index#open-a-shell) + [Environment Variables From dotenv](cli/index#environment-variables-from-dotenv) + [Environment Variables From virtualenv](cli/index#environment-variables-from-virtualenv) + [Custom Commands](cli/index#custom-commands) + [Plugins](cli/index#plugins) + [Custom Scripts](cli/index#custom-scripts) + [PyCharm Integration](cli/index#pycharm-integration) * [Development Server](server/index) + [Command Line](server/index#command-line) + [In Code](server/index#in-code) * [Working with the Shell](shell/index) + [Command Line Interface](shell/index#command-line-interface) + [Creating a Request Context](shell/index#creating-a-request-context) + [Firing Before/After Request](shell/index#firing-before-after-request) + [Further Improving the Shell Experience](shell/index#further-improving-the-shell-experience) * [Patterns for Flask](patterns/index) + [Large Applications as Packages](patterns/packages/index) + [Application Factories](patterns/appfactories/index) + [Application Dispatching](patterns/appdispatch/index) + [Using URL Processors](patterns/urlprocessors/index) + [Using SQLite 3 with Flask](patterns/sqlite3/index) + [SQLAlchemy in Flask](patterns/sqlalchemy/index) + [Uploading Files](patterns/fileuploads/index) + [Caching](patterns/caching/index) + [View Decorators](patterns/viewdecorators/index) + [Form Validation with WTForms](patterns/wtforms/index) + [Template Inheritance](patterns/templateinheritance/index) + [Message Flashing](patterns/flashing/index) + [JavaScript, `fetch`, and JSON](patterns/javascript/index) + [Lazily Loading Views](patterns/lazyloading/index) + [MongoDB with MongoEngine](patterns/mongoengine/index) + [Adding a favicon](patterns/favicon/index) + [Streaming Contents](patterns/streaming/index) + [Deferred Request Callbacks](patterns/deferredcallbacks/index) + [Adding HTTP Method Overrides](patterns/methodoverrides/index) + [Request Content Checksums](patterns/requestchecksum/index) + [Celery Background Tasks](patterns/celery/index) + [Subclassing Flask](patterns/subclassing/index) + [Single-Page Applications](patterns/singlepageapplications/index) * [Security Considerations](security/index) + [Cross-Site Scripting (XSS)](security/index#cross-site-scripting-xss) + [Cross-Site Request Forgery (CSRF)](security/index#cross-site-request-forgery-csrf) + [JSON Security](security/index#json-security) + [Security Headers](security/index#security-headers) + [Copy/Paste to Terminal](security/index#copy-paste-to-terminal) * [Deploying to Production](deploying/index) + [Self-Hosted Options](deploying/index#self-hosted-options) + [Hosting Platforms](deploying/index#hosting-platforms) * [Using `async` and `await`](async-await/index) + [Performance](async-await/index#performance) + [Background tasks](async-await/index#background-tasks) + [When to use Quart instead](async-await/index#when-to-use-quart-instead) + [Extensions](async-await/index#extensions) + [Other event loops](async-await/index#other-event-loops) API Reference ------------- If you are looking for information on a specific function, class or method, this part of the documentation is for you. * [API](api/index) + [Application Object](api/index#application-object) + [Blueprint Objects](api/index#blueprint-objects) + [Incoming Request Data](api/index#incoming-request-data) + [Response Objects](api/index#response-objects) + [Sessions](api/index#sessions) + [Session Interface](api/index#session-interface) + [Test Client](api/index#test-client) + [Test CLI Runner](api/index#test-cli-runner) + [Application Globals](api/index#application-globals) + [Useful Functions and Classes](api/index#useful-functions-and-classes) + [Message Flashing](api/index#message-flashing) + [JSON Support](api/index#module-flask.json) + [Template Rendering](api/index#template-rendering) + [Configuration](api/index#configuration) + [Stream Helpers](api/index#stream-helpers) + [Useful Internals](api/index#useful-internals) + [Signals](api/index#signals) + [Class-Based Views](api/index#class-based-views) + [URL Route Registrations](api/index#url-route-registrations) + [View Function Options](api/index#view-function-options) + [Command Line Interface](api/index#command-line-interface) Additional Notes ---------------- * [Design Decisions in Flask](design/index) + [The Explicit Application Object](design/index#the-explicit-application-object) + [The Routing System](design/index#the-routing-system) + [One Template Engine](design/index#one-template-engine) + [What does “micro” mean?](design/index#what-does-micro-mean) + [Thread Locals](design/index#thread-locals) + [Async/await and ASGI support](design/index#async-await-and-asgi-support) + [What Flask is, What Flask is Not](design/index#what-flask-is-what-flask-is-not) * [Flask Extension Development](https://flask.palletsprojects.com/en/2.2.x/extensiondev/) + [Naming](https://flask.palletsprojects.com/en/2.2.x/extensiondev/#naming) + [The Extension Class and Initialization](https://flask.palletsprojects.com/en/2.2.x/extensiondev/#the-extension-class-and-initialization) + [Adding Behavior](https://flask.palletsprojects.com/en/2.2.x/extensiondev/#adding-behavior) + [Configuration Techniques](https://flask.palletsprojects.com/en/2.2.x/extensiondev/#configuration-techniques) + [Data During a Request](https://flask.palletsprojects.com/en/2.2.x/extensiondev/#data-during-a-request) + [Views and Models](https://flask.palletsprojects.com/en/2.2.x/extensiondev/#views-and-models) + [Recommended Extension Guidelines](https://flask.palletsprojects.com/en/2.2.x/extensiondev/#recommended-extension-guidelines) * [How to contribute to Flask](https://flask.palletsprojects.com/en/2.2.x/contributing/) + [Support questions](https://flask.palletsprojects.com/en/2.2.x/contributing/#support-questions) + [Reporting issues](https://flask.palletsprojects.com/en/2.2.x/contributing/#reporting-issues) + [Submitting patches](https://flask.palletsprojects.com/en/2.2.x/contributing/#submitting-patches) * [License](https://flask.palletsprojects.com/en/2.2.x/license/) + [BSD-3-Clause Source License](https://flask.palletsprojects.com/en/2.2.x/license/#bsd-3-clause-source-license) + [Artwork License](https://flask.palletsprojects.com/en/2.2.x/license/#artwork-license) * [Changes](changes/index) + [Version 2.2.3](changes/index#version-2-2-3) + [Version 2.2.2](changes/index#version-2-2-2) + [Version 2.2.1](changes/index#version-2-2-1) + [Version 2.2.0](changes/index#version-2-2-0) + [Version 2.1.3](changes/index#version-2-1-3) + [Version 2.1.2](changes/index#version-2-1-2) + [Version 2.1.1](changes/index#version-2-1-1) + [Version 2.1.0](changes/index#version-2-1-0) + [Version 2.0.3](changes/index#version-2-0-3) + [Version 2.0.2](changes/index#version-2-0-2) + [Version 2.0.1](changes/index#version-2-0-1) + [Version 2.0.0](changes/index#version-2-0-0) + [Version 1.1.4](changes/index#version-1-1-4) + [Version 1.1.3](changes/index#version-1-1-3) + [Version 1.1.2](changes/index#version-1-1-2) + [Version 1.1.1](changes/index#version-1-1-1) + [Version 1.1.0](changes/index#version-1-1-0) + [Version 1.0.4](changes/index#version-1-0-4) + [Version 1.0.3](changes/index#version-1-0-3) + [Version 1.0.2](changes/index#version-1-0-2) + [Version 1.0.1](changes/index#version-1-0-1) + [Version 1.0](changes/index#version-1-0) + [Version 0.12.5](changes/index#version-0-12-5) + [Version 0.12.4](changes/index#version-0-12-4) + [Version 0.12.3](changes/index#version-0-12-3) + [Version 0.12.2](changes/index#version-0-12-2) + [Version 0.12.1](changes/index#version-0-12-1) + [Version 0.12](changes/index#version-0-12) + [Version 0.11.1](changes/index#version-0-11-1) + [Version 0.11](changes/index#version-0-11) + [Version 0.10.1](changes/index#version-0-10-1) + [Version 0.10](changes/index#version-0-10) + [Version 0.9](changes/index#version-0-9) + [Version 0.8.1](changes/index#version-0-8-1) + [Version 0.8](changes/index#version-0-8) + [Version 0.7.2](changes/index#version-0-7-2) + [Version 0.7.1](changes/index#version-0-7-1) + [Version 0.7](changes/index#version-0-7) + [Version 0.6.1](changes/index#version-0-6-1) + [Version 0.6](changes/index#version-0-6) + [Version 0.5.2](changes/index#version-0-5-2) + [Version 0.5.1](changes/index#version-0-5-1) + [Version 0.5](changes/index#version-0-5) + [Version 0.4](changes/index#version-0-4) + [Version 0.3.1](changes/index#version-0-3-1) + [Version 0.3](changes/index#version-0-3) + [Version 0.2](changes/index#version-0-2) + [Version 0.1](changes/index#version-0-1) flask Design Decisions in Flask Design Decisions in Flask ========================= If you are curious why Flask does certain things the way it does and not differently, this section is for you. This should give you an idea about some of the design decisions that may appear arbitrary and surprising at first, especially in direct comparison with other frameworks. The Explicit Application Object ------------------------------- A Python web application based on WSGI has to have one central callable object that implements the actual application. In Flask this is an instance of the [`Flask`](../api/index#flask.Flask "flask.Flask") class. Each Flask application has to create an instance of this class itself and pass it the name of the module, but why can’t Flask do that itself? Without such an explicit application object the following code: ``` from flask import Flask app = Flask(__name__) @app.route('/') def index(): return 'Hello World!' ``` Would look like this instead: ``` from hypothetical_flask import route @route('/') def index(): return 'Hello World!' ``` There are three major reasons for this. The most important one is that implicit application objects require that there may only be one instance at the time. There are ways to fake multiple applications with a single application object, like maintaining a stack of applications, but this causes some problems I won’t outline here in detail. Now the question is: when does a microframework need more than one application at the same time? A good example for this is unit testing. When you want to test something it can be very helpful to create a minimal application to test specific behavior. When the application object is deleted everything it allocated will be freed again. Another thing that becomes possible when you have an explicit object lying around in your code is that you can subclass the base class ([`Flask`](../api/index#flask.Flask "flask.Flask")) to alter specific behavior. This would not be possible without hacks if the object were created ahead of time for you based on a class that is not exposed to you. But there is another very important reason why Flask depends on an explicit instantiation of that class: the package name. Whenever you create a Flask instance you usually pass it `__name__` as package name. Flask depends on that information to properly load resources relative to your module. With Python’s outstanding support for reflection it can then access the package to figure out where the templates and static files are stored (see [`open_resource()`](../api/index#flask.Flask.open_resource "flask.Flask.open_resource")). Now obviously there are frameworks around that do not need any configuration and will still be able to load templates relative to your application module. But they have to use the current working directory for that, which is a very unreliable way to determine where the application is. The current working directory is process-wide and if you are running multiple applications in one process (which could happen in a webserver without you knowing) the paths will be off. Worse: many webservers do not set the working directory to the directory of your application but to the document root which does not have to be the same folder. The third reason is “explicit is better than implicit”. That object is your WSGI application, you don’t have to remember anything else. If you want to apply a WSGI middleware, just wrap it and you’re done (though there are better ways to do that so that you do not lose the reference to the application object [`wsgi_app()`](../api/index#flask.Flask.wsgi_app "flask.Flask.wsgi_app")). Furthermore this design makes it possible to use a factory function to create the application which is very helpful for unit testing and similar things ([Application Factories](../patterns/appfactories/index)). The Routing System ------------------ Flask uses the Werkzeug routing system which was designed to automatically order routes by complexity. This means that you can declare routes in arbitrary order and they will still work as expected. This is a requirement if you want to properly implement decorator based routing since decorators could be fired in undefined order when the application is split into multiple modules. Another design decision with the Werkzeug routing system is that routes in Werkzeug try to ensure that URLs are unique. Werkzeug will go quite far with that in that it will automatically redirect to a canonical URL if a route is ambiguous. One Template Engine ------------------- Flask decides on one template engine: Jinja2. Why doesn’t Flask have a pluggable template engine interface? You can obviously use a different template engine, but Flask will still configure Jinja2 for you. While that limitation that Jinja2 is *always* configured will probably go away, the decision to bundle one template engine and use that will not. Template engines are like programming languages and each of those engines has a certain understanding about how things work. On the surface they all work the same: you tell the engine to evaluate a template with a set of variables and take the return value as string. But that’s about where similarities end. Jinja2 for example has an extensive filter system, a certain way to do template inheritance, support for reusable blocks (macros) that can be used from inside templates and also from Python code, supports iterative template rendering, configurable syntax and more. On the other hand an engine like Genshi is based on XML stream evaluation, template inheritance by taking the availability of XPath into account and more. Mako on the other hand treats templates similar to Python modules. When it comes to connecting a template engine with an application or framework there is more than just rendering templates. For instance, Flask uses Jinja2’s extensive autoescaping support. Also it provides ways to access macros from Jinja2 templates. A template abstraction layer that would not take the unique features of the template engines away is a science on its own and a too large undertaking for a microframework like Flask. Furthermore extensions can then easily depend on one template language being present. You can easily use your own templating language, but an extension could still depend on Jinja itself. What does “micro” mean? ----------------------- “Micro” does not mean that your whole web application has to fit into a single Python file (although it certainly can), nor does it mean that Flask is lacking in functionality. The “micro” in microframework means Flask aims to keep the core simple but extensible. Flask won’t make many decisions for you, such as what database to use. Those decisions that it does make, such as what templating engine to use, are easy to change. Everything else is up to you, so that Flask can be everything you need and nothing you don’t. By default, Flask does not include a database abstraction layer, form validation or anything else where different libraries already exist that can handle that. Instead, Flask supports extensions to add such functionality to your application as if it was implemented in Flask itself. Numerous extensions provide database integration, form validation, upload handling, various open authentication technologies, and more. Flask may be “micro”, but it’s ready for production use on a variety of needs. Why does Flask call itself a microframework and yet it depends on two libraries (namely Werkzeug and Jinja2). Why shouldn’t it? If we look over to the Ruby side of web development there we have a protocol very similar to WSGI. Just that it’s called Rack there, but besides that it looks very much like a WSGI rendition for Ruby. But nearly all applications in Ruby land do not work with Rack directly, but on top of a library with the same name. This Rack library has two equivalents in Python: WebOb (formerly Paste) and Werkzeug. Paste is still around but from my understanding it’s sort of deprecated in favour of WebOb. The development of WebOb and Werkzeug started side by side with similar ideas in mind: be a good implementation of WSGI for other applications to take advantage. Flask is a framework that takes advantage of the work already done by Werkzeug to properly interface WSGI (which can be a complex task at times). Thanks to recent developments in the Python package infrastructure, packages with dependencies are no longer an issue and there are very few reasons against having libraries that depend on others. Thread Locals ------------- Flask uses thread local objects (context local objects in fact, they support greenlet contexts as well) for request, session and an extra object you can put your own things on ([`g`](../api/index#flask.g "flask.g")). Why is that and isn’t that a bad idea? Yes it is usually not such a bright idea to use thread locals. They cause troubles for servers that are not based on the concept of threads and make large applications harder to maintain. However Flask is just not designed for large applications or asynchronous servers. Flask wants to make it quick and easy to write a traditional web application. Async/await and ASGI support ---------------------------- Flask supports `async` coroutines for view functions by executing the coroutine on a separate thread instead of using an event loop on the main thread as an async-first (ASGI) framework would. This is necessary for Flask to remain backwards compatible with extensions and code built before `async` was introduced into Python. This compromise introduces a performance cost compared with the ASGI frameworks, due to the overhead of the threads. Due to how tied to WSGI Flask’s code is, it’s not clear if it’s possible to make the `Flask` class support ASGI and WSGI at the same time. Work is currently being done in Werkzeug to work with ASGI, which may eventually enable support in Flask as well. See [Using async and await](../async-await/index) for more discussion. What Flask is, What Flask is Not -------------------------------- Flask will never have a database layer. It will not have a form library or anything else in that direction. Flask itself just bridges to Werkzeug to implement a proper WSGI application and to Jinja2 to handle templating. It also binds to a few common standard library packages such as logging. Everything else is up for extensions. Why is this the case? Because people have different preferences and requirements and Flask could not meet those if it would force any of this into the core. The majority of web applications will need a template engine in some sort. However not every application needs a SQL database. As your codebase grows, you are free to make the design decisions appropriate for your project. Flask will continue to provide a very simple glue layer to the best that Python has to offer. You can implement advanced patterns in SQLAlchemy or another database tool, introduce non-relational data persistence as appropriate, and take advantage of framework-agnostic tools built for WSGI, the Python web interface. The idea of Flask is to build a good foundation for all applications. Everything else is up to you or extensions.
programming_docs
flask Modular Applications with Blueprints Modular Applications with Blueprints ==================================== Changelog New in version 0.7. Flask uses a concept of *blueprints* for making application components and supporting common patterns within an application or across applications. Blueprints can greatly simplify how large applications work and provide a central means for Flask extensions to register operations on applications. A [`Blueprint`](../api/index#flask.Blueprint "flask.Blueprint") object works similarly to a [`Flask`](../api/index#flask.Flask "flask.Flask") application object, but it is not actually an application. Rather it is a *blueprint* of how to construct or extend an application. Why Blueprints? --------------- Blueprints in Flask are intended for these cases: * Factor an application into a set of blueprints. This is ideal for larger applications; a project could instantiate an application object, initialize several extensions, and register a collection of blueprints. * Register a blueprint on an application at a URL prefix and/or subdomain. Parameters in the URL prefix/subdomain become common view arguments (with defaults) across all view functions in the blueprint. * Register a blueprint multiple times on an application with different URL rules. * Provide template filters, static files, templates, and other utilities through blueprints. A blueprint does not have to implement applications or view functions. * Register a blueprint on an application for any of these cases when initializing a Flask extension. A blueprint in Flask is not a pluggable app because it is not actually an application – it’s a set of operations which can be registered on an application, even multiple times. Why not have multiple application objects? You can do that (see [Application Dispatching](../patterns/appdispatch/index)), but your applications will have separate configs and will be managed at the WSGI layer. Blueprints instead provide separation at the Flask level, share application config, and can change an application object as necessary with being registered. The downside is that you cannot unregister a blueprint once an application was created without having to destroy the whole application object. The Concept of Blueprints ------------------------- The basic concept of blueprints is that they record operations to execute when registered on an application. Flask associates view functions with blueprints when dispatching requests and generating URLs from one endpoint to another. My First Blueprint ------------------ This is what a very basic blueprint looks like. In this case we want to implement a blueprint that does simple rendering of static templates: ``` from flask import Blueprint, render_template, abort from jinja2 import TemplateNotFound simple_page = Blueprint('simple_page', __name__, template_folder='templates') @simple_page.route('/', defaults={'page': 'index'}) @simple_page.route('/<page>') def show(page): try: return render_template(f'pages/{page}.html') except TemplateNotFound: abort(404) ``` When you bind a function with the help of the `@simple_page.route` decorator, the blueprint will record the intention of registering the function `show` on the application when it’s later registered. Additionally it will prefix the endpoint of the function with the name of the blueprint which was given to the [`Blueprint`](../api/index#flask.Blueprint "flask.Blueprint") constructor (in this case also `simple_page`). The blueprint’s name does not modify the URL, only the endpoint. Registering Blueprints ---------------------- So how do you register that blueprint? Like this: ``` from flask import Flask from yourapplication.simple_page import simple_page app = Flask(__name__) app.register_blueprint(simple_page) ``` If you check the rules registered on the application, you will find these: ``` >>> app.url_map Map([<Rule '/static/<filename>' (HEAD, OPTIONS, GET) -> static>, <Rule '/<page>' (HEAD, OPTIONS, GET) -> simple_page.show>, <Rule '/' (HEAD, OPTIONS, GET) -> simple_page.show>]) ``` The first one is obviously from the application itself for the static files. The other two are for the `show` function of the `simple_page` blueprint. As you can see, they are also prefixed with the name of the blueprint and separated by a dot (`.`). Blueprints however can also be mounted at different locations: ``` app.register_blueprint(simple_page, url_prefix='/pages') ``` And sure enough, these are the generated rules: ``` >>> app.url_map Map([<Rule '/static/<filename>' (HEAD, OPTIONS, GET) -> static>, <Rule '/pages/<page>' (HEAD, OPTIONS, GET) -> simple_page.show>, <Rule '/pages/' (HEAD, OPTIONS, GET) -> simple_page.show>]) ``` On top of that you can register blueprints multiple times though not every blueprint might respond properly to that. In fact it depends on how the blueprint is implemented if it can be mounted more than once. Nesting Blueprints ------------------ It is possible to register a blueprint on another blueprint. ``` parent = Blueprint('parent', __name__, url_prefix='/parent') child = Blueprint('child', __name__, url_prefix='/child') parent.register_blueprint(child) app.register_blueprint(parent) ``` The child blueprint will gain the parent’s name as a prefix to its name, and child URLs will be prefixed with the parent’s URL prefix. ``` url_for('parent.child.create') /parent/child/create ``` Blueprint-specific before request functions, etc. registered with the parent will trigger for the child. If a child does not have an error handler that can handle a given exception, the parent’s will be tried. Blueprint Resources ------------------- Blueprints can provide resources as well. Sometimes you might want to introduce a blueprint only for the resources it provides. ### Blueprint Resource Folder Like for regular applications, blueprints are considered to be contained in a folder. While multiple blueprints can originate from the same folder, it does not have to be the case and it’s usually not recommended. The folder is inferred from the second argument to [`Blueprint`](../api/index#flask.Blueprint "flask.Blueprint") which is usually `__name__`. This argument specifies what logical Python module or package corresponds to the blueprint. If it points to an actual Python package that package (which is a folder on the filesystem) is the resource folder. If it’s a module, the package the module is contained in will be the resource folder. You can access the [`Blueprint.root_path`](../api/index#flask.Blueprint.root_path "flask.Blueprint.root_path") property to see what the resource folder is: ``` >>> simple_page.root_path '/Users/username/TestProject/yourapplication' ``` To quickly open sources from this folder you can use the [`open_resource()`](../api/index#flask.Blueprint.open_resource "flask.Blueprint.open_resource") function: ``` with simple_page.open_resource('static/style.css') as f: code = f.read() ``` ### Static Files A blueprint can expose a folder with static files by providing the path to the folder on the filesystem with the `static_folder` argument. It is either an absolute path or relative to the blueprint’s location: ``` admin = Blueprint('admin', __name__, static_folder='static') ``` By default the rightmost part of the path is where it is exposed on the web. This can be changed with the `static_url_path` argument. Because the folder is called `static` here it will be available at the `url_prefix` of the blueprint + `/static`. If the blueprint has the prefix `/admin`, the static URL will be `/admin/static`. The endpoint is named `blueprint_name.static`. You can generate URLs to it with [`url_for()`](../api/index#flask.url_for "flask.url_for") like you would with the static folder of the application: ``` url_for('admin.static', filename='style.css') ``` However, if the blueprint does not have a `url_prefix`, it is not possible to access the blueprint’s static folder. This is because the URL would be `/static` in this case, and the application’s `/static` route takes precedence. Unlike template folders, blueprint static folders are not searched if the file does not exist in the application static folder. ### Templates If you want the blueprint to expose templates you can do that by providing the `template_folder` parameter to the [`Blueprint`](../api/index#flask.Blueprint "flask.Blueprint") constructor: ``` admin = Blueprint('admin', __name__, template_folder='templates') ``` For static files, the path can be absolute or relative to the blueprint resource folder. The template folder is added to the search path of templates but with a lower priority than the actual application’s template folder. That way you can easily override templates that a blueprint provides in the actual application. This also means that if you don’t want a blueprint template to be accidentally overridden, make sure that no other blueprint or actual application template has the same relative path. When multiple blueprints provide the same relative template path the first blueprint registered takes precedence over the others. So if you have a blueprint in the folder `yourapplication/admin` and you want to render the template `'admin/index.html'` and you have provided `templates` as a `template_folder` you will have to create a file like this: `yourapplication/admin/templates/admin/index.html`. The reason for the extra `admin` folder is to avoid getting our template overridden by a template named `index.html` in the actual application template folder. To further reiterate this: if you have a blueprint named `admin` and you want to render a template called `index.html` which is specific to this blueprint, the best idea is to lay out your templates like this: ``` yourpackage/ blueprints/ admin/ templates/ admin/ index.html __init__.py ``` And then when you want to render the template, use `admin/index.html` as the name to look up the template by. If you encounter problems loading the correct templates enable the `EXPLAIN_TEMPLATE_LOADING` config variable which will instruct Flask to print out the steps it goes through to locate templates on every `render_template` call. Building URLs ------------- If you want to link from one page to another you can use the [`url_for()`](../api/index#flask.url_for "flask.url_for") function just like you normally would do just that you prefix the URL endpoint with the name of the blueprint and a dot (`.`): ``` url_for('admin.index') ``` Additionally if you are in a view function of a blueprint or a rendered template and you want to link to another endpoint of the same blueprint, you can use relative redirects by prefixing the endpoint with a dot only: ``` url_for('.index') ``` This will link to `admin.index` for instance in case the current request was dispatched to any other admin blueprint endpoint. Blueprint Error Handlers ------------------------ Blueprints support the `errorhandler` decorator just like the [`Flask`](../api/index#flask.Flask "flask.Flask") application object, so it is easy to make Blueprint-specific custom error pages. Here is an example for a “404 Page Not Found” exception: ``` @simple_page.errorhandler(404) def page_not_found(e): return render_template('pages/404.html') ``` Most errorhandlers will simply work as expected; however, there is a caveat concerning handlers for 404 and 405 exceptions. These errorhandlers are only invoked from an appropriate `raise` statement or a call to `abort` in another of the blueprint’s view functions; they are not invoked by, e.g., an invalid URL access. This is because the blueprint does not “own” a certain URL space, so the application instance has no way of knowing which blueprint error handler it should run if given an invalid URL. If you would like to execute different handling strategies for these errors based on URL prefixes, they may be defined at the application level using the `request` proxy object: ``` @app.errorhandler(404) @app.errorhandler(405) def _handle_api_error(ex): if request.path.startswith('/api/'): return jsonify(error=str(ex)), ex.code else: return ex ``` See [Handling Application Errors](../errorhandling/index). flask Patterns for Flask Patterns for Flask ================== Certain features and interactions are common enough that you will find them in most web applications. For example, many applications use a relational database and user authentication. They will open a database connection at the beginning of the request and get the information for the logged in user. At the end of the request, the database connection is closed. These types of patterns may be a bit outside the scope of Flask itself, but Flask makes it easy to implement them. Some common patterns are collected in the following pages. * [Large Applications as Packages](packages/index) + [Simple Packages](packages/index#simple-packages) + [Working with Blueprints](packages/index#working-with-blueprints) * [Application Factories](appfactories/index) + [Basic Factories](appfactories/index#basic-factories) + [Factories & Extensions](appfactories/index#factories-extensions) + [Using Applications](appfactories/index#using-applications) + [Factory Improvements](appfactories/index#factory-improvements) * [Application Dispatching](appdispatch/index) + [Working with this Document](appdispatch/index#working-with-this-document) + [Combining Applications](appdispatch/index#combining-applications) + [Dispatch by Subdomain](appdispatch/index#dispatch-by-subdomain) + [Dispatch by Path](appdispatch/index#dispatch-by-path) * [Using URL Processors](urlprocessors/index) + [Internationalized Application URLs](urlprocessors/index#internationalized-application-urls) + [Internationalized Blueprint URLs](urlprocessors/index#internationalized-blueprint-urls) * [Using SQLite 3 with Flask](sqlite3/index) + [Connect on Demand](sqlite3/index#connect-on-demand) + [Easy Querying](sqlite3/index#easy-querying) + [Initial Schemas](sqlite3/index#initial-schemas) * [SQLAlchemy in Flask](sqlalchemy/index) + [Flask-SQLAlchemy Extension](sqlalchemy/index#flask-sqlalchemy-extension) + [Declarative](sqlalchemy/index#declarative) + [Manual Object Relational Mapping](sqlalchemy/index#manual-object-relational-mapping) + [SQL Abstraction Layer](sqlalchemy/index#sql-abstraction-layer) * [Uploading Files](fileuploads/index) + [A Gentle Introduction](fileuploads/index#a-gentle-introduction) + [Improving Uploads](fileuploads/index#improving-uploads) + [Upload Progress Bars](fileuploads/index#upload-progress-bars) + [An Easier Solution](fileuploads/index#an-easier-solution) * [Caching](caching/index) * [View Decorators](viewdecorators/index) + [Login Required Decorator](viewdecorators/index#login-required-decorator) + [Caching Decorator](viewdecorators/index#caching-decorator) + [Templating Decorator](viewdecorators/index#templating-decorator) + [Endpoint Decorator](viewdecorators/index#endpoint-decorator) * [Form Validation with WTForms](wtforms/index) + [The Forms](wtforms/index#the-forms) + [In the View](wtforms/index#in-the-view) + [Forms in Templates](wtforms/index#forms-in-templates) * [Template Inheritance](templateinheritance/index) + [Base Template](templateinheritance/index#base-template) + [Child Template](templateinheritance/index#child-template) * [Message Flashing](flashing/index) + [Simple Flashing](flashing/index#simple-flashing) + [Flashing With Categories](flashing/index#flashing-with-categories) + [Filtering Flash Messages](flashing/index#filtering-flash-messages) * [JavaScript, `fetch`, and JSON](javascript/index) + [Rendering Templates](javascript/index#rendering-templates) + [Generating URLs](javascript/index#generating-urls) + [Making a Request with `fetch`](javascript/index#making-a-request-with-fetch) + [Following Redirects](javascript/index#following-redirects) + [Replacing Content](javascript/index#replacing-content) + [Return JSON from Views](javascript/index#return-json-from-views) + [Receiving JSON in Views](javascript/index#receiving-json-in-views) * [Lazily Loading Views](lazyloading/index) + [Converting to Centralized URL Map](lazyloading/index#converting-to-centralized-url-map) + [Loading Late](lazyloading/index#loading-late) * [MongoDB with MongoEngine](mongoengine/index) + [Configuration](mongoengine/index#configuration) + [Mapping Documents](mongoengine/index#mapping-documents) + [Creating Data](mongoengine/index#creating-data) + [Queries](mongoengine/index#queries) + [Documentation](mongoengine/index#documentation) * [Adding a favicon](favicon/index) + [See also](favicon/index#see-also) * [Streaming Contents](streaming/index) + [Basic Usage](streaming/index#basic-usage) + [Streaming from Templates](streaming/index#streaming-from-templates) + [Streaming with Context](streaming/index#streaming-with-context) * [Deferred Request Callbacks](deferredcallbacks/index) * [Adding HTTP Method Overrides](methodoverrides/index) * [Request Content Checksums](requestchecksum/index) * [Celery Background Tasks](celery/index) + [Install](celery/index#install) + [Configure](celery/index#configure) + [An example task](celery/index#an-example-task) + [Run a worker](celery/index#run-a-worker) * [Subclassing Flask](subclassing/index) * [Single-Page Applications](singlepageapplications/index) flask Template Inheritance Template Inheritance ==================== The most powerful part of Jinja is template inheritance. Template inheritance allows you to build a base “skeleton” template that contains all the common elements of your site and defines **blocks** that child templates can override. Sounds complicated but is very basic. It’s easiest to understand it by starting with an example. Base Template ------------- This template, which we’ll call `layout.html`, defines a simple HTML skeleton document that you might use for a simple two-column page. It’s the job of “child” templates to fill the empty blocks with content: ``` <!doctype html> <html> <head> {% block head %} <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"> <title>{% block title %}{% endblock %} - My Webpage</title> {% endblock %} </head> <body> <div id="content">{% block content %}{% endblock %}</div> <div id="footer"> {% block footer %} &copy; Copyright 2010 by <a href="http://domain.invalid/">you</a>. {% endblock %} </div> </body> </html> ``` In this example, the `{% block %}` tags define four blocks that child templates can fill in. All the `block` tag does is tell the template engine that a child template may override those portions of the template. Child Template -------------- A child template might look like this: ``` {% extends "layout.html" %} {% block title %}Index{% endblock %} {% block head %} {{ super() }} <style type="text/css"> .important { color: #336699; } </style> {% endblock %} {% block content %} <h1>Index</h1> <p class="important"> Welcome on my awesome homepage. {% endblock %} ``` The `{% extends %}` tag is the key here. It tells the template engine that this template “extends” another template. When the template system evaluates this template, first it locates the parent. The extends tag must be the first tag in the template. To render the contents of a block defined in the parent template, use `{{ super() }}`. flask Request Content Checksums Request Content Checksums ========================= Various pieces of code can consume the request data and preprocess it. For instance JSON data ends up on the request object already read and processed, form data ends up there as well but goes through a different code path. This seems inconvenient when you want to calculate the checksum of the incoming request data. This is necessary sometimes for some APIs. Fortunately this is however very simple to change by wrapping the input stream. The following example calculates the SHA1 checksum of the incoming data as it gets read and stores it in the WSGI environment: ``` import hashlib class ChecksumCalcStream(object): def __init__(self, stream): self._stream = stream self._hash = hashlib.sha1() def read(self, bytes): rv = self._stream.read(bytes) self._hash.update(rv) return rv def readline(self, size_hint): rv = self._stream.readline(size_hint) self._hash.update(rv) return rv def generate_checksum(request): env = request.environ stream = ChecksumCalcStream(env['wsgi.input']) env['wsgi.input'] = stream return stream._hash ``` To use this, all you need to do is to hook the calculating stream in before the request starts consuming data. (Eg: be careful accessing `request.form` or anything of that nature. `before_request_handlers` for instance should be careful not to access it). Example usage: ``` @app.route('/special-api', methods=['POST']) def special_api(): hash = generate_checksum(request) # Accessing this parses the input stream files = request.files # At this point the hash is fully constructed. checksum = hash.hexdigest() return f"Hash was: {checksum}" ```
programming_docs
flask Adding HTTP Method Overrides Adding HTTP Method Overrides ============================ Some HTTP proxies do not support arbitrary HTTP methods or newer HTTP methods (such as PATCH). In that case it’s possible to “proxy” HTTP methods through another HTTP method in total violation of the protocol. The way this works is by letting the client do an HTTP POST request and set the `X-HTTP-Method-Override` header. Then the method is replaced with the header value before being passed to Flask. This can be accomplished with an HTTP middleware: ``` class HTTPMethodOverrideMiddleware(object): allowed_methods = frozenset([ 'GET', 'HEAD', 'POST', 'DELETE', 'PUT', 'PATCH', 'OPTIONS' ]) bodyless_methods = frozenset(['GET', 'HEAD', 'OPTIONS', 'DELETE']) def __init__(self, app): self.app = app def __call__(self, environ, start_response): method = environ.get('HTTP_X_HTTP_METHOD_OVERRIDE', '').upper() if method in self.allowed_methods: environ['REQUEST_METHOD'] = method if method in self.bodyless_methods: environ['CONTENT_LENGTH'] = '0' return self.app(environ, start_response) ``` To use this with Flask, wrap the app object with the middleware: ``` from flask import Flask app = Flask(__name__) app.wsgi_app = HTTPMethodOverrideMiddleware(app.wsgi_app) ``` flask Uploading Files Uploading Files =============== Ah yes, the good old problem of file uploads. The basic idea of file uploads is actually quite simple. It basically works like this: 1. A `<form>` tag is marked with `enctype=multipart/form-data` and an `<input type=file>` is placed in that form. 2. The application accesses the file from the `files` dictionary on the request object. 3. use the [`save()`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.FileStorage.save "(in Werkzeug v2.2.x)") method of the file to save the file permanently somewhere on the filesystem. A Gentle Introduction --------------------- Let’s start with a very basic application that uploads a file to a specific upload folder and displays a file to the user. Let’s look at the bootstrapping code for our application: ``` import os from flask import Flask, flash, request, redirect, url_for from werkzeug.utils import secure_filename UPLOAD_FOLDER = '/path/to/the/uploads' ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'} app = Flask(__name__) app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER ``` So first we need a couple of imports. Most should be straightforward, the `werkzeug.secure_filename()` is explained a little bit later. The `UPLOAD_FOLDER` is where we will store the uploaded files and the `ALLOWED_EXTENSIONS` is the set of allowed file extensions. Why do we limit the extensions that are allowed? You probably don’t want your users to be able to upload everything there if the server is directly sending out the data to the client. That way you can make sure that users are not able to upload HTML files that would cause XSS problems (see [Cross-Site Scripting (XSS)](../../security/index#security-xss)). Also make sure to disallow `.php` files if the server executes them, but who has PHP installed on their server, right? :) Next the functions that check if an extension is valid and that uploads the file and redirects the user to the URL for the uploaded file: ``` def allowed_file(filename): return '.' in filename and \ filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS @app.route('/', methods=['GET', 'POST']) def upload_file(): if request.method == 'POST': # check if the post request has the file part if 'file' not in request.files: flash('No file part') return redirect(request.url) file = request.files['file'] # If the user does not select a file, the browser submits an # empty file without a filename. if file.filename == '': flash('No selected file') return redirect(request.url) if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) return redirect(url_for('download_file', name=filename)) return ''' <!doctype html> <title>Upload new File</title> <h1>Upload new File</h1> <form method=post enctype=multipart/form-data> <input type=file name=file> <input type=submit value=Upload> </form> ''' ``` So what does that [`secure_filename()`](https://werkzeug.palletsprojects.com/en/2.2.x/utils/#werkzeug.utils.secure_filename "(in Werkzeug v2.2.x)") function actually do? Now the problem is that there is that principle called “never trust user input”. This is also true for the filename of an uploaded file. All submitted form data can be forged, and filenames can be dangerous. For the moment just remember: always use that function to secure a filename before storing it directly on the filesystem. Information for the Pros So you’re interested in what that [`secure_filename()`](https://werkzeug.palletsprojects.com/en/2.2.x/utils/#werkzeug.utils.secure_filename "(in Werkzeug v2.2.x)") function does and what the problem is if you’re not using it? So just imagine someone would send the following information as `filename` to your application: ``` filename = "../../../../home/username/.bashrc" ``` Assuming the number of `../` is correct and you would join this with the `UPLOAD_FOLDER` the user might have the ability to modify a file on the server’s filesystem he or she should not modify. This does require some knowledge about how the application looks like, but trust me, hackers are patient :) Now let’s look how that function works: ``` >>> secure_filename('../../../../home/username/.bashrc') 'home_username_.bashrc' ``` We want to be able to serve the uploaded files so they can be downloaded by users. We’ll define a `download_file` view to serve files in the upload folder by name. `url_for("download_file", name=name)` generates download URLs. ``` from flask import send_from_directory @app.route('/uploads/<name>') def download_file(name): return send_from_directory(app.config["UPLOAD_FOLDER"], name) ``` If you’re using middleware or the HTTP server to serve files, you can register the `download_file` endpoint as `build_only` so `url_for` will work without a view function. ``` app.add_url_rule( "/uploads/<name>", endpoint="download_file", build_only=True ) ``` Improving Uploads ----------------- Changelog New in version 0.6. So how exactly does Flask handle uploads? Well it will store them in the webserver’s memory if the files are reasonably small, otherwise in a temporary location (as returned by [`tempfile.gettempdir()`](https://docs.python.org/3/library/tempfile.html#tempfile.gettempdir "(in Python v3.10)")). But how do you specify the maximum file size after which an upload is aborted? By default Flask will happily accept file uploads with an unlimited amount of memory, but you can limit that by setting the `MAX_CONTENT_LENGTH` config key: ``` from flask import Flask, Request app = Flask(__name__) app.config['MAX_CONTENT_LENGTH'] = 16 * 1000 * 1000 ``` The code above will limit the maximum allowed payload to 16 megabytes. If a larger file is transmitted, Flask will raise a [`RequestEntityTooLarge`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.RequestEntityTooLarge "(in Werkzeug v2.2.x)") exception. Connection Reset Issue When using the local development server, you may get a connection reset error instead of a 413 response. You will get the correct status response when running the app with a production WSGI server. This feature was added in Flask 0.6 but can be achieved in older versions as well by subclassing the request object. For more information on that consult the Werkzeug documentation on file handling. Upload Progress Bars -------------------- A while ago many developers had the idea to read the incoming file in small chunks and store the upload progress in the database to be able to poll the progress with JavaScript from the client. The client asks the server every 5 seconds how much it has transmitted, but this is something it should already know. An Easier Solution ------------------ Now there are better solutions that work faster and are more reliable. There are JavaScript libraries like [jQuery](https://jquery.com/) that have form plugins to ease the construction of progress bar. Because the common pattern for file uploads exists almost unchanged in all applications dealing with uploads, there are also some Flask extensions that implement a full fledged upload mechanism that allows controlling which file extensions are allowed to be uploaded. flask Message Flashing Message Flashing ================ Good applications and user interfaces are all about feedback. If the user does not get enough feedback they will probably end up hating the application. Flask provides a really simple way to give feedback to a user with the flashing system. The flashing system basically makes it possible to record a message at the end of a request and access it next request and only next request. This is usually combined with a layout template that does this. Note that browsers and sometimes web servers enforce a limit on cookie sizes. This means that flashing messages that are too large for session cookies causes message flashing to fail silently. Simple Flashing --------------- So here is a full example: ``` from flask import Flask, flash, redirect, render_template, \ request, url_for app = Flask(__name__) app.secret_key = b'_5#y2L"F4Q8z\n\xec]/' @app.route('/') def index(): return render_template('index.html') @app.route('/login', methods=['GET', 'POST']) def login(): error = None if request.method == 'POST': if request.form['username'] != 'admin' or \ request.form['password'] != 'secret': error = 'Invalid credentials' else: flash('You were successfully logged in') return redirect(url_for('index')) return render_template('login.html', error=error) ``` And here is the `layout.html` template which does the magic: ``` <!doctype html> <title>My Application</title> {% with messages = get_flashed_messages() %} {% if messages %} <ul class=flashes> {% for message in messages %} <li>{{ message }}</li> {% endfor %} </ul> {% endif %} {% endwith %} {% block body %}{% endblock %} ``` Here is the `index.html` template which inherits from `layout.html`: ``` {% extends "layout.html" %} {% block body %} <h1>Overview</h1> <p>Do you want to <a href="{{ url_for('login') }}">log in?</a> {% endblock %} ``` And here is the `login.html` template which also inherits from `layout.html`: ``` {% extends "layout.html" %} {% block body %} <h1>Login</h1> {% if error %} <p class=error><strong>Error:</strong> {{ error }} {% endif %} <form method=post> <dl> <dt>Username: <dd><input type=text name=username value="{{ request.form.username }}"> <dt>Password: <dd><input type=password name=password> </dl> <p><input type=submit value=Login> </form> {% endblock %} ``` Flashing With Categories ------------------------ Changelog New in version 0.3. It is also possible to provide categories when flashing a message. The default category if nothing is provided is `'message'`. Alternative categories can be used to give the user better feedback. For example error messages could be displayed with a red background. To flash a message with a different category, just use the second argument to the [`flash()`](../../api/index#flask.flash "flask.flash") function: ``` flash('Invalid password provided', 'error') ``` Inside the template you then have to tell the [`get_flashed_messages()`](../../api/index#flask.get_flashed_messages "flask.get_flashed_messages") function to also return the categories. The loop looks slightly different in that situation then: ``` {% with messages = get_flashed_messages(with_categories=true) %} {% if messages %} <ul class=flashes> {% for category, message in messages %} <li class="{{ category }}">{{ message }}</li> {% endfor %} </ul> {% endif %} {% endwith %} ``` This is just one example of how to render these flashed messages. One might also use the category to add a prefix such as `<strong>Error:</strong>` to the message. Filtering Flash Messages ------------------------ Changelog New in version 0.9. Optionally you can pass a list of categories which filters the results of [`get_flashed_messages()`](../../api/index#flask.get_flashed_messages "flask.get_flashed_messages"). This is useful if you wish to render each category in a separate block. ``` {% with errors = get_flashed_messages(category_filter=["error"]) %} {% if errors %} <div class="alert-message block-message error"> <a class="close" href="#">×</a> <ul> {%- for msg in errors %} <li>{{ msg }}</li> {% endfor -%} </ul> </div> {% endif %} {% endwith %} ``` flask View Decorators View Decorators =============== Python has a really interesting feature called function decorators. This allows some really neat things for web applications. Because each view in Flask is a function, decorators can be used to inject additional functionality to one or more functions. The [`route()`](../../api/index#flask.Flask.route "flask.Flask.route") decorator is the one you probably used already. But there are use cases for implementing your own decorator. For instance, imagine you have a view that should only be used by people that are logged in. If a user goes to the site and is not logged in, they should be redirected to the login page. This is a good example of a use case where a decorator is an excellent solution. Login Required Decorator ------------------------ So let’s implement such a decorator. A decorator is a function that wraps and replaces another function. Since the original function is replaced, you need to remember to copy the original function’s information to the new function. Use [`functools.wraps()`](https://docs.python.org/3/library/functools.html#functools.wraps "(in Python v3.10)") to handle this for you. This example assumes that the login page is called `'login'` and that the current user is stored in `g.user` and is `None` if there is no-one logged in. ``` from functools import wraps from flask import g, request, redirect, url_for def login_required(f): @wraps(f) def decorated_function(*args, **kwargs): if g.user is None: return redirect(url_for('login', next=request.url)) return f(*args, **kwargs) return decorated_function ``` To use the decorator, apply it as innermost decorator to a view function. When applying further decorators, always remember that the [`route()`](../../api/index#flask.Flask.route "flask.Flask.route") decorator is the outermost. ``` @app.route('/secret_page') @login_required def secret_page(): pass ``` Note The `next` value will exist in `request.args` after a `GET` request for the login page. You’ll have to pass it along when sending the `POST` request from the login form. You can do this with a hidden input tag, then retrieve it from `request.form` when logging the user in. ``` <input type="hidden" value="{{ request.args.get('next', '') }}"/> ``` Caching Decorator ----------------- Imagine you have a view function that does an expensive calculation and because of that you would like to cache the generated results for a certain amount of time. A decorator would be nice for that. We’re assuming you have set up a cache like mentioned in [Caching](../caching/index). Here is an example cache function. It generates the cache key from a specific prefix (actually a format string) and the current path of the request. Notice that we are using a function that first creates the decorator that then decorates the function. Sounds awful? Unfortunately it is a little bit more complex, but the code should still be straightforward to read. The decorated function will then work as follows 1. get the unique cache key for the current request based on the current path. 2. get the value for that key from the cache. If the cache returned something we will return that value. 3. otherwise the original function is called and the return value is stored in the cache for the timeout provided (by default 5 minutes). Here the code: ``` from functools import wraps from flask import request def cached(timeout=5 * 60, key='view/{}'): def decorator(f): @wraps(f) def decorated_function(*args, **kwargs): cache_key = key.format(request.path) rv = cache.get(cache_key) if rv is not None: return rv rv = f(*args, **kwargs) cache.set(cache_key, rv, timeout=timeout) return rv return decorated_function return decorator ``` Notice that this assumes an instantiated `cache` object is available, see [Caching](../caching/index). Templating Decorator -------------------- A common pattern invented by the TurboGears guys a while back is a templating decorator. The idea of that decorator is that you return a dictionary with the values passed to the template from the view function and the template is automatically rendered. With that, the following three examples do exactly the same: ``` @app.route('/') def index(): return render_template('index.html', value=42) @app.route('/') @templated('index.html') def index(): return dict(value=42) @app.route('/') @templated() def index(): return dict(value=42) ``` As you can see, if no template name is provided it will use the endpoint of the URL map with dots converted to slashes + `'.html'`. Otherwise the provided template name is used. When the decorated function returns, the dictionary returned is passed to the template rendering function. If `None` is returned, an empty dictionary is assumed, if something else than a dictionary is returned we return it from the function unchanged. That way you can still use the redirect function or return simple strings. Here is the code for that decorator: ``` from functools import wraps from flask import request, render_template def templated(template=None): def decorator(f): @wraps(f) def decorated_function(*args, **kwargs): template_name = template if template_name is None: template_name = f"{request.endpoint.replace('.', '/')}.html" ctx = f(*args, **kwargs) if ctx is None: ctx = {} elif not isinstance(ctx, dict): return ctx return render_template(template_name, **ctx) return decorated_function return decorator ``` Endpoint Decorator ------------------ When you want to use the werkzeug routing system for more flexibility you need to map the endpoint as defined in the [`Rule`](https://werkzeug.palletsprojects.com/en/2.2.x/routing/#werkzeug.routing.Rule "(in Werkzeug v2.2.x)") to a view function. This is possible with this decorator. For example: ``` from flask import Flask from werkzeug.routing import Rule app = Flask(__name__) app.url_map.add(Rule('/', endpoint='index')) @app.endpoint('index') def my_index(): return "Hello world" ``` flask Adding a favicon Adding a favicon ================ A “favicon” is an icon used by browsers for tabs and bookmarks. This helps to distinguish your website and to give it a unique brand. A common question is how to add a favicon to a Flask application. First, of course, you need an icon. It should be 16 × 16 pixels and in the ICO file format. This is not a requirement but a de-facto standard supported by all relevant browsers. Put the icon in your static directory as `favicon.ico`. Now, to get browsers to find your icon, the correct way is to add a link tag in your HTML. So, for example: ``` <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}"> ``` That’s all you need for most browsers, however some really old ones do not support this standard. The old de-facto standard is to serve this file, with this name, at the website root. If your application is not mounted at the root path of the domain you either need to configure the web server to serve the icon at the root or if you can’t do that you’re out of luck. If however your application is the root you can simply route a redirect: ``` app.add_url_rule('/favicon.ico', redirect_to=url_for('static', filename='favicon.ico')) ``` If you want to save the extra redirect request you can also write a view using [`send_from_directory()`](../../api/index#flask.send_from_directory "flask.send_from_directory"): ``` import os from flask import send_from_directory @app.route('/favicon.ico') def favicon(): return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico', mimetype='image/vnd.microsoft.icon') ``` We can leave out the explicit mimetype and it will be guessed, but we may as well specify it to avoid the extra guessing, as it will always be the same. The above will serve the icon via your application and if possible it’s better to configure your dedicated web server to serve it; refer to the web server’s documentation. See also -------- * The [Favicon](https://en.wikipedia.org/wiki/Favicon) article on Wikipedia
programming_docs
flask SQLAlchemy in Flask SQLAlchemy in Flask =================== Many people prefer [SQLAlchemy](https://www.sqlalchemy.org/) for database access. In this case it’s encouraged to use a package instead of a module for your flask application and drop the models into a separate module ([Large Applications as Packages](../packages/index)). While that is not necessary, it makes a lot of sense. There are four very common ways to use SQLAlchemy. I will outline each of them here: Flask-SQLAlchemy Extension -------------------------- Because SQLAlchemy is a common database abstraction layer and object relational mapper that requires a little bit of configuration effort, there is a Flask extension that handles that for you. This is recommended if you want to get started quickly. You can download [Flask-SQLAlchemy](https://flask-sqlalchemy.palletsprojects.com/) from [PyPI](https://pypi.org/project/Flask-SQLAlchemy/). Declarative ----------- The declarative extension in SQLAlchemy is the most recent method of using SQLAlchemy. It allows you to define tables and models in one go, similar to how Django works. In addition to the following text I recommend the official documentation on the [declarative](https://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/) extension. Here’s the example `database.py` module for your application: ``` from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker from sqlalchemy.ext.declarative import declarative_base engine = create_engine('sqlite:////tmp/test.db') db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=engine)) Base = declarative_base() Base.query = db_session.query_property() def init_db(): # import all modules here that might define models so that # they will be registered properly on the metadata. Otherwise # you will have to import them first before calling init_db() import yourapplication.models Base.metadata.create_all(bind=engine) ``` To define your models, just subclass the `Base` class that was created by the code above. If you are wondering why we don’t have to care about threads here (like we did in the SQLite3 example above with the [`g`](../../api/index#flask.g "flask.g") object): that’s because SQLAlchemy does that for us already with the `scoped_session`. To use SQLAlchemy in a declarative way with your application, you just have to put the following code into your application module. Flask will automatically remove database sessions at the end of the request or when the application shuts down: ``` from yourapplication.database import db_session @app.teardown_appcontext def shutdown_session(exception=None): db_session.remove() ``` Here is an example model (put this into `models.py`, e.g.): ``` from sqlalchemy import Column, Integer, String from yourapplication.database import Base class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String(50), unique=True) email = Column(String(120), unique=True) def __init__(self, name=None, email=None): self.name = name self.email = email def __repr__(self): return f'<User {self.name!r}>' ``` To create the database you can use the `init_db` function: ``` >>> from yourapplication.database import init_db >>> init_db() ``` You can insert entries into the database like this: ``` >>> from yourapplication.database import db_session >>> from yourapplication.models import User >>> u = User('admin', 'admin@localhost') >>> db_session.add(u) >>> db_session.commit() ``` Querying is simple as well: ``` >>> User.query.all() [<User 'admin'>] >>> User.query.filter(User.name == 'admin').first() <User 'admin'> ``` Manual Object Relational Mapping -------------------------------- Manual object relational mapping has a few upsides and a few downsides versus the declarative approach from above. The main difference is that you define tables and classes separately and map them together. It’s more flexible but a little more to type. In general it works like the declarative approach, so make sure to also split up your application into multiple modules in a package. Here is an example `database.py` module for your application: ``` from sqlalchemy import create_engine, MetaData from sqlalchemy.orm import scoped_session, sessionmaker engine = create_engine('sqlite:////tmp/test.db') metadata = MetaData() db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=engine)) def init_db(): metadata.create_all(bind=engine) ``` As in the declarative approach, you need to close the session after each request or application context shutdown. Put this into your application module: ``` from yourapplication.database import db_session @app.teardown_appcontext def shutdown_session(exception=None): db_session.remove() ``` Here is an example table and model (put this into `models.py`): ``` from sqlalchemy import Table, Column, Integer, String from sqlalchemy.orm import mapper from yourapplication.database import metadata, db_session class User(object): query = db_session.query_property() def __init__(self, name=None, email=None): self.name = name self.email = email def __repr__(self): return f'<User {self.name!r}>' users = Table('users', metadata, Column('id', Integer, primary_key=True), Column('name', String(50), unique=True), Column('email', String(120), unique=True) ) mapper(User, users) ``` Querying and inserting works exactly the same as in the example above. SQL Abstraction Layer --------------------- If you just want to use the database system (and SQL) abstraction layer you basically only need the engine: ``` from sqlalchemy import create_engine, MetaData, Table engine = create_engine('sqlite:////tmp/test.db') metadata = MetaData(bind=engine) ``` Then you can either declare the tables in your code like in the examples above, or automatically load them: ``` from sqlalchemy import Table users = Table('users', metadata, autoload=True) ``` To insert data you can use the `insert` method. We have to get a connection first so that we can use a transaction: ``` >>> con = engine.connect() >>> con.execute(users.insert(), name='admin', email='admin@localhost') ``` SQLAlchemy will automatically commit for us. To query your database, you use the engine directly or use a connection: ``` >>> users.select(users.c.id == 1).execute().first() (1, 'admin', 'admin@localhost') ``` These results are also dict-like tuples: ``` >>> r = users.select(users.c.id == 1).execute().first() >>> r['name'] 'admin' ``` You can also pass strings of SQL statements to the `execute()` method: ``` >>> engine.execute('select * from users where id = :1', [1]).first() (1, 'admin', 'admin@localhost') ``` For more information about SQLAlchemy, head over to the [website](https://www.sqlalchemy.org/). flask Streaming Contents Streaming Contents ================== Sometimes you want to send an enormous amount of data to the client, much more than you want to keep in memory. When you are generating the data on the fly though, how do you send that back to the client without the roundtrip to the filesystem? The answer is by using generators and direct responses. Basic Usage ----------- This is a basic view function that generates a lot of CSV data on the fly. The trick is to have an inner function that uses a generator to generate data and to then invoke that function and pass it to a response object: ``` @app.route('/large.csv') def generate_large_csv(): def generate(): for row in iter_all_rows(): yield f"{','.join(row)}\n" return generate(), {"Content-Type": "text/csv"} ``` Each `yield` expression is directly sent to the browser. Note though that some WSGI middlewares might break streaming, so be careful there in debug environments with profilers and other things you might have enabled. Streaming from Templates ------------------------ The Jinja2 template engine supports rendering a template piece by piece, returning an iterator of strings. Flask provides the [`stream_template()`](../../api/index#flask.stream_template "flask.stream_template") and [`stream_template_string()`](../../api/index#flask.stream_template_string "flask.stream_template_string") functions to make this easier to use. ``` from flask import stream_template @app.get("/timeline") def timeline(): return stream_template("timeline.html") ``` The parts yielded by the render stream tend to match statement blocks in the template. Streaming with Context ---------------------- The [`request`](../../api/index#flask.request "flask.request") will not be active while the generator is running, because the view has already returned at that point. If you try to access `request`, you’ll get a `RuntimeError`. If your generator function relies on data in `request`, use the [`stream_with_context()`](../../api/index#flask.stream_with_context "flask.stream_with_context") wrapper. This will keep the request context active during the generator. ``` from flask import stream_with_context, request from markupsafe import escape @app.route('/stream') def streamed_response(): def generate(): yield '<p>Hello ' yield escape(request.args['name']) yield '!</p>' return stream_with_context(generate()) ``` It can also be used as a decorator. ``` @stream_with_context def generate(): ... return generate() ``` The [`stream_template()`](../../api/index#flask.stream_template "flask.stream_template") and [`stream_template_string()`](../../api/index#flask.stream_template_string "flask.stream_template_string") functions automatically use [`stream_with_context()`](../../api/index#flask.stream_with_context "flask.stream_with_context") if a request is active. flask Deferred Request Callbacks Deferred Request Callbacks ========================== One of the design principles of Flask is that response objects are created and passed down a chain of potential callbacks that can modify them or replace them. When the request handling starts, there is no response object yet. It is created as necessary either by a view function or by some other component in the system. What happens if you want to modify the response at a point where the response does not exist yet? A common example for that would be a [`before_request()`](../../api/index#flask.Flask.before_request "flask.Flask.before_request") callback that wants to set a cookie on the response object. One way is to avoid the situation. Very often that is possible. For instance you can try to move that logic into a [`after_request()`](../../api/index#flask.Flask.after_request "flask.Flask.after_request") callback instead. However, sometimes moving code there makes it more complicated or awkward to reason about. As an alternative, you can use [`after_this_request()`](../../api/index#flask.after_this_request "flask.after_this_request") to register callbacks that will execute after only the current request. This way you can defer code execution from anywhere in the application, based on the current request. At any time during a request, we can register a function to be called at the end of the request. For example you can remember the current language of the user in a cookie in a [`before_request()`](../../api/index#flask.Flask.before_request "flask.Flask.before_request") callback: ``` from flask import request, after_this_request @app.before_request def detect_user_language(): language = request.cookies.get('user_lang') if language is None: language = guess_language_from_request() # when the response exists, set a cookie with the language @after_this_request def remember_language(response): response.set_cookie('user_lang', language) return response g.language = language ``` flask Using URL Processors Using URL Processors ==================== Changelog New in version 0.7. Flask 0.7 introduces the concept of URL processors. The idea is that you might have a bunch of resources with common parts in the URL that you don’t always explicitly want to provide. For instance you might have a bunch of URLs that have the language code in it but you don’t want to have to handle it in every single function yourself. URL processors are especially helpful when combined with blueprints. We will handle both application specific URL processors here as well as blueprint specifics. Internationalized Application URLs ---------------------------------- Consider an application like this: ``` from flask import Flask, g app = Flask(__name__) @app.route('/<lang_code>/') def index(lang_code): g.lang_code = lang_code ... @app.route('/<lang_code>/about') def about(lang_code): g.lang_code = lang_code ... ``` This is an awful lot of repetition as you have to handle the language code setting on the [`g`](../../api/index#flask.g "flask.g") object yourself in every single function. Sure, a decorator could be used to simplify this, but if you want to generate URLs from one function to another you would have to still provide the language code explicitly which can be annoying. For the latter, this is where [`url_defaults()`](../../api/index#flask.Flask.url_defaults "flask.Flask.url_defaults") functions come in. They can automatically inject values into a call to [`url_for()`](../../api/index#flask.url_for "flask.url_for"). The code below checks if the language code is not yet in the dictionary of URL values and if the endpoint wants a value named `'lang_code'`: ``` @app.url_defaults def add_language_code(endpoint, values): if 'lang_code' in values or not g.lang_code: return if app.url_map.is_endpoint_expecting(endpoint, 'lang_code'): values['lang_code'] = g.lang_code ``` The method [`is_endpoint_expecting()`](https://werkzeug.palletsprojects.com/en/2.2.x/routing/#werkzeug.routing.Map.is_endpoint_expecting "(in Werkzeug v2.2.x)") of the URL map can be used to figure out if it would make sense to provide a language code for the given endpoint. The reverse of that function are [`url_value_preprocessor()`](../../api/index#flask.Flask.url_value_preprocessor "flask.Flask.url_value_preprocessor")s. They are executed right after the request was matched and can execute code based on the URL values. The idea is that they pull information out of the values dictionary and put it somewhere else: ``` @app.url_value_preprocessor def pull_lang_code(endpoint, values): g.lang_code = values.pop('lang_code', None) ``` That way you no longer have to do the `lang_code` assignment to [`g`](../../api/index#flask.g "flask.g") in every function. You can further improve that by writing your own decorator that prefixes URLs with the language code, but the more beautiful solution is using a blueprint. Once the `'lang_code'` is popped from the values dictionary and it will no longer be forwarded to the view function reducing the code to this: ``` from flask import Flask, g app = Flask(__name__) @app.url_defaults def add_language_code(endpoint, values): if 'lang_code' in values or not g.lang_code: return if app.url_map.is_endpoint_expecting(endpoint, 'lang_code'): values['lang_code'] = g.lang_code @app.url_value_preprocessor def pull_lang_code(endpoint, values): g.lang_code = values.pop('lang_code', None) @app.route('/<lang_code>/') def index(): ... @app.route('/<lang_code>/about') def about(): ... ``` Internationalized Blueprint URLs -------------------------------- Because blueprints can automatically prefix all URLs with a common string it’s easy to automatically do that for every function. Furthermore blueprints can have per-blueprint URL processors which removes a whole lot of logic from the [`url_defaults()`](../../api/index#flask.Flask.url_defaults "flask.Flask.url_defaults") function because it no longer has to check if the URL is really interested in a `'lang_code'` parameter: ``` from flask import Blueprint, g bp = Blueprint('frontend', __name__, url_prefix='/<lang_code>') @bp.url_defaults def add_language_code(endpoint, values): values.setdefault('lang_code', g.lang_code) @bp.url_value_preprocessor def pull_lang_code(endpoint, values): g.lang_code = values.pop('lang_code') @bp.route('/') def index(): ... @bp.route('/about') def about(): ... ``` flask MongoDB with MongoEngine MongoDB with MongoEngine ======================== Using a document database like MongoDB is a common alternative to relational SQL databases. This pattern shows how to use [MongoEngine](http://mongoengine.org), a document mapper library, to integrate with MongoDB. A running MongoDB server and [Flask-MongoEngine](https://flask-mongoengine.readthedocs.io) are required. ``` pip install flask-mongoengine ``` Configuration ------------- Basic setup can be done by defining `MONGODB_SETTINGS` on `app.config` and creating a `MongoEngine` instance. ``` from flask import Flask from flask_mongoengine import MongoEngine app = Flask(__name__) app.config['MONGODB_SETTINGS'] = { "db": "myapp", } db = MongoEngine(app) ``` Mapping Documents ----------------- To declare a model that represents a Mongo document, create a class that inherits from `Document` and declare each of the fields. ``` import mongoengine as me class Movie(me.Document): title = me.StringField(required=True) year = me.IntField() rated = me.StringField() director = me.StringField() actors = me.ListField() ``` If the document has nested fields, use `EmbeddedDocument` to defined the fields of the embedded document and `EmbeddedDocumentField` to declare it on the parent document. ``` class Imdb(me.EmbeddedDocument): imdb_id = me.StringField() rating = me.DecimalField() votes = me.IntField() class Movie(me.Document): ... imdb = me.EmbeddedDocumentField(Imdb) ``` Creating Data ------------- Instantiate your document class with keyword arguments for the fields. You can also assign values to the field attributes after instantiation. Then call `doc.save()`. ``` bttf = Movie(title="Back To The Future", year=1985) bttf.actors = [ "Michael J. Fox", "Christopher Lloyd" ] bttf.imdb = Imdb(imdb_id="tt0088763", rating=8.5) bttf.save() ``` Queries ------- Use the class `objects` attribute to make queries. A keyword argument looks for an equal value on the field. ``` bttf = Movies.objects(title="Back To The Future").get_or_404() ``` Query operators may be used by concatenating them with the field name using a double-underscore. `objects`, and queries returned by calling it, are iterable. ``` some_theron_movie = Movie.objects(actors__in=["Charlize Theron"]).first() for recents in Movie.objects(year__gte=2017): print(recents.title) ``` Documentation ------------- There are many more ways to define and query documents with MongoEngine. For more information, check out the [official documentation](http://mongoengine.org). Flask-MongoEngine adds helpful utilities on top of MongoEngine. Check out their [documentation](https://flask-mongoengine.readthedocs.io) as well. flask Using SQLite 3 with Flask Using SQLite 3 with Flask ========================= In Flask you can easily implement the opening of database connections on demand and closing them when the context dies (usually at the end of the request). Here is a simple example of how you can use SQLite 3 with Flask: ``` import sqlite3 from flask import g DATABASE = '/path/to/database.db' def get_db(): db = getattr(g, '_database', None) if db is None: db = g._database = sqlite3.connect(DATABASE) return db @app.teardown_appcontext def close_connection(exception): db = getattr(g, '_database', None) if db is not None: db.close() ``` Now, to use the database, the application must either have an active application context (which is always true if there is a request in flight) or create an application context itself. At that point the `get_db` function can be used to get the current database connection. Whenever the context is destroyed the database connection will be terminated. Example: ``` @app.route('/') def index(): cur = get_db().cursor() ... ``` Note Please keep in mind that the teardown request and appcontext functions are always executed, even if a before-request handler failed or was never executed. Because of this we have to make sure here that the database is there before we close it. Connect on Demand ----------------- The upside of this approach (connecting on first use) is that this will only open the connection if truly necessary. If you want to use this code outside a request context you can use it in a Python shell by opening the application context by hand: ``` with app.app_context(): # now you can use get_db() ``` Easy Querying ------------- Now in each request handling function you can access `get_db()` to get the current open database connection. To simplify working with SQLite, a row factory function is useful. It is executed for every result returned from the database to convert the result. For instance, in order to get dictionaries instead of tuples, this could be inserted into the `get_db` function we created above: ``` def make_dicts(cursor, row): return dict((cursor.description[idx][0], value) for idx, value in enumerate(row)) db.row_factory = make_dicts ``` This will make the sqlite3 module return dicts for this database connection, which are much nicer to deal with. Even more simply, we could place this in `get_db` instead: ``` db.row_factory = sqlite3.Row ``` This would use Row objects rather than dicts to return the results of queries. These are `namedtuple` s, so we can access them either by index or by key. For example, assuming we have a `sqlite3.Row` called `r` for the rows `id`, `FirstName`, `LastName`, and `MiddleInitial`: ``` >>> # You can get values based on the row's name >>> r['FirstName'] John >>> # Or, you can get them based on index >>> r[1] John # Row objects are also iterable: >>> for value in r: ... print(value) 1 John Doe M ``` Additionally, it is a good idea to provide a query function that combines getting the cursor, executing and fetching the results: ``` def query_db(query, args=(), one=False): cur = get_db().execute(query, args) rv = cur.fetchall() cur.close() return (rv[0] if rv else None) if one else rv ``` This handy little function, in combination with a row factory, makes working with the database much more pleasant than it is by just using the raw cursor and connection objects. Here is how you can use it: ``` for user in query_db('select * from users'): print(user['username'], 'has the id', user['user_id']) ``` Or if you just want a single result: ``` user = query_db('select * from users where username = ?', [the_username], one=True) if user is None: print('No such user') else: print(the_username, 'has the id', user['user_id']) ``` To pass variable parts to the SQL statement, use a question mark in the statement and pass in the arguments as a list. Never directly add them to the SQL statement with string formatting because this makes it possible to attack the application using [SQL Injections](https://en.wikipedia.org/wiki/SQL_injection). Initial Schemas --------------- Relational databases need schemas, so applications often ship a `schema.sql` file that creates the database. It’s a good idea to provide a function that creates the database based on that schema. This function can do that for you: ``` def init_db(): with app.app_context(): db = get_db() with app.open_resource('schema.sql', mode='r') as f: db.cursor().executescript(f.read()) db.commit() ``` You can then create such a database from the Python shell: ``` >>> from yourapplication import init_db >>> init_db() ```
programming_docs
flask Large Applications as Packages Large Applications as Packages ============================== Imagine a simple flask application structure that looks like this: ``` /yourapplication yourapplication.py /static style.css /templates layout.html index.html login.html ... ``` While this is fine for small applications, for larger applications it’s a good idea to use a package instead of a module. The [Tutorial](https://flask.palletsprojects.com/en/2.2.x/tutorial/) is structured to use the package pattern, see the [example code](https://github.com/pallets/flask/tree/2.2.3/examples/tutorial). Simple Packages --------------- To convert that into a larger one, just create a new folder `yourapplication` inside the existing one and move everything below it. Then rename `yourapplication.py` to `__init__.py`. (Make sure to delete all `.pyc` files first, otherwise things would most likely break) You should then end up with something like that: ``` /yourapplication /yourapplication __init__.py /static style.css /templates layout.html index.html login.html ... ``` But how do you run your application now? The naive `python yourapplication/__init__.py` will not work. Let’s just say that Python does not want modules in packages to be the startup file. But that is not a big problem, just add a new file called `setup.py` next to the inner `yourapplication` folder with the following contents: ``` from setuptools import setup setup( name='yourapplication', packages=['yourapplication'], include_package_data=True, install_requires=[ 'flask', ], ) ``` Install your application so it is importable: ``` $ pip install -e . ``` To use the `flask` command and run your application you need to set the `--app` option that tells Flask where to find the application instance: $ flask –app yourapplication run What did we gain from this? Now we can restructure the application a bit into multiple modules. The only thing you have to remember is the following quick checklist: 1. the `Flask` application object creation has to be in the `__init__.py` file. That way each module can import it safely and the `__name__` variable will resolve to the correct package. 2. all the view functions (the ones with a [`route()`](../../api/index#flask.Flask.route "flask.Flask.route") decorator on top) have to be imported in the `__init__.py` file. Not the object itself, but the module it is in. Import the view module **after the application object is created**. Here’s an example `__init__.py`: ``` from flask import Flask app = Flask(__name__) import yourapplication.views ``` And this is what `views.py` would look like: ``` from yourapplication import app @app.route('/') def index(): return 'Hello World!' ``` You should then end up with something like that: ``` /yourapplication setup.py /yourapplication __init__.py views.py /static style.css /templates layout.html index.html login.html ... ``` Circular Imports Every Python programmer hates them, and yet we just added some: circular imports (That’s when two modules depend on each other. In this case `views.py` depends on `__init__.py`). Be advised that this is a bad idea in general but here it is actually fine. The reason for this is that we are not actually using the views in `__init__.py` and just ensuring the module is imported and we are doing that at the bottom of the file. Working with Blueprints ----------------------- If you have larger applications it’s recommended to divide them into smaller groups where each group is implemented with the help of a blueprint. For a gentle introduction into this topic refer to the [Modular Applications with Blueprints](../../blueprints/index) chapter of the documentation. flask Celery Background Tasks Celery Background Tasks ======================= If your application has a long running task, such as processing some uploaded data or sending email, you don’t want to wait for it to finish during a request. Instead, use a task queue to send the necessary data to another process that will run the task in the background while the request returns immediately. Celery is a powerful task queue that can be used for simple background tasks as well as complex multi-stage programs and schedules. This guide will show you how to configure Celery using Flask, but assumes you’ve already read the [First Steps with Celery](https://celery.readthedocs.io/en/latest/getting-started/first-steps-with-celery.html) guide in the Celery documentation. Install ------- Celery is a separate Python package. Install it from PyPI using pip: ``` $ pip install celery ``` Configure --------- The first thing you need is a Celery instance, this is called the celery application. It serves the same purpose as the [`Flask`](../../api/index#flask.Flask "flask.Flask") object in Flask, just for Celery. Since this instance is used as the entry-point for everything you want to do in Celery, like creating tasks and managing workers, it must be possible for other modules to import it. For instance you can place this in a `tasks` module. While you can use Celery without any reconfiguration with Flask, it becomes a bit nicer by subclassing tasks and adding support for Flask’s application contexts and hooking it up with the Flask configuration. This is all that is necessary to integrate Celery with Flask: ``` from celery import Celery def make_celery(app): celery = Celery(app.import_name) celery.conf.update(app.config["CELERY_CONFIG"]) class ContextTask(celery.Task): def __call__(self, *args, **kwargs): with app.app_context(): return self.run(*args, **kwargs) celery.Task = ContextTask return celery ``` The function creates a new Celery object, configures it with the broker from the application config, updates the rest of the Celery config from the Flask config and then creates a subclass of the task that wraps the task execution in an application context. Note Celery 5.x deprecated uppercase configuration keys, and 6.x will remove them. See their official [migration guide](https://docs.celeryproject.org/en/stable/userguide/configuration.html#conf-old-settings-map.). An example task --------------- Let’s write a task that adds two numbers together and returns the result. We configure Celery’s broker and backend to use Redis, create a `celery` application using the factory from above, and then use it to define the task. ``` from flask import Flask flask_app = Flask(__name__) flask_app.config.update(CELERY_CONFIG={ 'broker_url': 'redis://localhost:6379', 'result_backend': 'redis://localhost:6379', }) celery = make_celery(flask_app) @celery.task() def add_together(a, b): return a + b ``` This task can now be called in the background: ``` result = add_together.delay(23, 42) result.wait() # 65 ``` Run a worker ------------ If you jumped in and already executed the above code you will be disappointed to learn that `.wait()` will never actually return. That’s because you also need to run a Celery worker to receive and execute the task. ``` $ celery -A your_application.celery worker ``` The `your_application` string has to point to your application’s package or module that creates the `celery` object. Now that the worker is running, `wait` will return the result once the task is finished. flask Form Validation with WTForms Form Validation with WTForms ============================ When you have to work with form data submitted by a browser view, code quickly becomes very hard to read. There are libraries out there designed to make this process easier to manage. One of them is [WTForms](https://wtforms.readthedocs.io/) which we will handle here. If you find yourself in the situation of having many forms, you might want to give it a try. When you are working with WTForms you have to define your forms as classes first. I recommend breaking up the application into multiple modules ([Large Applications as Packages](../packages/index)) for that and adding a separate module for the forms. Getting the most out of WTForms with an Extension The [Flask-WTF](https://flask-wtf.readthedocs.io/) extension expands on this pattern and adds a few little helpers that make working with forms and Flask more fun. You can get it from [PyPI](https://pypi.org/project/Flask-WTF/). The Forms --------- This is an example form for a typical registration page: ``` from wtforms import Form, BooleanField, StringField, PasswordField, validators class RegistrationForm(Form): username = StringField('Username', [validators.Length(min=4, max=25)]) email = StringField('Email Address', [validators.Length(min=6, max=35)]) password = PasswordField('New Password', [ validators.DataRequired(), validators.EqualTo('confirm', message='Passwords must match') ]) confirm = PasswordField('Repeat Password') accept_tos = BooleanField('I accept the TOS', [validators.DataRequired()]) ``` In the View ----------- In the view function, the usage of this form looks like this: ``` @app.route('/register', methods=['GET', 'POST']) def register(): form = RegistrationForm(request.form) if request.method == 'POST' and form.validate(): user = User(form.username.data, form.email.data, form.password.data) db_session.add(user) flash('Thanks for registering') return redirect(url_for('login')) return render_template('register.html', form=form) ``` Notice we’re implying that the view is using SQLAlchemy here ([SQLAlchemy in Flask](../sqlalchemy/index)), but that’s not a requirement, of course. Adapt the code as necessary. Things to remember: 1. create the form from the request `form` value if the data is submitted via the HTTP `POST` method and `args` if the data is submitted as `GET`. 2. to validate the data, call the `validate()` method, which will return `True` if the data validates, `False` otherwise. 3. to access individual values from the form, access `form.<NAME>.data`. Forms in Templates ------------------ Now to the template side. When you pass the form to the templates, you can easily render them there. Look at the following example template to see how easy this is. WTForms does half the form generation for us already. To make it even nicer, we can write a macro that renders a field with label and a list of errors if there are any. Here’s an example `_formhelpers.html` template with such a macro: ``` {% macro render_field(field) %} <dt>{{ field.label }} <dd>{{ field(**kwargs)|safe }} {% if field.errors %} <ul class=errors> {% for error in field.errors %} <li>{{ error }}</li> {% endfor %} </ul> {% endif %} </dd> {% endmacro %} ``` This macro accepts a couple of keyword arguments that are forwarded to WTForm’s field function, which renders the field for us. The keyword arguments will be inserted as HTML attributes. So, for example, you can call `render_field(form.username, class='username')` to add a class to the input element. Note that WTForms returns standard Python strings, so we have to tell Jinja2 that this data is already HTML-escaped with the `|safe` filter. Here is the `register.html` template for the function we used above, which takes advantage of the `_formhelpers.html` template: ``` {% from "_formhelpers.html" import render_field %} <form method=post> <dl> {{ render_field(form.username) }} {{ render_field(form.email) }} {{ render_field(form.password) }} {{ render_field(form.confirm) }} {{ render_field(form.accept_tos) }} </dl> <p><input type=submit value=Register> </form> ``` For more information about WTForms, head over to the [WTForms website](https://wtforms.readthedocs.io/). flask JavaScript, fetch, and JSON JavaScript, fetch, and JSON =========================== You may want to make your HTML page dynamic, by changing data without reloading the entire page. Instead of submitting an HTML `<form>` and performing a redirect to re-render the template, you can add [JavaScript](https://developer.mozilla.org/Web/JavaScript) that calls [`fetch()`](https://developer.mozilla.org/Web/API/Fetch_API) and replaces content on the page. [`fetch()`](https://developer.mozilla.org/Web/API/Fetch_API) is the modern, built-in JavaScript solution to making requests from a page. You may have heard of other “AJAX” methods and libraries, such as [`XMLHttpRequest()`](https://developer.mozilla.org/Web/API/XMLHttpRequest) or [jQuery](https://jquery.com/). These are no longer needed in modern browsers, although you may choose to use them or another library depending on your application’s requirements. These docs will only focus on built-in JavaScript features. Rendering Templates ------------------- It is important to understand the difference between templates and JavaScript. Templates are rendered on the server, before the response is sent to the user’s browser. JavaScript runs in the user’s browser, after the template is rendered and sent. Therefore, it is impossible to use JavaScript to affect how the Jinja template is rendered, but it is possible to render data into the JavaScript that will run. To provide data to JavaScript when rendering the template, use the [`tojson()`](https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-filters.tojson "(in Jinja v3.1.x)") filter in a `<script>` block. This will convert the data to a valid JavaScript object, and ensure that any unsafe HTML characters are rendered safely. If you do not use the `tojson` filter, you will get a `SyntaxError` in the browser console. ``` data = generate_report() return render_template("report.html", chart_data=data) ``` ``` <script> const chart_data = {{ chart_data|tojson }} chartLib.makeChart(chart_data) </script> ``` A less common pattern is to add the data to a `data-` attribute on an HTML tag. In this case, you must use single quotes around the value, not double quotes, otherwise you will produce invalid or unsafe HTML. ``` <div data-chart='{{ chart_data|tojson }}'></div> ``` Generating URLs --------------- The other way to get data from the server to JavaScript is to make a request for it. First, you need to know the URL to request. The simplest way to generate URLs is to continue to use [`url_for()`](../../api/index#flask.url_for "flask.url_for") when rendering the template. For example: ``` const user_url = {{ url_for("user", id=current_user.id)|tojson }} fetch(user_url).then(...) ``` However, you might need to generate a URL based on information you only know in JavaScript. As discussed above, JavaScript runs in the user’s browser, not as part of the template rendering, so you can’t use `url_for` at that point. In this case, you need to know the “root URL” under which your application is served. In simple setups, this is `/`, but it might also be something else, like `https://example.com/myapp/`. A simple way to tell your JavaScript code about this root is to set it as a global variable when rendering the template. Then you can use it when generating URLs from JavaScript. ``` const SCRIPT_ROOT = {{ request.script_root|tojson }} let user_id = ... // do something to get a user id from the page let user_url = `${SCRIPT_ROOT}/user/${user_id}` fetch(user_url).then(...) ``` Making a Request with `fetch` ----------------------------- [`fetch()`](https://developer.mozilla.org/Web/API/Fetch_API) takes two arguments, a URL and an object with other options, and returns a [`Promise`](https://developer.mozilla.org/Web/JavaScript/Reference/Global_Objects/Promise). We won’t cover all the available options, and will only use `then()` on the promise, not other callbacks or `await` syntax. Read the linked MDN docs for more information about those features. By default, the GET method is used. If the response contains JSON, it can be used with a `then()` callback chain. ``` const room_url = {{ url_for("room_detail", id=room.id)|tojson }} fetch(room_url) .then(response => response.json()) .then(data => { // data is a parsed JSON object }) ``` To send data, use a data method such as POST, and pass the `body` option. The most common types for data are form data or JSON data. To send form data, pass a populated [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) object. This uses the same format as an HTML form, and would be accessed with `request.form` in a Flask view. ``` let data = new FormData() data.append("name": "Flask Room") data.append("description": "Talk about Flask here.") fetch(room_url, { "method": "POST", "body": data, }).then(...) ``` In general, prefer sending request data as form data, as would be used when submitting an HTML form. JSON can represent more complex data, but unless you need that it’s better to stick with the simpler format. When sending JSON data, the `Content-Type: application/json` header must be sent as well, otherwise Flask will return a 400 error. ``` let data = { "name": "Flask Room", "description": "Talk about Flask here.", } fetch(room_url, { "method": "POST", "headers": {"Content-Type": "application/json"}, "body": JSON.stringify(data), }).then(...) ``` Following Redirects ------------------- A response might be a redirect, for example if you logged in with JavaScript instead of a traditional HTML form, and your view returned a redirect instead of JSON. JavaScript requests do follow redirects, but they don’t change the page. If you want to make the page change you can inspect the response and apply the redirect manually. ``` fetch("/login", {"body": ...}).then( response => { if (response.redirected) { window.location = response.url } else { showLoginError() } } ) ``` Replacing Content ----------------- A response might be new HTML, either a new section of the page to add or replace, or an entirely new page. In general, if you’re returning the entire page, it would be better to handle that with a redirect as shown in the previous section. The following example shows how to replace a `<div>` with the HTML returned by a request. ``` <div id="geology-fact"> {{ include "geology_fact.html" }} </div> <script> const geology_url = {{ url_for("geology_fact")|tojson }} const geology_div = getElementById("geology-fact") fetch(geology_url) .then(response => response.text) .then(text => geology_div.innerHtml = text) </script> ``` Return JSON from Views ---------------------- To return a JSON object from your API view, you can directly return a dict from the view. It will be serialized to JSON automatically. ``` @app.route("/user/<int:id>") def user_detail(id): user = User.query.get_or_404(id) return { "username": User.username, "email": User.email, "picture": url_for("static", filename=f"users/{id}/profile.png"), } ``` If you want to return another JSON type, use the [`jsonify()`](../../api/index#flask.json.jsonify "flask.json.jsonify") function, which creates a response object with the given data serialized to JSON. ``` from flask import jsonify @app.route("/users") def user_list(): users = User.query.order_by(User.name).all() return jsonify([u.to_json() for u in users]) ``` It is usually not a good idea to return file data in a JSON response. JSON cannot represent binary data directly, so it must be base64 encoded, which can be slow, takes more bandwidth to send, and is not as easy to cache. Instead, serve files using one view, and generate a URL to the desired file to include in the JSON. Then the client can make a separate request to get the linked resource after getting the JSON. Receiving JSON in Views ----------------------- Use the [`json`](../../api/index#flask.Request.json "flask.Request.json") property of the [`request`](../../api/index#flask.request "flask.request") object to decode the request’s body as JSON. If the body is not valid JSON, or the `Content-Type` header is not set to `application/json`, a 400 Bad Request error will be raised. ``` from flask import request @app.post("/user/<int:id>") def user_update(id): user = User.query.get_or_404(id) user.update_from_json(request.json) db.session.commit() return user.to_json() ```
programming_docs
flask Caching Caching ======= When your application runs slow, throw some caches in. Well, at least it’s the easiest way to speed up things. What does a cache do? Say you have a function that takes some time to complete but the results would still be good enough if they were 5 minutes old. So then the idea is that you actually put the result of that calculation into a cache for some time. Flask itself does not provide caching for you, but [Flask-Caching](https://flask-caching.readthedocs.io/en/latest/), an extension for Flask does. Flask-Caching supports various backends, and it is even possible to develop your own caching backend. flask Single-Page Applications Single-Page Applications ======================== Flask can be used to serve Single-Page Applications (SPA) by placing static files produced by your frontend framework in a subfolder inside of your project. You will also need to create a catch-all endpoint that routes all requests to your SPA. The following example demonstrates how to serve an SPA along with an API: ``` from flask import Flask, jsonify app = Flask(__name__, static_folder='app', static_url_path="/app") @app.route("/heartbeat") def heartbeat(): return jsonify({"status": "healthy"}) @app.route('/', defaults={'path': ''}) @app.route('/<path:path>') def catch_all(path): return app.send_static_file("index.html") ``` flask Subclassing Flask Subclassing Flask ================= The [`Flask`](../../api/index#flask.Flask "flask.Flask") class is designed for subclassing. For example, you may want to override how request parameters are handled to preserve their order: ``` from flask import Flask, Request from werkzeug.datastructures import ImmutableOrderedMultiDict class MyRequest(Request): """Request subclass to override request parameter storage""" parameter_storage_class = ImmutableOrderedMultiDict class MyFlask(Flask): """Flask subclass using the custom request class""" request_class = MyRequest ``` This is the recommended approach for overriding or augmenting Flask’s internal functionality. flask Application Factories Application Factories ===================== If you are already using packages and blueprints for your application ([Modular Applications with Blueprints](../../blueprints/index)) there are a couple of really nice ways to further improve the experience. A common pattern is creating the application object when the blueprint is imported. But if you move the creation of this object into a function, you can then create multiple instances of this app later. So why would you want to do this? 1. Testing. You can have instances of the application with different settings to test every case. 2. Multiple instances. Imagine you want to run different versions of the same application. Of course you could have multiple instances with different configs set up in your webserver, but if you use factories, you can have multiple instances of the same application running in the same application process which can be handy. So how would you then actually implement that? Basic Factories --------------- The idea is to set up the application in a function. Like this: ``` def create_app(config_filename): app = Flask(__name__) app.config.from_pyfile(config_filename) from yourapplication.model import db db.init_app(app) from yourapplication.views.admin import admin from yourapplication.views.frontend import frontend app.register_blueprint(admin) app.register_blueprint(frontend) return app ``` The downside is that you cannot use the application object in the blueprints at import time. You can however use it from within a request. How do you get access to the application with the config? Use [`current_app`](../../api/index#flask.current_app "flask.current_app"): ``` from flask import current_app, Blueprint, render_template admin = Blueprint('admin', __name__, url_prefix='/admin') @admin.route('/') def index(): return render_template(current_app.config['INDEX_TEMPLATE']) ``` Here we look up the name of a template in the config. Factories & Extensions ---------------------- It’s preferable to create your extensions and app factories so that the extension object does not initially get bound to the application. Using [Flask-SQLAlchemy](https://flask-sqlalchemy.palletsprojects.com/), as an example, you should not do something along those lines: ``` def create_app(config_filename): app = Flask(__name__) app.config.from_pyfile(config_filename) db = SQLAlchemy(app) ``` But, rather, in model.py (or equivalent): ``` db = SQLAlchemy() ``` and in your application.py (or equivalent): ``` def create_app(config_filename): app = Flask(__name__) app.config.from_pyfile(config_filename) from yourapplication.model import db db.init_app(app) ``` Using this design pattern, no application-specific state is stored on the extension object, so one extension object can be used for multiple apps. For more information about the design of extensions refer to [Flask Extension Development](https://flask.palletsprojects.com/en/2.2.x/extensiondev/). Using Applications ------------------ To run such an application, you can use the **flask** command: ``` $ flask run --app hello run ``` Flask will automatically detect the factory if it is named `create_app` or `make_app` in `hello`. You can also pass arguments to the factory like this: ``` $ flask run --app hello:create_app(local_auth=True)`` ``` Then the `create_app` factory in `myapp` is called with the keyword argument `local_auth=True`. See [Command Line Interface](../../cli/index) for more detail. Factory Improvements -------------------- The factory function above is not very clever, but you can improve it. The following changes are straightforward to implement: 1. Make it possible to pass in configuration values for unit tests so that you don’t have to create config files on the filesystem. 2. Call a function from a blueprint when the application is setting up so that you have a place to modify attributes of the application (like hooking in before/after request handlers etc.) 3. Add in WSGI middlewares when the application is being created if necessary. flask Lazily Loading Views Lazily Loading Views ==================== Flask is usually used with the decorators. Decorators are simple and you have the URL right next to the function that is called for that specific URL. However there is a downside to this approach: it means all your code that uses decorators has to be imported upfront or Flask will never actually find your function. This can be a problem if your application has to import quick. It might have to do that on systems like Google’s App Engine or other systems. So if you suddenly notice that your application outgrows this approach you can fall back to a centralized URL mapping. The system that enables having a central URL map is the [`add_url_rule()`](../../api/index#flask.Flask.add_url_rule "flask.Flask.add_url_rule") function. Instead of using decorators, you have a file that sets up the application with all URLs. Converting to Centralized URL Map --------------------------------- Imagine the current application looks somewhat like this: ``` from flask import Flask app = Flask(__name__) @app.route('/') def index(): pass @app.route('/user/<username>') def user(username): pass ``` Then, with the centralized approach you would have one file with the views (`views.py`) but without any decorator: ``` def index(): pass def user(username): pass ``` And then a file that sets up an application which maps the functions to URLs: ``` from flask import Flask from yourapplication import views app = Flask(__name__) app.add_url_rule('/', view_func=views.index) app.add_url_rule('/user/<username>', view_func=views.user) ``` Loading Late ------------ So far we only split up the views and the routing, but the module is still loaded upfront. The trick is to actually load the view function as needed. This can be accomplished with a helper class that behaves just like a function but internally imports the real function on first use: ``` from werkzeug.utils import import_string, cached_property class LazyView(object): def __init__(self, import_name): self.__module__, self.__name__ = import_name.rsplit('.', 1) self.import_name = import_name @cached_property def view(self): return import_string(self.import_name) def __call__(self, *args, **kwargs): return self.view(*args, **kwargs) ``` What’s important here is is that `__module__` and `__name__` are properly set. This is used by Flask internally to figure out how to name the URL rules in case you don’t provide a name for the rule yourself. Then you can define your central place to combine the views like this: ``` from flask import Flask from yourapplication.helpers import LazyView app = Flask(__name__) app.add_url_rule('/', view_func=LazyView('yourapplication.views.index')) app.add_url_rule('/user/<username>', view_func=LazyView('yourapplication.views.user')) ``` You can further optimize this in terms of amount of keystrokes needed to write this by having a function that calls into [`add_url_rule()`](../../api/index#flask.Flask.add_url_rule "flask.Flask.add_url_rule") by prefixing a string with the project name and a dot, and by wrapping `view_func` in a `LazyView` as needed. ``` def url(import_name, url_rules=[], **options): view = LazyView(f"yourapplication.{import_name}") for url_rule in url_rules: app.add_url_rule(url_rule, view_func=view, **options) # add a single route to the index view url('views.index', ['/']) # add two routes to a single function endpoint url_rules = ['/user/','/user/<username>'] url('views.user', url_rules) ``` One thing to keep in mind is that before and after request handlers have to be in a file that is imported upfront to work properly on the first request. The same goes for any kind of remaining decorator. flask Application Dispatching Application Dispatching ======================= Application dispatching is the process of combining multiple Flask applications on the WSGI level. You can combine not only Flask applications but any WSGI application. This would allow you to run a Django and a Flask application in the same interpreter side by side if you want. The usefulness of this depends on how the applications work internally. The fundamental difference from [Large Applications as Packages](../packages/index) is that in this case you are running the same or different Flask applications that are entirely isolated from each other. They run different configurations and are dispatched on the WSGI level. Working with this Document -------------------------- Each of the techniques and examples below results in an `application` object that can be run with any WSGI server. For production, see [Deploying to Production](../../deploying/index). For development, Werkzeug provides a server through [`werkzeug.serving.run_simple()`](https://werkzeug.palletsprojects.com/en/2.2.x/serving/#werkzeug.serving.run_simple "(in Werkzeug v2.2.x)"): ``` from werkzeug.serving import run_simple run_simple('localhost', 5000, application, use_reloader=True) ``` Note that [`run_simple`](https://werkzeug.palletsprojects.com/en/2.2.x/serving/#werkzeug.serving.run_simple "(in Werkzeug v2.2.x)") is not intended for use in production. Use a production WSGI server. See [Deploying to Production](../../deploying/index). In order to use the interactive debugger, debugging must be enabled both on the application and the simple server. Here is the “hello world” example with debugging and [`run_simple`](https://werkzeug.palletsprojects.com/en/2.2.x/serving/#werkzeug.serving.run_simple "(in Werkzeug v2.2.x)"): ``` from flask import Flask from werkzeug.serving import run_simple app = Flask(__name__) app.debug = True @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': run_simple('localhost', 5000, app, use_reloader=True, use_debugger=True, use_evalex=True) ``` Combining Applications ---------------------- If you have entirely separated applications and you want them to work next to each other in the same Python interpreter process you can take advantage of the `werkzeug.wsgi.DispatcherMiddleware`. The idea here is that each Flask application is a valid WSGI application and they are combined by the dispatcher middleware into a larger one that is dispatched based on prefix. For example you could have your main application run on `/` and your backend interface on `/backend`: ``` from werkzeug.middleware.dispatcher import DispatcherMiddleware from frontend_app import application as frontend from backend_app import application as backend application = DispatcherMiddleware(frontend, { '/backend': backend }) ``` Dispatch by Subdomain --------------------- Sometimes you might want to use multiple instances of the same application with different configurations. Assuming the application is created inside a function and you can call that function to instantiate it, that is really easy to implement. In order to develop your application to support creating new instances in functions have a look at the [Application Factories](../appfactories/index) pattern. A very common example would be creating applications per subdomain. For instance you configure your webserver to dispatch all requests for all subdomains to your application and you then use the subdomain information to create user-specific instances. Once you have your server set up to listen on all subdomains you can use a very simple WSGI application to do the dynamic application creation. The perfect level for abstraction in that regard is the WSGI layer. You write your own WSGI application that looks at the request that comes and delegates it to your Flask application. If that application does not exist yet, it is dynamically created and remembered: ``` from threading import Lock class SubdomainDispatcher(object): def __init__(self, domain, create_app): self.domain = domain self.create_app = create_app self.lock = Lock() self.instances = {} def get_application(self, host): host = host.split(':')[0] assert host.endswith(self.domain), 'Configuration error' subdomain = host[:-len(self.domain)].rstrip('.') with self.lock: app = self.instances.get(subdomain) if app is None: app = self.create_app(subdomain) self.instances[subdomain] = app return app def __call__(self, environ, start_response): app = self.get_application(environ['HTTP_HOST']) return app(environ, start_response) ``` This dispatcher can then be used like this: ``` from myapplication import create_app, get_user_for_subdomain from werkzeug.exceptions import NotFound def make_app(subdomain): user = get_user_for_subdomain(subdomain) if user is None: # if there is no user for that subdomain we still have # to return a WSGI application that handles that request. # We can then just return the NotFound() exception as # application which will render a default 404 page. # You might also redirect the user to the main page then return NotFound() # otherwise create the application for the specific user return create_app(user) application = SubdomainDispatcher('example.com', make_app) ``` Dispatch by Path ---------------- Dispatching by a path on the URL is very similar. Instead of looking at the `Host` header to figure out the subdomain one simply looks at the request path up to the first slash: ``` from threading import Lock from werkzeug.wsgi import pop_path_info, peek_path_info class PathDispatcher(object): def __init__(self, default_app, create_app): self.default_app = default_app self.create_app = create_app self.lock = Lock() self.instances = {} def get_application(self, prefix): with self.lock: app = self.instances.get(prefix) if app is None: app = self.create_app(prefix) if app is not None: self.instances[prefix] = app return app def __call__(self, environ, start_response): app = self.get_application(peek_path_info(environ)) if app is not None: pop_path_info(environ) else: app = self.default_app return app(environ, start_response) ``` The big difference between this and the subdomain one is that this one falls back to another application if the creator function returns `None`: ``` from myapplication import create_app, default_app, get_user_for_prefix def make_app(prefix): user = get_user_for_prefix(prefix) if user is not None: return create_app(user) application = PathDispatcher(default_app, make_app) ``` flask Configuration Handling Configuration Handling ====================== Applications need some kind of configuration. There are different settings you might want to change depending on the application environment like toggling the debug mode, setting the secret key, and other such environment-specific things. The way Flask is designed usually requires the configuration to be available when the application starts up. You can hard code the configuration in the code, which for many small applications is not actually that bad, but there are better ways. Independent of how you load your config, there is a config object available which holds the loaded configuration values: The [`config`](../api/index#flask.Flask.config "flask.Flask.config") attribute of the [`Flask`](../api/index#flask.Flask "flask.Flask") object. This is the place where Flask itself puts certain configuration values and also where extensions can put their configuration values. But this is also where you can have your own configuration. Configuration Basics -------------------- The [`config`](../api/index#flask.Flask.config "flask.Flask.config") is actually a subclass of a dictionary and can be modified just like any dictionary: ``` app = Flask(__name__) app.config['TESTING'] = True ``` Certain configuration values are also forwarded to the [`Flask`](../api/index#flask.Flask "flask.Flask") object so you can read and write them from there: ``` app.testing = True ``` To update multiple keys at once you can use the [`dict.update()`](https://docs.python.org/3/library/stdtypes.html#dict.update "(in Python v3.10)") method: ``` app.config.update( TESTING=True, SECRET_KEY='192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf' ) ``` Debug Mode ---------- The [`DEBUG`](#DEBUG "DEBUG") config value is special because it may behave inconsistently if changed after the app has begun setting up. In order to set debug mode reliably, use the `--debug` option on the `flask` command.``flask run`` will use the interactive debugger and reloader by default in debug mode. ``` $ flask --app hello --debug run ``` Using the option is recommended. While it is possible to set [`DEBUG`](#DEBUG "DEBUG") in your config or code, this is strongly discouraged. It can’t be read early by the `flask` command, and some systems or extensions may have already configured themselves based on a previous value. Builtin Configuration Values ---------------------------- The following configuration values are used internally by Flask: `ENV` What environment the app is running in. The [`env`](../api/index#flask.Flask.env "flask.Flask.env") attribute maps to this config key. Default: `'production'` Deprecated since version 2.2: Will be removed in Flask 2.3. Use `--debug` instead. Changelog New in version 1.0. `DEBUG` Whether debug mode is enabled. When using `flask run` to start the development server, an interactive debugger will be shown for unhandled exceptions, and the server will be reloaded when code changes. The [`debug`](../api/index#flask.Flask.debug "flask.Flask.debug") attribute maps to this config key. This is set with the `FLASK_DEBUG` environment variable. It may not behave as expected if set in code. **Do not enable debug mode when deploying in production.** Default: `False` `TESTING` Enable testing mode. Exceptions are propagated rather than handled by the the app’s error handlers. Extensions may also change their behavior to facilitate easier testing. You should enable this in your own tests. Default: `False` `PROPAGATE_EXCEPTIONS` Exceptions are re-raised rather than being handled by the app’s error handlers. If not set, this is implicitly true if `TESTING` or `DEBUG` is enabled. Default: `None` `TRAP_HTTP_EXCEPTIONS` If there is no handler for an `HTTPException`-type exception, re-raise it to be handled by the interactive debugger instead of returning it as a simple error response. Default: `False` `TRAP_BAD_REQUEST_ERRORS` Trying to access a key that doesn’t exist from request dicts like `args` and `form` will return a 400 Bad Request error page. Enable this to treat the error as an unhandled exception instead so that you get the interactive debugger. This is a more specific version of `TRAP_HTTP_EXCEPTIONS`. If unset, it is enabled in debug mode. Default: `None` `SECRET_KEY` A secret key that will be used for securely signing the session cookie and can be used for any other security related needs by extensions or your application. It should be a long random `bytes` or `str`. For example, copy the output of this to your config: ``` $ python -c 'import secrets; print(secrets.token_hex())' '192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf' ``` **Do not reveal the secret key when posting questions or committing code.** Default: `None` `SESSION_COOKIE_NAME` The name of the session cookie. Can be changed in case you already have a cookie with the same name. Default: `'session'` `SESSION_COOKIE_DOMAIN` The domain match rule that the session cookie will be valid for. If not set, the cookie will be valid for all subdomains of [`SERVER_NAME`](#SERVER_NAME "SERVER_NAME"). If `False`, the cookie’s domain will not be set. Default: `None` `SESSION_COOKIE_PATH` The path that the session cookie will be valid for. If not set, the cookie will be valid underneath `APPLICATION_ROOT` or `/` if that is not set. Default: `None` `SESSION_COOKIE_HTTPONLY` Browsers will not allow JavaScript access to cookies marked as “HTTP only” for security. Default: `True` `SESSION_COOKIE_SECURE` Browsers will only send cookies with requests over HTTPS if the cookie is marked “secure”. The application must be served over HTTPS for this to make sense. Default: `False` `SESSION_COOKIE_SAMESITE` Restrict how cookies are sent with requests from external sites. Can be set to `'Lax'` (recommended) or `'Strict'`. See [Set-Cookie options](../security/index#security-cookie). Default: `None` Changelog New in version 1.0. `PERMANENT_SESSION_LIFETIME` If `session.permanent` is true, the cookie’s expiration will be set this number of seconds in the future. Can either be a [`datetime.timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta "(in Python v3.10)") or an `int`. Flask’s default cookie implementation validates that the cryptographic signature is not older than this value. Default: `timedelta(days=31)` (`2678400` seconds) `SESSION_REFRESH_EACH_REQUEST` Control whether the cookie is sent with every response when `session.permanent` is true. Sending the cookie every time (the default) can more reliably keep the session from expiring, but uses more bandwidth. Non-permanent sessions are not affected. Default: `True` `USE_X_SENDFILE` When serving files, set the `X-Sendfile` header instead of serving the data with Flask. Some web servers, such as Apache, recognize this and serve the data more efficiently. This only makes sense when using such a server. Default: `False` `SEND_FILE_MAX_AGE_DEFAULT` When serving files, set the cache control max age to this number of seconds. Can be a [`datetime.timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta "(in Python v3.10)") or an `int`. Override this value on a per-file basis using [`get_send_file_max_age()`](../api/index#flask.Flask.get_send_file_max_age "flask.Flask.get_send_file_max_age") on the application or blueprint. If `None`, `send_file` tells the browser to use conditional requests will be used instead of a timed cache, which is usually preferable. Default: `None` `SERVER_NAME` Inform the application what host and port it is bound to. Required for subdomain route matching support. If set, will be used for the session cookie domain if [`SESSION_COOKIE_DOMAIN`](#SESSION_COOKIE_DOMAIN "SESSION_COOKIE_DOMAIN") is not set. Modern web browsers will not allow setting cookies for domains without a dot. To use a domain locally, add any names that should route to the app to your `hosts` file. ``` 127.0.0.1 localhost.dev ``` If set, `url_for` can generate external URLs with only an application context instead of a request context. Default: `None` `APPLICATION_ROOT` Inform the application what path it is mounted under by the application / web server. This is used for generating URLs outside the context of a request (inside a request, the dispatcher is responsible for setting `SCRIPT_NAME` instead; see [Application Dispatching](../patterns/appdispatch/index) for examples of dispatch configuration). Will be used for the session cookie path if `SESSION_COOKIE_PATH` is not set. Default: `'/'` `PREFERRED_URL_SCHEME` Use this scheme for generating external URLs when not in a request context. Default: `'http'` `MAX_CONTENT_LENGTH` Don’t read more than this many bytes from the incoming request data. If not set and the request does not specify a `CONTENT_LENGTH`, no data will be read for security. Default: `None` `JSON_AS_ASCII` Serialize objects to ASCII-encoded JSON. If this is disabled, the JSON returned from `jsonify` will contain Unicode characters. This has security implications when rendering the JSON into JavaScript in templates, and should typically remain enabled. Default: `True` Deprecated since version 2.2: Will be removed in Flask 2.3. Set `app.json.ensure_ascii` instead. `JSON_SORT_KEYS` Sort the keys of JSON objects alphabetically. This is useful for caching because it ensures the data is serialized the same way no matter what Python’s hash seed is. While not recommended, you can disable this for a possible performance improvement at the cost of caching. Default: `True` Deprecated since version 2.2: Will be removed in Flask 2.3. Set `app.json.sort_keys` instead. `JSONIFY_PRETTYPRINT_REGULAR` `jsonify()` responses will be output with newlines, spaces, and indentation for easier reading by humans. Always enabled in debug mode. Default: `False` Deprecated since version 2.2: Will be removed in Flask 2.3. Set `app.json.compact` instead. `JSONIFY_MIMETYPE` The mimetype of `jsonify` responses. Default: `'application/json'` Deprecated since version 2.2: Will be removed in Flask 2.3. Set `app.json.mimetype` instead. `TEMPLATES_AUTO_RELOAD` Reload templates when they are changed. If not set, it will be enabled in debug mode. Default: `None` `EXPLAIN_TEMPLATE_LOADING` Log debugging information tracing how a template file was loaded. This can be useful to figure out why a template was not loaded or the wrong file appears to be loaded. Default: `False` `MAX_COOKIE_SIZE` Warn if cookie headers are larger than this many bytes. Defaults to `4093`. Larger cookies may be silently ignored by browsers. Set to `0` to disable the warning. Changed in version 2.2: Removed `PRESERVE_CONTEXT_ON_EXCEPTION`. Changed in version 2.2: `JSON_AS_ASCII`, `JSON_SORT_KEYS`, `JSONIFY_MIMETYPE`, and `JSONIFY_PRETTYPRINT_REGULAR` will be removed in Flask 2.3. The default `app.json` provider has equivalent attributes instead. Changed in version 2.2: `ENV` will be removed in Flask 2.3. Use `--debug` instead. Changelog Changed in version 1.0: `LOGGER_NAME` and `LOGGER_HANDLER_POLICY` were removed. See [Logging](../logging/index) for information about configuration. Added [`ENV`](#ENV "ENV") to reflect the `FLASK_ENV` environment variable. Added [`SESSION_COOKIE_SAMESITE`](#SESSION_COOKIE_SAMESITE "SESSION_COOKIE_SAMESITE") to control the session cookie’s `SameSite` option. Added [`MAX_COOKIE_SIZE`](#MAX_COOKIE_SIZE "MAX_COOKIE_SIZE") to control a warning from Werkzeug. New in version 0.11: `SESSION_REFRESH_EACH_REQUEST`, `TEMPLATES_AUTO_RELOAD`, `LOGGER_HANDLER_POLICY`, `EXPLAIN_TEMPLATE_LOADING` New in version 0.10: `JSON_AS_ASCII`, `JSON_SORT_KEYS`, `JSONIFY_PRETTYPRINT_REGULAR` New in version 0.9: `PREFERRED_URL_SCHEME` New in version 0.8: `TRAP_BAD_REQUEST_ERRORS`, `TRAP_HTTP_EXCEPTIONS`, `APPLICATION_ROOT`, `SESSION_COOKIE_DOMAIN`, `SESSION_COOKIE_PATH`, `SESSION_COOKIE_HTTPONLY`, `SESSION_COOKIE_SECURE` New in version 0.7: `PROPAGATE_EXCEPTIONS`, `PRESERVE_CONTEXT_ON_EXCEPTION` New in version 0.6: `MAX_CONTENT_LENGTH` New in version 0.5: `SERVER_NAME` New in version 0.4: `LOGGER_NAME` Configuring from Python Files ----------------------------- Configuration becomes more useful if you can store it in a separate file, ideally located outside the actual application package. You can deploy your application, then separately configure it for the specific deployment. A common pattern is this: ``` app = Flask(__name__) app.config.from_object('yourapplication.default_settings') app.config.from_envvar('YOURAPPLICATION_SETTINGS') ``` This first loads the configuration from the `yourapplication.default_settings` module and then overrides the values with the contents of the file the `YOURAPPLICATION_SETTINGS` environment variable points to. This environment variable can be set in the shell before starting the server: ``` $ export YOURAPPLICATION_SETTINGS=/path/to/settings.cfg $ flask run * Running on http://127.0.0.1:5000/ ``` ``` $ set -x YOURAPPLICATION_SETTINGS /path/to/settings.cfg $ flask run * Running on http://127.0.0.1:5000/ ``` ``` > set YOURAPPLICATION_SETTINGS=\path\to\settings.cfg > flask run * Running on http://127.0.0.1:5000/ ``` ``` > $env:YOURAPPLICATION_SETTINGS = "\path\to\settings.cfg" > flask run * Running on http://127.0.0.1:5000/ ``` The configuration files themselves are actual Python files. Only values in uppercase are actually stored in the config object later on. So make sure to use uppercase letters for your config keys. Here is an example of a configuration file: ``` # Example configuration SECRET_KEY = '192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf' ``` Make sure to load the configuration very early on, so that extensions have the ability to access the configuration when starting up. There are other methods on the config object as well to load from individual files. For a complete reference, read the [`Config`](../api/index#flask.Config "flask.Config") object’s documentation. Configuring from Data Files --------------------------- It is also possible to load configuration from a file in a format of your choice using [`from_file()`](../api/index#flask.Config.from_file "flask.Config.from_file"). For example to load from a TOML file: ``` import toml app.config.from_file("config.toml", load=toml.load) ``` Or from a JSON file: ``` import json app.config.from_file("config.json", load=json.load) ``` Configuring from Environment Variables -------------------------------------- In addition to pointing to configuration files using environment variables, you may find it useful (or necessary) to control your configuration values directly from the environment. Flask can be instructed to load all environment variables starting with a specific prefix into the config using [`from_prefixed_env()`](../api/index#flask.Config.from_prefixed_env "flask.Config.from_prefixed_env"). Environment variables can be set in the shell before starting the server: ``` $ export FLASK_SECRET_KEY="5f352379324c22463451387a0aec5d2f" $ export FLASK_MAIL_ENABLED=false $ flask run * Running on http://127.0.0.1:5000/ ``` ``` $ set -x FLASK_SECRET_KEY "5f352379324c22463451387a0aec5d2f" $ set -x FLASK_MAIL_ENABLED false $ flask run * Running on http://127.0.0.1:5000/ ``` ``` > set FLASK_SECRET_KEY="5f352379324c22463451387a0aec5d2f" > set FLASK_MAIL_ENABLED=false > flask run * Running on http://127.0.0.1:5000/ ``` ``` > $env:FLASK_SECRET_KEY = "5f352379324c22463451387a0aec5d2f" > $env:FLASK_MAIL_ENABLED = "false" > flask run * Running on http://127.0.0.1:5000/ ``` The variables can then be loaded and accessed via the config with a key equal to the environment variable name without the prefix i.e. ``` app.config.from_prefixed_env() app.config["SECRET_KEY"] # Is "5f352379324c22463451387a0aec5d2f" ``` The prefix is `FLASK_` by default. This is configurable via the `prefix` argument of [`from_prefixed_env()`](../api/index#flask.Config.from_prefixed_env "flask.Config.from_prefixed_env"). Values will be parsed to attempt to convert them to a more specific type than strings. By default [`json.loads()`](https://docs.python.org/3/library/json.html#json.loads "(in Python v3.10)") is used, so any valid JSON value is possible, including lists and dicts. This is configurable via the `loads` argument of [`from_prefixed_env()`](../api/index#flask.Config.from_prefixed_env "flask.Config.from_prefixed_env"). When adding a boolean value with the default JSON parsing, only “true” and “false”, lowercase, are valid values. Keep in mind that any non-empty string is considered `True` by Python. It is possible to set keys in nested dictionaries by separating the keys with double underscore (`__`). Any intermediate keys that don’t exist on the parent dict will be initialized to an empty dict. ``` $ export FLASK_MYAPI__credentials__username=user123 ``` ``` app.config["MYAPI"]["credentials"]["username"] # Is "user123" ``` On Windows, environment variable keys are always uppercase, therefore the above example would end up as `MYAPI__CREDENTIALS__USERNAME`. For even more config loading features, including merging and case-insensitive Windows support, try a dedicated library such as [Dynaconf](https://www.dynaconf.com/), which includes integration with Flask. Configuration Best Practices ---------------------------- The downside with the approach mentioned earlier is that it makes testing a little harder. There is no single 100% solution for this problem in general, but there are a couple of things you can keep in mind to improve that experience: 1. Create your application in a function and register blueprints on it. That way you can create multiple instances of your application with different configurations attached which makes unit testing a lot easier. You can use this to pass in configuration as needed. 2. Do not write code that needs the configuration at import time. If you limit yourself to request-only accesses to the configuration you can reconfigure the object later on as needed. 3. Make sure to load the configuration very early on, so that extensions can access the configuration when calling `init_app`. Development / Production ------------------------ Most applications need more than one configuration. There should be at least separate configurations for the production server and the one used during development. The easiest way to handle this is to use a default configuration that is always loaded and part of the version control, and a separate configuration that overrides the values as necessary as mentioned in the example above: ``` app = Flask(__name__) app.config.from_object('yourapplication.default_settings') app.config.from_envvar('YOURAPPLICATION_SETTINGS') ``` Then you just have to add a separate `config.py` file and export `YOURAPPLICATION_SETTINGS=/path/to/config.py` and you are done. However there are alternative ways as well. For example you could use imports or subclassing. What is very popular in the Django world is to make the import explicit in the config file by adding `from yourapplication.default_settings import *` to the top of the file and then overriding the changes by hand. You could also inspect an environment variable like `YOURAPPLICATION_MODE` and set that to `production`, `development` etc and import different hard-coded files based on that. An interesting pattern is also to use classes and inheritance for configuration: ``` class Config(object): TESTING = False class ProductionConfig(Config): DATABASE_URI = 'mysql://user@localhost/foo' class DevelopmentConfig(Config): DATABASE_URI = "sqlite:////tmp/foo.db" class TestingConfig(Config): DATABASE_URI = 'sqlite:///:memory:' TESTING = True ``` To enable such a config you just have to call into [`from_object()`](../api/index#flask.Config.from_object "flask.Config.from_object"): ``` app.config.from_object('configmodule.ProductionConfig') ``` Note that [`from_object()`](../api/index#flask.Config.from_object "flask.Config.from_object") does not instantiate the class object. If you need to instantiate the class, such as to access a property, then you must do so before calling [`from_object()`](../api/index#flask.Config.from_object "flask.Config.from_object"): ``` from configmodule import ProductionConfig app.config.from_object(ProductionConfig()) # Alternatively, import via string: from werkzeug.utils import import_string cfg = import_string('configmodule.ProductionConfig')() app.config.from_object(cfg) ``` Instantiating the configuration object allows you to use `@property` in your configuration classes: ``` class Config(object): """Base config, uses staging database server.""" TESTING = False DB_SERVER = '192.168.1.56' @property def DATABASE_URI(self): # Note: all caps return f"mysql://user@{self.DB_SERVER}/foo" class ProductionConfig(Config): """Uses production database server.""" DB_SERVER = '192.168.19.32' class DevelopmentConfig(Config): DB_SERVER = 'localhost' class TestingConfig(Config): DB_SERVER = 'localhost' DATABASE_URI = 'sqlite:///:memory:' ``` There are many different ways and it’s up to you how you want to manage your configuration files. However here a list of good recommendations: * Keep a default configuration in version control. Either populate the config with this default configuration or import it in your own configuration files before overriding values. * Use an environment variable to switch between the configurations. This can be done from outside the Python interpreter and makes development and deployment much easier because you can quickly and easily switch between different configs without having to touch the code at all. If you are working often on different projects you can even create your own script for sourcing that activates a virtualenv and exports the development configuration for you. * Use a tool like [fabric](https://www.fabfile.org/) to push code and configuration separately to the production server(s). Instance Folders ---------------- Changelog New in version 0.8. Flask 0.8 introduces instance folders. Flask for a long time made it possible to refer to paths relative to the application’s folder directly (via `Flask.root_path`). This was also how many developers loaded configurations stored next to the application. Unfortunately however this only works well if applications are not packages in which case the root path refers to the contents of the package. With Flask 0.8 a new attribute was introduced: `Flask.instance_path`. It refers to a new concept called the “instance folder”. The instance folder is designed to not be under version control and be deployment specific. It’s the perfect place to drop things that either change at runtime or configuration files. You can either explicitly provide the path of the instance folder when creating the Flask application or you can let Flask autodetect the instance folder. For explicit configuration use the `instance_path` parameter: ``` app = Flask(__name__, instance_path='/path/to/instance/folder') ``` Please keep in mind that this path *must* be absolute when provided. If the `instance_path` parameter is not provided the following default locations are used: * Uninstalled module: ``` /myapp.py /instance ``` * Uninstalled package: ``` /myapp /__init__.py /instance ``` * Installed module or package: ``` $PREFIX/lib/pythonX.Y/site-packages/myapp $PREFIX/var/myapp-instance ``` `$PREFIX` is the prefix of your Python installation. This can be `/usr` or the path to your virtualenv. You can print the value of `sys.prefix` to see what the prefix is set to. Since the config object provided loading of configuration files from relative filenames we made it possible to change the loading via filenames to be relative to the instance path if wanted. The behavior of relative paths in config files can be flipped between “relative to the application root” (the default) to “relative to instance folder” via the `instance_relative_config` switch to the application constructor: ``` app = Flask(__name__, instance_relative_config=True) ``` Here is a full example of how to configure Flask to preload the config from a module and then override the config from a file in the instance folder if it exists: ``` app = Flask(__name__, instance_relative_config=True) app.config.from_object('yourapplication.default_settings') app.config.from_pyfile('application.cfg', silent=True) ``` The path to the instance folder can be found via the `Flask.instance_path`. Flask also provides a shortcut to open a file from the instance folder with `Flask.open_instance_resource()`. Example usage for both: ``` filename = os.path.join(app.instance_path, 'application.cfg') with open(filename) as f: config = f.read() # or via open_instance_resource: with app.open_instance_resource('application.cfg') as f: config = f.read() ```
programming_docs
flask Security Considerations Security Considerations ======================= Web applications usually face all kinds of security problems and it’s very hard to get everything right. Flask tries to solve a few of these things for you, but there are a couple more you have to take care of yourself. Cross-Site Scripting (XSS) -------------------------- Cross site scripting is the concept of injecting arbitrary HTML (and with it JavaScript) into the context of a website. To remedy this, developers have to properly escape text so that it cannot include arbitrary HTML tags. For more information on that have a look at the Wikipedia article on [Cross-Site Scripting](https://en.wikipedia.org/wiki/Cross-site_scripting). Flask configures Jinja2 to automatically escape all values unless explicitly told otherwise. This should rule out all XSS problems caused in templates, but there are still other places where you have to be careful: * generating HTML without the help of Jinja2 * calling [`Markup`](../api/index#flask.Markup "flask.Markup") on data submitted by users * sending out HTML from uploaded files, never do that, use the `Content-Disposition: attachment` header to prevent that problem. * sending out textfiles from uploaded files. Some browsers are using content-type guessing based on the first few bytes so users could trick a browser to execute HTML. Another thing that is very important are unquoted attributes. While Jinja2 can protect you from XSS issues by escaping HTML, there is one thing it cannot protect you from: XSS by attribute injection. To counter this possible attack vector, be sure to always quote your attributes with either double or single quotes when using Jinja expressions in them: ``` <input value="{{ value }}"> ``` Why is this necessary? Because if you would not be doing that, an attacker could easily inject custom JavaScript handlers. For example an attacker could inject this piece of HTML+JavaScript: ``` onmouseover=alert(document.cookie) ``` When the user would then move with the mouse over the input, the cookie would be presented to the user in an alert window. But instead of showing the cookie to the user, a good attacker might also execute any other JavaScript code. In combination with CSS injections the attacker might even make the element fill out the entire page so that the user would just have to have the mouse anywhere on the page to trigger the attack. There is one class of XSS issues that Jinja’s escaping does not protect against. The `a` tag’s `href` attribute can contain a `javascript:` URI, which the browser will execute when clicked if not secured properly. ``` <a href="{{ value }}">click here</a> <a href="javascript:alert('unsafe');">click here</a> ``` To prevent this, you’ll need to set the [Content Security Policy (CSP)](#security-csp) response header. Cross-Site Request Forgery (CSRF) --------------------------------- Another big problem is CSRF. This is a very complex topic and I won’t outline it here in detail just mention what it is and how to theoretically prevent it. If your authentication information is stored in cookies, you have implicit state management. The state of “being logged in” is controlled by a cookie, and that cookie is sent with each request to a page. Unfortunately that includes requests triggered by 3rd party sites. If you don’t keep that in mind, some people might be able to trick your application’s users with social engineering to do stupid things without them knowing. Say you have a specific URL that, when you sent `POST` requests to will delete a user’s profile (say `http://example.com/user/delete`). If an attacker now creates a page that sends a post request to that page with some JavaScript they just have to trick some users to load that page and their profiles will end up being deleted. Imagine you were to run Facebook with millions of concurrent users and someone would send out links to images of little kittens. When users would go to that page, their profiles would get deleted while they are looking at images of fluffy cats. How can you prevent that? Basically for each request that modifies content on the server you would have to either use a one-time token and store that in the cookie **and** also transmit it with the form data. After receiving the data on the server again, you would then have to compare the two tokens and ensure they are equal. Why does Flask not do that for you? The ideal place for this to happen is the form validation framework, which does not exist in Flask. JSON Security ------------- In Flask 0.10 and lower, `jsonify()` did not serialize top-level arrays to JSON. This was because of a security vulnerability in ECMAScript 4. ECMAScript 5 closed this vulnerability, so only extremely old browsers are still vulnerable. All of these browsers have [other more serious vulnerabilities](https://github.com/pallets/flask/issues/248#issuecomment-59934857), so this behavior was changed and `jsonify()` now supports serializing arrays. Security Headers ---------------- Browsers recognize various response headers in order to control security. We recommend reviewing each of the headers below for use in your application. The [Flask-Talisman](https://github.com/GoogleCloudPlatform/flask-talisman) extension can be used to manage HTTPS and the security headers for you. ### HTTP Strict Transport Security (HSTS) Tells the browser to convert all HTTP requests to HTTPS, preventing man-in-the-middle (MITM) attacks. ``` response.headers['Strict-Transport-Security'] = 'max-age=31536000; includeSubDomains' ``` * <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security> ### Content Security Policy (CSP) Tell the browser where it can load various types of resource from. This header should be used whenever possible, but requires some work to define the correct policy for your site. A very strict policy would be: ``` response.headers['Content-Security-Policy'] = "default-src 'self'" ``` * <https://csp.withgoogle.com/docs/index.html> * <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy> ### X-Content-Type-Options Forces the browser to honor the response content type instead of trying to detect it, which can be abused to generate a cross-site scripting (XSS) attack. ``` response.headers['X-Content-Type-Options'] = 'nosniff' ``` * <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options> ### X-Frame-Options Prevents external sites from embedding your site in an `iframe`. This prevents a class of attacks where clicks in the outer frame can be translated invisibly to clicks on your page’s elements. This is also known as “clickjacking”. ``` response.headers['X-Frame-Options'] = 'SAMEORIGIN' ``` * <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options> ### Set-Cookie options These options can be added to a `Set-Cookie` header to improve their security. Flask has configuration options to set these on the session cookie. They can be set on other cookies too. * `Secure` limits cookies to HTTPS traffic only. * `HttpOnly` protects the contents of cookies from being read with JavaScript. * `SameSite` restricts how cookies are sent with requests from external sites. Can be set to `'Lax'` (recommended) or `'Strict'`. `Lax` prevents sending cookies with CSRF-prone requests from external sites, such as submitting a form. `Strict` prevents sending cookies with all external requests, including following regular links. ``` app.config.update( SESSION_COOKIE_SECURE=True, SESSION_COOKIE_HTTPONLY=True, SESSION_COOKIE_SAMESITE='Lax', ) response.set_cookie('username', 'flask', secure=True, httponly=True, samesite='Lax') ``` Specifying `Expires` or `Max-Age` options, will remove the cookie after the given time, or the current time plus the age, respectively. If neither option is set, the cookie will be removed when the browser is closed. ``` # cookie expires after 10 minutes response.set_cookie('snakes', '3', max_age=600) ``` For the session cookie, if [`session.permanent`](../api/index#flask.session.permanent "flask.session.permanent") is set, then [`PERMANENT_SESSION_LIFETIME`](../config/index#PERMANENT_SESSION_LIFETIME "PERMANENT_SESSION_LIFETIME") is used to set the expiration. Flask’s default cookie implementation validates that the cryptographic signature is not older than this value. Lowering this value may help mitigate replay attacks, where intercepted cookies can be sent at a later time. ``` app.config.update( PERMANENT_SESSION_LIFETIME=600 ) @app.route('/login', methods=['POST']) def login(): ... session.clear() session['user_id'] = user.id session.permanent = True ... ``` Use `itsdangerous.TimedSerializer` to sign and validate other cookie values (or any values that need secure signatures). * <https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies> * <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie> ### HTTP Public Key Pinning (HPKP) This tells the browser to authenticate with the server using only the specific certificate key to prevent MITM attacks. Warning Be careful when enabling this, as it is very difficult to undo if you set up or upgrade your key incorrectly. * <https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning> Copy/Paste to Terminal ---------------------- Hidden characters such as the backspace character (`\b`, `^H`) can cause text to render differently in HTML than how it is interpreted if [pasted into a terminal](https://security.stackexchange.com/q/39118). For example, `import y\bose\bm\bi\bt\be\b` renders as `import yosemite` in HTML, but the backspaces are applied when pasted into a terminal, and it becomes `import os`. If you expect users to copy and paste untrusted code from your site, such as from comments posted by users on a technical blog, consider applying extra filtering, such as replacing all `\b` characters. ``` body = body.replace("\b", "") ``` Most modern terminals will warn about and remove hidden characters when pasting, so this isn’t strictly necessary. It’s also possible to craft dangerous commands in other ways that aren’t possible to filter. Depending on your site’s use case, it may be good to show a warning about copying code in general. flask Handling Application Errors Handling Application Errors =========================== Applications fail, servers fail. Sooner or later you will see an exception in production. Even if your code is 100% correct, you will still see exceptions from time to time. Why? Because everything else involved will fail. Here are some situations where perfectly fine code can lead to server errors: * the client terminated the request early and the application was still reading from the incoming data * the database server was overloaded and could not handle the query * a filesystem is full * a harddrive crashed * a backend server overloaded * a programming error in a library you are using * network connection of the server to another system failed And that’s just a small sample of issues you could be facing. So how do we deal with that sort of problem? By default if your application runs in production mode, and an exception is raised Flask will display a very simple page for you and log the exception to the [`logger`](../api/index#flask.Flask.logger "flask.Flask.logger"). But there is more you can do, and we will cover some better setups to deal with errors including custom exceptions and 3rd party tools. Error Logging Tools ------------------- Sending error mails, even if just for critical ones, can become overwhelming if enough users are hitting the error and log files are typically never looked at. This is why we recommend using [Sentry](https://sentry.io/) for dealing with application errors. It’s available as a source-available project [on GitHub](https://github.com/getsentry/sentry) and is also available as a [hosted version](https://sentry.io/signup/) which you can try for free. Sentry aggregates duplicate errors, captures the full stack trace and local variables for debugging, and sends you mails based on new errors or frequency thresholds. To use Sentry you need to install the `sentry-sdk` client with extra `flask` dependencies. ``` $ pip install sentry-sdk[flask] ``` And then add this to your Flask app: ``` import sentry_sdk from sentry_sdk.integrations.flask import FlaskIntegration sentry_sdk.init('YOUR_DSN_HERE', integrations=[FlaskIntegration()]) ``` The `YOUR_DSN_HERE` value needs to be replaced with the DSN value you get from your Sentry installation. After installation, failures leading to an Internal Server Error are automatically reported to Sentry and from there you can receive error notifications. See also: * Sentry also supports catching errors from a worker queue (RQ, Celery, etc.) in a similar fashion. See the [Python SDK docs](https://docs.sentry.io/platforms/python/) for more information. * [Getting started with Sentry](https://docs.sentry.io/quickstart/?platform=python) * [Flask-specific documentation](https://docs.sentry.io/platforms/python/guides/flask/) Error Handlers -------------- When an error occurs in Flask, an appropriate [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) will be returned. 400-499 indicate errors with the client’s request data, or about the data requested. 500-599 indicate errors with the server or application itself. You might want to show custom error pages to the user when an error occurs. This can be done by registering error handlers. An error handler is a function that returns a response when a type of error is raised, similar to how a view is a function that returns a response when a request URL is matched. It is passed the instance of the error being handled, which is most likely a [`HTTPException`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.HTTPException "(in Werkzeug v2.2.x)"). The status code of the response will not be set to the handler’s code. Make sure to provide the appropriate HTTP status code when returning a response from a handler. ### Registering Register handlers by decorating a function with [`errorhandler()`](../api/index#flask.Flask.errorhandler "flask.Flask.errorhandler"). Or use [`register_error_handler()`](../api/index#flask.Flask.register_error_handler "flask.Flask.register_error_handler") to register the function later. Remember to set the error code when returning the response. ``` @app.errorhandler(werkzeug.exceptions.BadRequest) def handle_bad_request(e): return 'bad request!', 400 # or, without the decorator app.register_error_handler(400, handle_bad_request) ``` [`werkzeug.exceptions.HTTPException`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.HTTPException "(in Werkzeug v2.2.x)") subclasses like [`BadRequest`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.BadRequest "(in Werkzeug v2.2.x)") and their HTTP codes are interchangeable when registering handlers. (`BadRequest.code == 400`) Non-standard HTTP codes cannot be registered by code because they are not known by Werkzeug. Instead, define a subclass of [`HTTPException`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.HTTPException "(in Werkzeug v2.2.x)") with the appropriate code and register and raise that exception class. ``` class InsufficientStorage(werkzeug.exceptions.HTTPException): code = 507 description = 'Not enough storage space.' app.register_error_handler(InsufficientStorage, handle_507) raise InsufficientStorage() ``` Handlers can be registered for any exception class, not just [`HTTPException`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.HTTPException "(in Werkzeug v2.2.x)") subclasses or HTTP status codes. Handlers can be registered for a specific class, or for all subclasses of a parent class. ### Handling When building a Flask application you *will* run into exceptions. If some part of your code breaks while handling a request (and you have no error handlers registered), a “500 Internal Server Error” ([`InternalServerError`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.InternalServerError "(in Werkzeug v2.2.x)")) will be returned by default. Similarly, “404 Not Found” ([`NotFound`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.NotFound "(in Werkzeug v2.2.x)")) error will occur if a request is sent to an unregistered route. If a route receives an unallowed request method, a “405 Method Not Allowed” ([`MethodNotAllowed`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.MethodNotAllowed "(in Werkzeug v2.2.x)")) will be raised. These are all subclasses of [`HTTPException`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.HTTPException "(in Werkzeug v2.2.x)") and are provided by default in Flask. Flask gives you the ability to raise any HTTP exception registered by Werkzeug. However, the default HTTP exceptions return simple exception pages. You might want to show custom error pages to the user when an error occurs. This can be done by registering error handlers. When Flask catches an exception while handling a request, it is first looked up by code. If no handler is registered for the code, Flask looks up the error by its class hierarchy; the most specific handler is chosen. If no handler is registered, [`HTTPException`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.HTTPException "(in Werkzeug v2.2.x)") subclasses show a generic message about their code, while other exceptions are converted to a generic “500 Internal Server Error”. For example, if an instance of [`ConnectionRefusedError`](https://docs.python.org/3/library/exceptions.html#ConnectionRefusedError "(in Python v3.10)") is raised, and a handler is registered for [`ConnectionError`](https://docs.python.org/3/library/exceptions.html#ConnectionError "(in Python v3.10)") and [`ConnectionRefusedError`](https://docs.python.org/3/library/exceptions.html#ConnectionRefusedError "(in Python v3.10)"), the more specific [`ConnectionRefusedError`](https://docs.python.org/3/library/exceptions.html#ConnectionRefusedError "(in Python v3.10)") handler is called with the exception instance to generate the response. Handlers registered on the blueprint take precedence over those registered globally on the application, assuming a blueprint is handling the request that raises the exception. However, the blueprint cannot handle 404 routing errors because the 404 occurs at the routing level before the blueprint can be determined. ### Generic Exception Handlers It is possible to register error handlers for very generic base classes such as `HTTPException` or even `Exception`. However, be aware that these will catch more than you might expect. For example, an error handler for `HTTPException` might be useful for turning the default HTML errors pages into JSON. However, this handler will trigger for things you don’t cause directly, such as 404 and 405 errors during routing. Be sure to craft your handler carefully so you don’t lose information about the HTTP error. ``` from flask import json from werkzeug.exceptions import HTTPException @app.errorhandler(HTTPException) def handle_exception(e): """Return JSON instead of HTML for HTTP errors.""" # start with the correct headers and status code from the error response = e.get_response() # replace the body with JSON response.data = json.dumps({ "code": e.code, "name": e.name, "description": e.description, }) response.content_type = "application/json" return response ``` An error handler for `Exception` might seem useful for changing how all errors, even unhandled ones, are presented to the user. However, this is similar to doing `except Exception:` in Python, it will capture *all* otherwise unhandled errors, including all HTTP status codes. In most cases it will be safer to register handlers for more specific exceptions. Since `HTTPException` instances are valid WSGI responses, you could also pass them through directly. ``` from werkzeug.exceptions import HTTPException @app.errorhandler(Exception) def handle_exception(e): # pass through HTTP errors if isinstance(e, HTTPException): return e # now you're handling non-HTTP exceptions only return render_template("500_generic.html", e=e), 500 ``` Error handlers still respect the exception class hierarchy. If you register handlers for both `HTTPException` and `Exception`, the `Exception` handler will not handle `HTTPException` subclasses because it the `HTTPException` handler is more specific. ### Unhandled Exceptions When there is no error handler registered for an exception, a 500 Internal Server Error will be returned instead. See [`flask.Flask.handle_exception()`](../api/index#flask.Flask.handle_exception "flask.Flask.handle_exception") for information about this behavior. If there is an error handler registered for `InternalServerError`, this will be invoked. As of Flask 1.1.0, this error handler will always be passed an instance of `InternalServerError`, not the original unhandled error. The original error is available as `e.original_exception`. An error handler for “500 Internal Server Error” will be passed uncaught exceptions in addition to explicit 500 errors. In debug mode, a handler for “500 Internal Server Error” will not be used. Instead, the interactive debugger will be shown. Custom Error Pages ------------------ Sometimes when building a Flask application, you might want to raise a [`HTTPException`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.HTTPException "(in Werkzeug v2.2.x)") to signal to the user that something is wrong with the request. Fortunately, Flask comes with a handy [`abort()`](../api/index#flask.abort "flask.abort") function that aborts a request with a HTTP error from werkzeug as desired. It will also provide a plain black and white error page for you with a basic description, but nothing fancy. Depending on the error code it is less or more likely for the user to actually see such an error. Consider the code below, we might have a user profile route, and if the user fails to pass a username we can raise a “400 Bad Request”. If the user passes a username and we can’t find it, we raise a “404 Not Found”. ``` from flask import abort, render_template, request # a username needs to be supplied in the query args # a successful request would be like /profile?username=jack @app.route("/profile") def user_profile(): username = request.arg.get("username") # if a username isn't supplied in the request, return a 400 bad request if username is None: abort(400) user = get_user(username=username) # if a user can't be found by their username, return 404 not found if user is None: abort(404) return render_template("profile.html", user=user) ``` Here is another example implementation for a “404 Page Not Found” exception: ``` from flask import render_template @app.errorhandler(404) def page_not_found(e): # note that we set the 404 status explicitly return render_template('404.html'), 404 ``` When using [Application Factories](../patterns/appfactories/index): ``` from flask import Flask, render_template def page_not_found(e): return render_template('404.html'), 404 def create_app(config_filename): app = Flask(__name__) app.register_error_handler(404, page_not_found) return app ``` An example template might be this: ``` {% extends "layout.html" %} {% block title %}Page Not Found{% endblock %} {% block body %} <h1>Page Not Found</h1> <p>What you were looking for is just not there. <p><a href="{{ url_for('index') }}">go somewhere nice</a> {% endblock %} ``` ### Further Examples The above examples wouldn’t actually be an improvement on the default exception pages. We can create a custom 500.html template like this: ``` {% extends "layout.html" %} {% block title %}Internal Server Error{% endblock %} {% block body %} <h1>Internal Server Error</h1> <p>Oops... we seem to have made a mistake, sorry!</p> <p><a href="{{ url_for('index') }}">Go somewhere nice instead</a> {% endblock %} ``` It can be implemented by rendering the template on “500 Internal Server Error”: ``` from flask import render_template @app.errorhandler(500) def internal_server_error(e): # note that we set the 500 status explicitly return render_template('500.html'), 500 ``` When using [Application Factories](../patterns/appfactories/index): ``` from flask import Flask, render_template def internal_server_error(e): return render_template('500.html'), 500 def create_app(): app = Flask(__name__) app.register_error_handler(500, internal_server_error) return app ``` When using [Modular Applications with Blueprints](../blueprints/index): ``` from flask import Blueprint blog = Blueprint('blog', __name__) # as a decorator @blog.errorhandler(500) def internal_server_error(e): return render_template('500.html'), 500 # or with register_error_handler blog.register_error_handler(500, internal_server_error) ``` Blueprint Error Handlers ------------------------ In [Modular Applications with Blueprints](../blueprints/index), most error handlers will work as expected. However, there is a caveat concerning handlers for 404 and 405 exceptions. These error handlers are only invoked from an appropriate `raise` statement or a call to `abort` in another of the blueprint’s view functions; they are not invoked by, e.g., an invalid URL access. This is because the blueprint does not “own” a certain URL space, so the application instance has no way of knowing which blueprint error handler it should run if given an invalid URL. If you would like to execute different handling strategies for these errors based on URL prefixes, they may be defined at the application level using the `request` proxy object. ``` from flask import jsonify, render_template # at the application level # not the blueprint level @app.errorhandler(404) def page_not_found(e): # if a request is in our blog URL space if request.path.startswith('/blog/'): # we return a custom blog 404 page return render_template("blog/404.html"), 404 else: # otherwise we return our generic site-wide 404 page return render_template("404.html"), 404 @app.errorhandler(405) def method_not_allowed(e): # if a request has the wrong method to our API if request.path.startswith('/api/'): # we return a json saying so return jsonify(message="Method Not Allowed"), 405 else: # otherwise we return a generic site-wide 405 page return render_template("405.html"), 405 ``` Returning API Errors as JSON ---------------------------- When building APIs in Flask, some developers realise that the built-in exceptions are not expressive enough for APIs and that the content type of *text/html* they are emitting is not very useful for API consumers. Using the same techniques as above and [`jsonify()`](../api/index#flask.json.jsonify "flask.json.jsonify") we can return JSON responses to API errors. [`abort()`](../api/index#flask.abort "flask.abort") is called with a `description` parameter. The error handler will use that as the JSON error message, and set the status code to 404. ``` from flask import abort, jsonify @app.errorhandler(404) def resource_not_found(e): return jsonify(error=str(e)), 404 @app.route("/cheese") def get_one_cheese(): resource = get_resource() if resource is None: abort(404, description="Resource not found") return jsonify(resource) ``` We can also create custom exception classes. For instance, we can introduce a new custom exception for an API that can take a proper human readable message, a status code for the error and some optional payload to give more context for the error. This is a simple example: ``` from flask import jsonify, request class InvalidAPIUsage(Exception): status_code = 400 def __init__(self, message, status_code=None, payload=None): super().__init__() self.message = message if status_code is not None: self.status_code = status_code self.payload = payload def to_dict(self): rv = dict(self.payload or ()) rv['message'] = self.message return rv @app.errorhandler(InvalidAPIUsage) def invalid_api_usage(e): return jsonify(e.to_dict()), e.status_code # an API app route for getting user information # a correct request might be /api/user?user_id=420 @app.route("/api/user") def user_api(user_id): user_id = request.arg.get("user_id") if not user_id: raise InvalidAPIUsage("No user id provided!") user = get_user(user_id=user_id) if not user: raise InvalidAPIUsage("No such user!", status_code=404) return jsonify(user.to_dict()) ``` A view can now raise that exception with an error message. Additionally some extra payload can be provided as a dictionary through the `payload` parameter. Logging ------- See [Logging](../logging/index) for information about how to log exceptions, such as by emailing them to admins. Debugging --------- See [Debugging Application Errors](../debugging/index) for information about how to debug errors in development and production.
programming_docs
flask Working with the Shell Working with the Shell ====================== Changelog New in version 0.3. One of the reasons everybody loves Python is the interactive shell. It basically allows you to execute Python commands in real time and immediately get results back. Flask itself does not come with an interactive shell, because it does not require any specific setup upfront, just import your application and start playing around. There are however some handy helpers to make playing around in the shell a more pleasant experience. The main issue with interactive console sessions is that you’re not triggering a request like a browser does which means that [`g`](../api/index#flask.g "flask.g"), [`request`](../api/index#flask.request "flask.request") and others are not available. But the code you want to test might depend on them, so what can you do? This is where some helper functions come in handy. Keep in mind however that these functions are not only there for interactive shell usage, but also for unit testing and other situations that require a faked request context. Generally it’s recommended that you read [The Request Context](../reqcontext/index) first. Command Line Interface ---------------------- Starting with Flask 0.11 the recommended way to work with the shell is the `flask shell` command which does a lot of this automatically for you. For instance the shell is automatically initialized with a loaded application context. For more information see [Command Line Interface](../cli/index). Creating a Request Context -------------------------- The easiest way to create a proper request context from the shell is by using the [`test_request_context`](../api/index#flask.Flask.test_request_context "flask.Flask.test_request_context") method which creates us a [`RequestContext`](../api/index#flask.ctx.RequestContext "flask.ctx.RequestContext"): ``` >>> ctx = app.test_request_context() ``` Normally you would use the `with` statement to make this request object active, but in the shell it’s easier to use the `push()` and [`pop()`](../api/index#flask.ctx.RequestContext.pop "flask.ctx.RequestContext.pop") methods by hand: ``` >>> ctx.push() ``` From that point onwards you can work with the request object until you call `pop`: ``` >>> ctx.pop() ``` Firing Before/After Request --------------------------- By just creating a request context, you still don’t have run the code that is normally run before a request. This might result in your database being unavailable if you are connecting to the database in a before-request callback or the current user not being stored on the [`g`](../api/index#flask.g "flask.g") object etc. This however can easily be done yourself. Just call [`preprocess_request()`](../api/index#flask.Flask.preprocess_request "flask.Flask.preprocess_request"): ``` >>> ctx = app.test_request_context() >>> ctx.push() >>> app.preprocess_request() ``` Keep in mind that the [`preprocess_request()`](../api/index#flask.Flask.preprocess_request "flask.Flask.preprocess_request") function might return a response object, in that case just ignore it. To shutdown a request, you need to trick a bit before the after request functions (triggered by [`process_response()`](../api/index#flask.Flask.process_response "flask.Flask.process_response")) operate on a response object: ``` >>> app.process_response(app.response_class()) <Response 0 bytes [200 OK]> >>> ctx.pop() ``` The functions registered as [`teardown_request()`](../api/index#flask.Flask.teardown_request "flask.Flask.teardown_request") are automatically called when the context is popped. So this is the perfect place to automatically tear down resources that were needed by the request context (such as database connections). Further Improving the Shell Experience -------------------------------------- If you like the idea of experimenting in a shell, create yourself a module with stuff you want to star import into your interactive session. There you could also define some more helper methods for common things such as initializing the database, dropping tables etc. Just put them into a module (like `shelltools`) and import from there: ``` >>> from shelltools import * ``` flask Changes Changes ======= Version 2.2.3 ------------- Unreleased Version 2.2.2 ------------- Released 2022-08-08 * Update Werkzeug dependency to >= 2.2.2. This includes fixes related to the new faster router, header parsing, and the development server. [#4754](https://github.com/pallets/flask/pull/4754) * Fix the default value for `app.env` to be `"production"`. This attribute remains deprecated. [#4740](https://github.com/pallets/flask/issues/4740) Version 2.2.1 ------------- Released 2022-08-03 * Setting or accessing `json_encoder` or `json_decoder` raises a deprecation warning. [#4732](https://github.com/pallets/flask/issues/4732) Version 2.2.0 ------------- Released 2022-08-01 * Remove previously deprecated code. [#4667](https://github.com/pallets/flask/pull/4667) + Old names for some `send_file` parameters have been removed. `download_name` replaces `attachment_filename`, `max_age` replaces `cache_timeout`, and `etag` replaces `add_etags`. Additionally, `path` replaces `filename` in `send_from_directory`. + The `RequestContext.g` property returning `AppContext.g` is removed. * Update Werkzeug dependency to >= 2.2. * The app and request contexts are managed using Python context vars directly rather than Werkzeug’s `LocalStack`. This should result in better performance and memory use. [#4682](https://github.com/pallets/flask/pull/4682) + Extension maintainers, be aware that `_app_ctx_stack.top` and `_request_ctx_stack.top` are deprecated. Store data on `g` instead using a unique prefix, like `g._extension_name_attr`. * The `FLASK_ENV` environment variable and `app.env` attribute are deprecated, removing the distinction between development and debug mode. Debug mode should be controlled directly using the `--debug` option or `app.run(debug=True)`. [#4714](https://github.com/pallets/flask/issues/4714) * Some attributes that proxied config keys on `app` are deprecated: `session_cookie_name`, `send_file_max_age_default`, `use_x_sendfile`, `propagate_exceptions`, and `templates_auto_reload`. Use the relevant config keys instead. [#4716](https://github.com/pallets/flask/issues/4716) * Add new customization points to the `Flask` app object for many previously global behaviors. + `flask.url_for` will call `app.url_for`. [#4568](https://github.com/pallets/flask/issues/4568) + `flask.abort` will call `app.aborter`. `Flask.aborter_class` and `Flask.make_aborter` can be used to customize this aborter. [#4567](https://github.com/pallets/flask/issues/4567) + `flask.redirect` will call `app.redirect`. [#4569](https://github.com/pallets/flask/issues/4569) + `flask.json` is an instance of `JSONProvider`. A different provider can be set to use a different JSON library. `flask.jsonify` will call `app.json.response`, other functions in `flask.json` will call corresponding functions in `app.json`. [#4692](https://github.com/pallets/flask/pull/4692) * JSON configuration is moved to attributes on the default `app.json` provider. `JSON_AS_ASCII`, `JSON_SORT_KEYS`, `JSONIFY_MIMETYPE`, and `JSONIFY_PRETTYPRINT_REGULAR` are deprecated. [#4692](https://github.com/pallets/flask/pull/4692) * Setting custom `json_encoder` and `json_decoder` classes on the app or a blueprint, and the corresponding `json.JSONEncoder` and `JSONDecoder` classes, are deprecated. JSON behavior can now be overridden using the `app.json` provider interface. [#4692](https://github.com/pallets/flask/pull/4692) * `json.htmlsafe_dumps` and `json.htmlsafe_dump` are deprecated, the function is built-in to Jinja now. [#4692](https://github.com/pallets/flask/pull/4692) * Refactor `register_error_handler` to consolidate error checking. Rewrite some error messages to be more consistent. [#4559](https://github.com/pallets/flask/issues/4559) * Use Blueprint decorators and functions intended for setup after registering the blueprint will show a warning. In the next version, this will become an error just like the application setup methods. [#4571](https://github.com/pallets/flask/issues/4571) * `before_first_request` is deprecated. Run setup code when creating the application instead. [#4605](https://github.com/pallets/flask/issues/4605) * Added the `View.init_every_request` class attribute. If a view subclass sets this to `False`, the view will not create a new instance on every request. [#2520](https://github.com/pallets/flask/issues/2520). * A `flask.cli.FlaskGroup` Click group can be nested as a sub-command in a custom CLI. [#3263](https://github.com/pallets/flask/issues/3263) * Add `--app` and `--debug` options to the `flask` CLI, instead of requiring that they are set through environment variables. [#2836](https://github.com/pallets/flask/issues/2836) * Add `--env-file` option to the `flask` CLI. This allows specifying a dotenv file to load in addition to `.env` and `.flaskenv`. [#3108](https://github.com/pallets/flask/issues/3108) * It is no longer required to decorate custom CLI commands on `app.cli` or `blueprint.cli` with `@with_appcontext`, an app context will already be active at that point. [#2410](https://github.com/pallets/flask/issues/2410) * `SessionInterface.get_expiration_time` uses a timezone-aware value. [#4645](https://github.com/pallets/flask/pull/4645) * View functions can return generators directly instead of wrapping them in a `Response`. [#4629](https://github.com/pallets/flask/pull/4629) * Add `stream_template` and `stream_template_string` functions to render a template as a stream of pieces. [#4629](https://github.com/pallets/flask/pull/4629) * A new implementation of context preservation during debugging and testing. [#4666](https://github.com/pallets/flask/pull/4666) + `request`, `g`, and other context-locals point to the correct data when running code in the interactive debugger console. [#2836](https://github.com/pallets/flask/issues/2836) + Teardown functions are always run at the end of the request, even if the context is preserved. They are also run after the preserved context is popped. + `stream_with_context` preserves context separately from a `with client` block. It will be cleaned up when `response.get_data()` or `response.close()` is called. * Allow returning a list from a view function, to convert it to a JSON response like a dict is. [#4672](https://github.com/pallets/flask/issues/4672) * When type checking, allow `TypedDict` to be returned from view functions. [#4695](https://github.com/pallets/flask/pull/4695) * Remove the `--eager-loading/--lazy-loading` options from the `flask run` command. The app is always eager loaded the first time, then lazily loaded in the reloader. The reloader always prints errors immediately but continues serving. Remove the internal `DispatchingApp` middleware used by the previous implementation. [#4715](https://github.com/pallets/flask/issues/4715) Version 2.1.3 ------------- Released 2022-07-13 * Inline some optional imports that are only used for certain CLI commands. [#4606](https://github.com/pallets/flask/pull/4606) * Relax type annotation for `after_request` functions. [#4600](https://github.com/pallets/flask/issues/4600) * `instance_path` for namespace packages uses the path closest to the imported submodule. [#4610](https://github.com/pallets/flask/issues/4610) * Clearer error message when `render_template` and `render_template_string` are used outside an application context. [#4693](https://github.com/pallets/flask/pull/4693) Version 2.1.2 ------------- Released 2022-04-28 * Fix type annotation for `json.loads`, it accepts str or bytes. [#4519](https://github.com/pallets/flask/issues/4519) * The `--cert` and `--key` options on `flask run` can be given in either order. [#4459](https://github.com/pallets/flask/issues/4459) Version 2.1.1 ------------- Released on 2022-03-30 * Set the minimum required version of importlib\_metadata to 3.6.0, which is required on Python < 3.10. [#4502](https://github.com/pallets/flask/issues/4502) Version 2.1.0 ------------- Released 2022-03-28 * Drop support for Python 3.6. [#4335](https://github.com/pallets/flask/pull/4335) * Update Click dependency to >= 8.0. [#4008](https://github.com/pallets/flask/pull/4008) * Remove previously deprecated code. [#4337](https://github.com/pallets/flask/pull/4337) + The CLI does not pass `script_info` to app factory functions. + `config.from_json` is replaced by `config.from_file(name, load=json.load)`. + `json` functions no longer take an `encoding` parameter. + `safe_join` is removed, use `werkzeug.utils.safe_join` instead. + `total_seconds` is removed, use `timedelta.total_seconds` instead. + The same blueprint cannot be registered with the same name. Use `name=` when registering to specify a unique name. + The test client’s `as_tuple` parameter is removed. Use `response.request.environ` instead. [#4417](https://github.com/pallets/flask/pull/4417) * Some parameters in `send_file` and `send_from_directory` were renamed in 2.0. The deprecation period for the old names is extended to 2.2. Be sure to test with deprecation warnings visible. + `attachment_filename` is renamed to `download_name`. + `cache_timeout` is renamed to `max_age`. + `add_etags` is renamed to `etag`. + `filename` is renamed to `path`. * The `RequestContext.g` property is deprecated. Use `g` directly or `AppContext.g` instead. [#3898](https://github.com/pallets/flask/issues/3898) * `copy_current_request_context` can decorate async functions. [#4303](https://github.com/pallets/flask/pull/4303) * The CLI uses `importlib.metadata` instead of `setuptools` to load command entry points. [#4419](https://github.com/pallets/flask/issues/4419) * Overriding `FlaskClient.open` will not cause an error on redirect. [#3396](https://github.com/pallets/flask/issues/3396) * Add an `--exclude-patterns` option to the `flask run` CLI command to specify patterns that will be ignored by the reloader. [#4188](https://github.com/pallets/flask/issues/4188) * When using lazy loading (the default with the debugger), the Click context from the `flask run` command remains available in the loader thread. [#4460](https://github.com/pallets/flask/issues/4460) * Deleting the session cookie uses the `httponly` flag. [#4485](https://github.com/pallets/flask/issues/4485) * Relax typing for `errorhandler` to allow the user to use more precise types and decorate the same function multiple times. [#4095](https://github.com/pallets/flask/issues/4095), [#4295](https://github.com/pallets/flask/issues/4295), [#4297](https://github.com/pallets/flask/issues/4297) * Fix typing for `__exit__` methods for better compatibility with `ExitStack`. [#4474](https://github.com/pallets/flask/issues/4474) * From Werkzeug, for redirect responses the `Location` header URL will remain relative, and exclude the scheme and domain, by default. [#4496](https://github.com/pallets/flask/pull/4496) * Add `Config.from_prefixed_env()` to load config values from environment variables that start with `FLASK_` or another prefix. This parses values as JSON by default, and allows setting keys in nested dicts. [#4479](https://github.com/pallets/flask/pull/4479) Version 2.0.3 ------------- Released 2022-02-14 * The test client’s `as_tuple` parameter is deprecated and will be removed in Werkzeug 2.1. It is now also deprecated in Flask, to be removed in Flask 2.1, while remaining compatible with both in 2.0.x. Use `response.request.environ` instead. [#4341](https://github.com/pallets/flask/pull/4341) * Fix type annotation for `errorhandler` decorator. [#4295](https://github.com/pallets/flask/issues/4295) * Revert a change to the CLI that caused it to hide `ImportError` tracebacks when importing the application. [#4307](https://github.com/pallets/flask/issues/4307) * `app.json_encoder` and `json_decoder` are only passed to `dumps` and `loads` if they have custom behavior. This improves performance, mainly on PyPy. [#4349](https://github.com/pallets/flask/issues/4349) * Clearer error message when `after_this_request` is used outside a request context. [#4333](https://github.com/pallets/flask/issues/4333) Version 2.0.2 ------------- Released 2021-10-04 * Fix type annotation for `teardown_*` methods. [#4093](https://github.com/pallets/flask/issues/4093) * Fix type annotation for `before_request` and `before_app_request` decorators. [#4104](https://github.com/pallets/flask/issues/4104) * Fixed the issue where typing requires template global decorators to accept functions with no arguments. [#4098](https://github.com/pallets/flask/issues/4098) * Support View and MethodView instances with async handlers. [#4112](https://github.com/pallets/flask/issues/4112) * Enhance typing of `app.errorhandler` decorator. [#4095](https://github.com/pallets/flask/issues/4095) * Fix registering a blueprint twice with differing names. [#4124](https://github.com/pallets/flask/issues/4124) * Fix the type of `static_folder` to accept `pathlib.Path`. [#4150](https://github.com/pallets/flask/issues/4150) * `jsonify` handles `decimal.Decimal` by encoding to `str`. [#4157](https://github.com/pallets/flask/issues/4157) * Correctly handle raising deferred errors in CLI lazy loading. [#4096](https://github.com/pallets/flask/issues/4096) * The CLI loader handles `**kwargs` in a `create_app` function. [#4170](https://github.com/pallets/flask/issues/4170) * Fix the order of `before_request` and other callbacks that trigger before the view returns. They are called from the app down to the closest nested blueprint. [#4229](https://github.com/pallets/flask/issues/4229) Version 2.0.1 ------------- Released 2021-05-21 * Re-add the `filename` parameter in `send_from_directory`. The `filename` parameter has been renamed to `path`, the old name is deprecated. [#4019](https://github.com/pallets/flask/pull/4019) * Mark top-level names as exported so type checking understands imports in user projects. [#4024](https://github.com/pallets/flask/issues/4024) * Fix type annotation for `g` and inform mypy that it is a namespace object that has arbitrary attributes. [#4020](https://github.com/pallets/flask/issues/4020) * Fix some types that weren’t available in Python 3.6.0. [#4040](https://github.com/pallets/flask/issues/4040) * Improve typing for `send_file`, `send_from_directory`, and `get_send_file_max_age`. [#4044](https://github.com/pallets/flask/issues/4044), [#4026](https://github.com/pallets/flask/pull/4026) * Show an error when a blueprint name contains a dot. The `.` has special meaning, it is used to separate (nested) blueprint names and the endpoint name. [#4041](https://github.com/pallets/flask/issues/4041) * Combine URL prefixes when nesting blueprints that were created with a `url_prefix` value. [#4037](https://github.com/pallets/flask/issues/4037) * Revert a change to the order that URL matching was done. The URL is again matched after the session is loaded, so the session is available in custom URL converters. [#4053](https://github.com/pallets/flask/issues/4053) * Re-add deprecated `Config.from_json`, which was accidentally removed early. [#4078](https://github.com/pallets/flask/issues/4078) * Improve typing for some functions using `Callable` in their type signatures, focusing on decorator factories. [#4060](https://github.com/pallets/flask/issues/4060) * Nested blueprints are registered with their dotted name. This allows different blueprints with the same name to be nested at different locations. [#4069](https://github.com/pallets/flask/issues/4069) * `register_blueprint` takes a `name` option to change the (pre-dotted) name the blueprint is registered with. This allows the same blueprint to be registered multiple times with unique names for `url_for`. Registering the same blueprint with the same name multiple times is deprecated. [#1091](https://github.com/pallets/flask/issues/1091) * Improve typing for `stream_with_context`. [#4052](https://github.com/pallets/flask/issues/4052) Version 2.0.0 ------------- Released 2021-05-11 * Drop support for Python 2 and 3.5. * Bump minimum versions of other Pallets projects: Werkzeug >= 2, Jinja2 >= 3, MarkupSafe >= 2, ItsDangerous >= 2, Click >= 8. Be sure to check the change logs for each project. For better compatibility with other applications (e.g. Celery) that still require Click 7, there is no hard dependency on Click 8 yet, but using Click 7 will trigger a DeprecationWarning and Flask 2.1 will depend on Click 8. * JSON support no longer uses simplejson. To use another JSON module, override `app.json_encoder` and `json_decoder`. [#3555](https://github.com/pallets/flask/issues/3555) * The `encoding` option to JSON functions is deprecated. [#3562](https://github.com/pallets/flask/pull/3562) * Passing `script_info` to app factory functions is deprecated. This was not portable outside the `flask` command. Use `click.get_current_context().obj` if it’s needed. [#3552](https://github.com/pallets/flask/issues/3552) * The CLI shows better error messages when the app failed to load when looking up commands. [#2741](https://github.com/pallets/flask/issues/2741) * Add `SessionInterface.get_cookie_name` to allow setting the session cookie name dynamically. [#3369](https://github.com/pallets/flask/pull/3369) * Add `Config.from_file` to load config using arbitrary file loaders, such as `toml.load` or `json.load`. `Config.from_json` is deprecated in favor of this. [#3398](https://github.com/pallets/flask/pull/3398) * The `flask run` command will only defer errors on reload. Errors present during the initial call will cause the server to exit with the traceback immediately. [#3431](https://github.com/pallets/flask/issues/3431) * `send_file` raises a `ValueError` when passed an `io` object in text mode. Previously, it would respond with 200 OK and an empty file. [#3358](https://github.com/pallets/flask/issues/3358) * When using ad-hoc certificates, check for the cryptography library instead of PyOpenSSL. [#3492](https://github.com/pallets/flask/pull/3492) * When specifying a factory function with `FLASK_APP`, keyword argument can be passed. [#3553](https://github.com/pallets/flask/issues/3553) * When loading a `.env` or `.flaskenv` file, the current working directory is no longer changed to the location of the file. [#3560](https://github.com/pallets/flask/pull/3560) * When returning a `(response, headers)` tuple from a view, the headers replace rather than extend existing headers on the response. For example, this allows setting the `Content-Type` for `jsonify()`. Use `response.headers.extend()` if extending is desired. [#3628](https://github.com/pallets/flask/issues/3628) * The `Scaffold` class provides a common API for the `Flask` and `Blueprint` classes. `Blueprint` information is stored in attributes just like `Flask`, rather than opaque lambda functions. This is intended to improve consistency and maintainability. [#3215](https://github.com/pallets/flask/issues/3215) * Include `samesite` and `secure` options when removing the session cookie. [#3726](https://github.com/pallets/flask/pull/3726) * Support passing a `pathlib.Path` to `static_folder`. [#3579](https://github.com/pallets/flask/pull/3579) * `send_file` and `send_from_directory` are wrappers around the implementations in `werkzeug.utils`. [#3828](https://github.com/pallets/flask/pull/3828) * Some `send_file` parameters have been renamed, the old names are deprecated. `attachment_filename` is renamed to `download_name`. `cache_timeout` is renamed to `max_age`. `add_etags` is renamed to `etag`. [#3828](https://github.com/pallets/flask/pull/3828), [#3883](https://github.com/pallets/flask/pull/3883) * `send_file` passes `download_name` even if `as_attachment=False` by using `Content-Disposition: inline`. [#3828](https://github.com/pallets/flask/pull/3828) * `send_file` sets `conditional=True` and `max_age=None` by default. `Cache-Control` is set to `no-cache` if `max_age` is not set, otherwise `public`. This tells browsers to validate conditional requests instead of using a timed cache. [#3828](https://github.com/pallets/flask/pull/3828) * `helpers.safe_join` is deprecated. Use `werkzeug.utils.safe_join` instead. [#3828](https://github.com/pallets/flask/pull/3828) * The request context does route matching before opening the session. This could allow a session interface to change behavior based on `request.endpoint`. [#3776](https://github.com/pallets/flask/issues/3776) * Use Jinja’s implementation of the `|tojson` filter. [#3881](https://github.com/pallets/flask/issues/3881) * Add route decorators for common HTTP methods. For example, `@app.post("/login")` is a shortcut for `@app.route("/login", methods=["POST"])`. [#3907](https://github.com/pallets/flask/pull/3907) * Support async views, error handlers, before and after request, and teardown functions. [#3412](https://github.com/pallets/flask/pull/3412) * Support nesting blueprints. [#593](https://github.com/pallets/flask/issues/593), [#1548](https://github.com/pallets/flask/issues/1548), [#3923](https://github.com/pallets/flask/pull/3923) * Set the default encoding to “UTF-8” when loading `.env` and `.flaskenv` files to allow to use non-ASCII characters. [#3931](https://github.com/pallets/flask/issues/3931) * `flask shell` sets up tab and history completion like the default `python` shell if `readline` is installed. [#3941](https://github.com/pallets/flask/issues/3941) * `helpers.total_seconds()` is deprecated. Use `timedelta.total_seconds()` instead. [#3962](https://github.com/pallets/flask/pull/3962) * Add type hinting. [#3973](https://github.com/pallets/flask/pull/3973). Version 1.1.4 ------------- Released 2021-05-13 * Update `static_folder` to use `_compat.fspath` instead of `os.fspath` to continue supporting Python < 3.6 [#4050](https://github.com/pallets/flask/issues/4050) Version 1.1.3 ------------- Released 2021-05-13 * Set maximum versions of Werkzeug, Jinja, Click, and ItsDangerous. [#4043](https://github.com/pallets/flask/issues/4043) * Re-add support for passing a `pathlib.Path` for `static_folder`. [#3579](https://github.com/pallets/flask/pull/3579) Version 1.1.2 ------------- Released 2020-04-03 * Work around an issue when running the `flask` command with an external debugger on Windows. [#3297](https://github.com/pallets/flask/issues/3297) * The static route will not catch all URLs if the `Flask` `static_folder` argument ends with a slash. [#3452](https://github.com/pallets/flask/issues/3452) Version 1.1.1 ------------- Released 2019-07-08 * The `flask.json_available` flag was added back for compatibility with some extensions. It will raise a deprecation warning when used, and will be removed in version 2.0.0. [#3288](https://github.com/pallets/flask/issues/3288) Version 1.1.0 ------------- Released 2019-07-04 * Bump minimum Werkzeug version to >= 0.15. * Drop support for Python 3.4. * Error handlers for `InternalServerError` or `500` will always be passed an instance of `InternalServerError`. If they are invoked due to an unhandled exception, that original exception is now available as `e.original_exception` rather than being passed directly to the handler. The same is true if the handler is for the base `HTTPException`. This makes error handler behavior more consistent. [#3266](https://github.com/pallets/flask/pull/3266) + `Flask.finalize_request` is called for all unhandled exceptions even if there is no `500` error handler. * `Flask.logger` takes the same name as `Flask.name` (the value passed as `Flask(import_name)`. This reverts 1.0’s behavior of always logging to `"flask.app"`, in order to support multiple apps in the same process. A warning will be shown if old configuration is detected that needs to be moved. [#2866](https://github.com/pallets/flask/issues/2866) * `RequestContext.copy` includes the current session object in the request context copy. This prevents `session` pointing to an out-of-date object. [#2935](https://github.com/pallets/flask/issues/2935) * Using built-in RequestContext, unprintable Unicode characters in Host header will result in a HTTP 400 response and not HTTP 500 as previously. [#2994](https://github.com/pallets/flask/pull/2994) * `send_file` supports `PathLike` objects as described in [**PEP 519**](https://peps.python.org/pep-0519/), to support `pathlib` in Python 3. [#3059](https://github.com/pallets/flask/pull/3059) * `send_file` supports `BytesIO` partial content. [#2957](https://github.com/pallets/flask/issues/2957) * `open_resource` accepts the “rt” file mode. This still does the same thing as “r”. [#3163](https://github.com/pallets/flask/issues/3163) * The `MethodView.methods` attribute set in a base class is used by subclasses. [#3138](https://github.com/pallets/flask/issues/3138) * `Flask.jinja_options` is a `dict` instead of an `ImmutableDict` to allow easier configuration. Changes must still be made before creating the environment. [#3190](https://github.com/pallets/flask/pull/3190) * Flask’s `JSONMixin` for the request and response wrappers was moved into Werkzeug. Use Werkzeug’s version with Flask-specific support. This bumps the Werkzeug dependency to >= 0.15. [#3125](https://github.com/pallets/flask/issues/3125) * The `flask` command entry point is simplified to take advantage of Werkzeug 0.15’s better reloader support. This bumps the Werkzeug dependency to >= 0.15. [#3022](https://github.com/pallets/flask/issues/3022) * Support `static_url_path` that ends with a forward slash. [#3134](https://github.com/pallets/flask/issues/3134) * Support empty `static_folder` without requiring setting an empty `static_url_path` as well. [#3124](https://github.com/pallets/flask/pull/3124) * `jsonify` supports `dataclass` objects. [#3195](https://github.com/pallets/flask/pull/3195) * Allow customizing the `Flask.url_map_class` used for routing. [#3069](https://github.com/pallets/flask/pull/3069) * The development server port can be set to 0, which tells the OS to pick an available port. [#2926](https://github.com/pallets/flask/issues/2926) * The return value from `cli.load_dotenv` is more consistent with the documentation. It will return `False` if python-dotenv is not installed, or if the given path isn’t a file. [#2937](https://github.com/pallets/flask/issues/2937) * Signaling support has a stub for the `connect_via` method when the Blinker library is not installed. [#3208](https://github.com/pallets/flask/pull/3208) * Add an `--extra-files` option to the `flask run` CLI command to specify extra files that will trigger the reloader on change. [#2897](https://github.com/pallets/flask/issues/2897) * Allow returning a dictionary from a view function. Similar to how returning a string will produce a `text/html` response, returning a dict will call `jsonify` to produce a `application/json` response. [#3111](https://github.com/pallets/flask/pull/3111) * Blueprints have a `cli` Click group like `app.cli`. CLI commands registered with a blueprint will be available as a group under the `flask` command. [#1357](https://github.com/pallets/flask/issues/1357). * When using the test client as a context manager (`with client:`), all preserved request contexts are popped when the block exits, ensuring nested contexts are cleaned up correctly. [#3157](https://github.com/pallets/flask/pull/3157) * Show a better error message when the view return type is not supported. [#3214](https://github.com/pallets/flask/issues/3214) * `flask.testing.make_test_environ_builder()` has been deprecated in favour of a new class `flask.testing.EnvironBuilder`. [#3232](https://github.com/pallets/flask/pull/3232) * The `flask run` command no longer fails if Python is not built with SSL support. Using the `--cert` option will show an appropriate error message. [#3211](https://github.com/pallets/flask/issues/3211) * URL matching now occurs after the request context is pushed, rather than when it’s created. This allows custom URL converters to access the app and request contexts, such as to query a database for an id. [#3088](https://github.com/pallets/flask/issues/3088) Version 1.0.4 ------------- Released 2019-07-04 * The key information for `BadRequestKeyError` is no longer cleared outside debug mode, so error handlers can still access it. This requires upgrading to Werkzeug 0.15.5. [#3249](https://github.com/pallets/flask/issues/3249) * `send_file` url quotes the “:” and “/” characters for more compatible UTF-8 filename support in some browsers. [#3074](https://github.com/pallets/flask/issues/3074) * Fixes for [**PEP 451**](https://peps.python.org/pep-0451/) import loaders and pytest 5.x. [#3275](https://github.com/pallets/flask/issues/3275) * Show message about dotenv on stderr instead of stdout. [#3285](https://github.com/pallets/flask/issues/3285) Version 1.0.3 ------------- Released 2019-05-17 * `send_file` encodes filenames as ASCII instead of Latin-1 (ISO-8859-1). This fixes compatibility with Gunicorn, which is stricter about header encodings than [**PEP 3333**](https://peps.python.org/pep-3333/). [#2766](https://github.com/pallets/flask/issues/2766) * Allow custom CLIs using `FlaskGroup` to set the debug flag without it always being overwritten based on environment variables. [#2765](https://github.com/pallets/flask/pull/2765) * `flask --version` outputs Werkzeug’s version and simplifies the Python version. [#2825](https://github.com/pallets/flask/pull/2825) * `send_file` handles an `attachment_filename` that is a native Python 2 string (bytes) with UTF-8 coded bytes. [#2933](https://github.com/pallets/flask/issues/2933) * A catch-all error handler registered for `HTTPException` will not handle `RoutingException`, which is used internally during routing. This fixes the unexpected behavior that had been introduced in 1.0. [#2986](https://github.com/pallets/flask/pull/2986) * Passing the `json` argument to `app.test_client` does not push/pop an extra app context. [#2900](https://github.com/pallets/flask/issues/2900) Version 1.0.2 ------------- Released 2018-05-02 * Fix more backwards compatibility issues with merging slashes between a blueprint prefix and route. [#2748](https://github.com/pallets/flask/pull/2748) * Fix error with `flask routes` command when there are no routes. [#2751](https://github.com/pallets/flask/issues/2751) Version 1.0.1 ------------- Released 2018-04-29 * Fix registering partials (with no `__name__`) as view functions. [#2730](https://github.com/pallets/flask/pull/2730) * Don’t treat lists returned from view functions the same as tuples. Only tuples are interpreted as response data. [#2736](https://github.com/pallets/flask/issues/2736) * Extra slashes between a blueprint’s `url_prefix` and a route URL are merged. This fixes some backwards compatibility issues with the change in 1.0. [#2731](https://github.com/pallets/flask/issues/2731), [#2742](https://github.com/pallets/flask/issues/2742) * Only trap `BadRequestKeyError` errors in debug mode, not all `BadRequest` errors. This allows `abort(400)` to continue working as expected. [#2735](https://github.com/pallets/flask/issues/2735) * The `FLASK_SKIP_DOTENV` environment variable can be set to `1` to skip automatically loading dotenv files. [#2722](https://github.com/pallets/flask/issues/2722) Version 1.0 ----------- Released 2018-04-26 * Python 2.6 and 3.3 are no longer supported. * Bump minimum dependency versions to the latest stable versions: Werkzeug >= 0.14, Jinja >= 2.10, itsdangerous >= 0.24, Click >= 5.1. [#2586](https://github.com/pallets/flask/issues/2586) * Skip `app.run` when a Flask application is run from the command line. This avoids some behavior that was confusing to debug. * Change the default for `JSONIFY_PRETTYPRINT_REGULAR` to `False`. `~json.jsonify` returns a compact format by default, and an indented format in debug mode. [#2193](https://github.com/pallets/flask/pull/2193) * `Flask.__init__` accepts the `host_matching` argument and sets it on `Flask.url_map`. [#1559](https://github.com/pallets/flask/issues/1559) * `Flask.__init__` accepts the `static_host` argument and passes it as the `host` argument when defining the static route. [#1559](https://github.com/pallets/flask/issues/1559) * `send_file` supports Unicode in `attachment_filename`. [#2223](https://github.com/pallets/flask/pull/2223) * Pass `_scheme` argument from `url_for` to `Flask.handle_url_build_error`. [#2017](https://github.com/pallets/flask/pull/2017) * `Flask.add_url_rule` accepts the `provide_automatic_options` argument to disable adding the `OPTIONS` method. [#1489](https://github.com/pallets/flask/pull/1489) * `MethodView` subclasses inherit method handlers from base classes. [#1936](https://github.com/pallets/flask/pull/1936) * Errors caused while opening the session at the beginning of the request are handled by the app’s error handlers. [#2254](https://github.com/pallets/flask/pull/2254) * Blueprints gained `Blueprint.json_encoder` and `Blueprint.json_decoder` attributes to override the app’s encoder and decoder. [#1898](https://github.com/pallets/flask/pull/1898) * `Flask.make_response` raises `TypeError` instead of `ValueError` for bad response types. The error messages have been improved to describe why the type is invalid. [#2256](https://github.com/pallets/flask/pull/2256) * Add `routes` CLI command to output routes registered on the application. [#2259](https://github.com/pallets/flask/pull/2259) * Show warning when session cookie domain is a bare hostname or an IP address, as these may not behave properly in some browsers, such as Chrome. [#2282](https://github.com/pallets/flask/pull/2282) * Allow IP address as exact session cookie domain. [#2282](https://github.com/pallets/flask/pull/2282) * `SESSION_COOKIE_DOMAIN` is set if it is detected through `SERVER_NAME`. [#2282](https://github.com/pallets/flask/pull/2282) * Auto-detect zero-argument app factory called `create_app` or `make_app` from `FLASK_APP`. [#2297](https://github.com/pallets/flask/pull/2297) * Factory functions are not required to take a `script_info` parameter to work with the `flask` command. If they take a single parameter or a parameter named `script_info`, the `ScriptInfo` object will be passed. [#2319](https://github.com/pallets/flask/pull/2319) * `FLASK_APP` can be set to an app factory, with arguments if needed, for example `FLASK_APP=myproject.app:create_app('dev')`. [#2326](https://github.com/pallets/flask/pull/2326) * `FLASK_APP` can point to local packages that are not installed in editable mode, although `pip install -e` is still preferred. [#2414](https://github.com/pallets/flask/pull/2414) * The `View` class attribute `View.provide_automatic_options` is set in `View.as_view`, to be detected by `Flask.add_url_rule`. [#2316](https://github.com/pallets/flask/pull/2316) * Error handling will try handlers registered for `blueprint, code`, `app, code`, `blueprint, exception`, `app, exception`. [#2314](https://github.com/pallets/flask/pull/2314) * `Cookie` is added to the response’s `Vary` header if the session is accessed at all during the request (and not deleted). [#2288](https://github.com/pallets/flask/pull/2288) * `Flask.test_request_context` accepts `subdomain` and `url_scheme` arguments for use when building the base URL. [#1621](https://github.com/pallets/flask/pull/1621) * Set `APPLICATION_ROOT` to `'/'` by default. This was already the implicit default when it was set to `None`. * `TRAP_BAD_REQUEST_ERRORS` is enabled by default in debug mode. `BadRequestKeyError` has a message with the bad key in debug mode instead of the generic bad request message. [#2348](https://github.com/pallets/flask/pull/2348) * Allow registering new tags with `TaggedJSONSerializer` to support storing other types in the session cookie. [#2352](https://github.com/pallets/flask/pull/2352) * Only open the session if the request has not been pushed onto the context stack yet. This allows `stream_with_context` generators to access the same session that the containing view uses. [#2354](https://github.com/pallets/flask/pull/2354) * Add `json` keyword argument for the test client request methods. This will dump the given object as JSON and set the appropriate content type. [#2358](https://github.com/pallets/flask/pull/2358) * Extract JSON handling to a mixin applied to both the `Request` and `Response` classes. This adds the `Response.is_json` and `Response.get_json` methods to the response to make testing JSON response much easier. [#2358](https://github.com/pallets/flask/pull/2358) * Removed error handler caching because it caused unexpected results for some exception inheritance hierarchies. Register handlers explicitly for each exception if you want to avoid traversing the MRO. [#2362](https://github.com/pallets/flask/pull/2362) * Fix incorrect JSON encoding of aware, non-UTC datetimes. [#2374](https://github.com/pallets/flask/pull/2374) * Template auto reloading will honor debug mode even even if `Flask.jinja_env` was already accessed. [#2373](https://github.com/pallets/flask/pull/2373) * The following old deprecated code was removed. [#2385](https://github.com/pallets/flask/issues/2385) + `flask.ext` - import extensions directly by their name instead of through the `flask.ext` namespace. For example, `import flask.ext.sqlalchemy` becomes `import flask_sqlalchemy`. + `Flask.init_jinja_globals` - extend `Flask.create_jinja_environment` instead. + `Flask.error_handlers` - tracked by `Flask.error_handler_spec`, use `Flask.errorhandler` to register handlers. + `Flask.request_globals_class` - use `Flask.app_ctx_globals_class` instead. + `Flask.static_path` - use `Flask.static_url_path` instead. + `Request.module` - use `Request.blueprint` instead. * The `Request.json` property is no longer deprecated. [#1421](https://github.com/pallets/flask/issues/1421) * Support passing a `EnvironBuilder` or `dict` to `test_client.open`. [#2412](https://github.com/pallets/flask/pull/2412) * The `flask` command and `Flask.run` will load environment variables from `.env` and `.flaskenv` files if python-dotenv is installed. [#2416](https://github.com/pallets/flask/pull/2416) * When passing a full URL to the test client, the scheme in the URL is used instead of `PREFERRED_URL_SCHEME`. [#2430](https://github.com/pallets/flask/pull/2430) * `Flask.logger` has been simplified. `LOGGER_NAME` and `LOGGER_HANDLER_POLICY` config was removed. The logger is always named `flask.app`. The level is only set on first access, it doesn’t check `Flask.debug` each time. Only one format is used, not different ones depending on `Flask.debug`. No handlers are removed, and a handler is only added if no handlers are already configured. [#2436](https://github.com/pallets/flask/pull/2436) * Blueprint view function names may not contain dots. [#2450](https://github.com/pallets/flask/pull/2450) * Fix a `ValueError` caused by invalid `Range` requests in some cases. [#2526](https://github.com/pallets/flask/issues/2526) * The development server uses threads by default. [#2529](https://github.com/pallets/flask/pull/2529) * Loading config files with `silent=True` will ignore `ENOTDIR` errors. [#2581](https://github.com/pallets/flask/pull/2581) * Pass `--cert` and `--key` options to `flask run` to run the development server over HTTPS. [#2606](https://github.com/pallets/flask/pull/2606) * Added `SESSION_COOKIE_SAMESITE` to control the `SameSite` attribute on the session cookie. [#2607](https://github.com/pallets/flask/pull/2607) * Added `Flask.test_cli_runner` to create a Click runner that can invoke Flask CLI commands for testing. [#2636](https://github.com/pallets/flask/pull/2636) * Subdomain matching is disabled by default and setting `SERVER_NAME` does not implicitly enable it. It can be enabled by passing `subdomain_matching=True` to the `Flask` constructor. [#2635](https://github.com/pallets/flask/pull/2635) * A single trailing slash is stripped from the blueprint `url_prefix` when it is registered with the app. [#2629](https://github.com/pallets/flask/pull/2629) * `Request.get_json` doesn’t cache the result if parsing fails when `silent` is true. [#2651](https://github.com/pallets/flask/issues/2651) * `Request.get_json` no longer accepts arbitrary encodings. Incoming JSON should be encoded using UTF-8 per [**RFC 8259**](https://datatracker.ietf.org/doc/html/rfc8259.html), but Flask will autodetect UTF-8, -16, or -32. [#2691](https://github.com/pallets/flask/pull/2691) * Added `MAX_COOKIE_SIZE` and `Response.max_cookie_size` to control when Werkzeug warns about large cookies that browsers may ignore. [#2693](https://github.com/pallets/flask/pull/2693) * Updated documentation theme to make docs look better in small windows. [#2709](https://github.com/pallets/flask/pull/2709) * Rewrote the tutorial docs and example project to take a more structured approach to help new users avoid common pitfalls. [#2676](https://github.com/pallets/flask/pull/2676) Version 0.12.5 -------------- Released 2020-02-10 * Pin Werkzeug to < 1.0.0. [#3497](https://github.com/pallets/flask/issues/3497) Version 0.12.4 -------------- Released 2018-04-29 * Repackage 0.12.3 to fix package layout issue. [#2728](https://github.com/pallets/flask/issues/2728) Version 0.12.3 -------------- Released 2018-04-26 * `Request.get_json` no longer accepts arbitrary encodings. Incoming JSON should be encoded using UTF-8 per [**RFC 8259**](https://datatracker.ietf.org/doc/html/rfc8259.html), but Flask will autodetect UTF-8, -16, or -32. [#2692](https://github.com/pallets/flask/issues/2692) * Fix a Python warning about imports when using `python -m flask`. [#2666](https://github.com/pallets/flask/issues/2666) * Fix a `ValueError` caused by invalid `Range` requests in some cases. Version 0.12.2 -------------- Released 2017-05-16 * Fix a bug in `safe_join` on Windows. Version 0.12.1 -------------- Released 2017-03-31 * Prevent `flask run` from showing a `NoAppException` when an `ImportError` occurs within the imported application module. * Fix encoding behavior of `app.config.from_pyfile` for Python 3. [#2118](https://github.com/pallets/flask/issues/2118) * Use the `SERVER_NAME` config if it is present as default values for `app.run`. [#2109](https://github.com/pallets/flask/issues/2109), [#2152](https://github.com/pallets/flask/pull/2152) * Call `ctx.auto_pop` with the exception object instead of `None`, in the event that a `BaseException` such as `KeyboardInterrupt` is raised in a request handler. Version 0.12 ------------ Released 2016-12-21, codename Punsch * The cli command now responds to `--version`. * Mimetype guessing and ETag generation for file-like objects in `send_file` has been removed. [#104](https://github.com/pallets/flask/issues/104), :pr`1849` * Mimetype guessing in `send_file` now fails loudly and doesn’t fall back to `application/octet-stream`. [#1988](https://github.com/pallets/flask/pull/1988) * Make `flask.safe_join` able to join multiple paths like `os.path.join` [#1730](https://github.com/pallets/flask/pull/1730) * Revert a behavior change that made the dev server crash instead of returning an Internal Server Error. [#2006](https://github.com/pallets/flask/pull/2006) * Correctly invoke response handlers for both regular request dispatching as well as error handlers. * Disable logger propagation by default for the app logger. * Add support for range requests in `send_file`. * `app.test_client` includes preset default environment, which can now be directly set, instead of per `client.get`. * Fix crash when running under PyPy3. [#1814](https://github.com/pallets/flask/pull/1814) Version 0.11.1 -------------- Released 2016-06-07 * Fixed a bug that prevented `FLASK_APP=foobar/__init__.py` from working. [#1872](https://github.com/pallets/flask/pull/1872) Version 0.11 ------------ Released 2016-05-29, codename Absinthe * Added support to serializing top-level arrays to `jsonify`. This introduces a security risk in ancient browsers. * Added before\_render\_template signal. * Added `**kwargs` to `Flask.test_client` to support passing additional keyword arguments to the constructor of `Flask.test_client_class`. * Added `SESSION_REFRESH_EACH_REQUEST` config key that controls the set-cookie behavior. If set to `True` a permanent session will be refreshed each request and get their lifetime extended, if set to `False` it will only be modified if the session actually modifies. Non permanent sessions are not affected by this and will always expire if the browser window closes. * Made Flask support custom JSON mimetypes for incoming data. * Added support for returning tuples in the form `(response, headers)` from a view function. * Added `Config.from_json`. * Added `Flask.config_class`. * Added `Config.get_namespace`. * Templates are no longer automatically reloaded outside of debug mode. This can be configured with the new `TEMPLATES_AUTO_RELOAD` config key. * Added a workaround for a limitation in Python 3.3’s namespace loader. * Added support for explicit root paths when using Python 3.3’s namespace packages. * Added `flask` and the `flask.cli` module to start the local debug server through the click CLI system. This is recommended over the old `flask.run()` method as it works faster and more reliable due to a different design and also replaces `Flask-Script`. * Error handlers that match specific classes are now checked first, thereby allowing catching exceptions that are subclasses of HTTP exceptions (in `werkzeug.exceptions`). This makes it possible for an extension author to create exceptions that will by default result in the HTTP error of their choosing, but may be caught with a custom error handler if desired. * Added `Config.from_mapping`. * Flask will now log by default even if debug is disabled. The log format is now hardcoded but the default log handling can be disabled through the `LOGGER_HANDLER_POLICY` configuration key. * Removed deprecated module functionality. * Added the `EXPLAIN_TEMPLATE_LOADING` config flag which when enabled will instruct Flask to explain how it locates templates. This should help users debug when the wrong templates are loaded. * Enforce blueprint handling in the order they were registered for template loading. * Ported test suite to py.test. * Deprecated `request.json` in favour of `request.get_json()`. * Add “pretty” and “compressed” separators definitions in jsonify() method. Reduces JSON response size when `JSONIFY_PRETTYPRINT_REGULAR=False` by removing unnecessary white space included by default after separators. * JSON responses are now terminated with a newline character, because it is a convention that UNIX text files end with a newline and some clients don’t deal well when this newline is missing. [#1262](https://github.com/pallets/flask/pull/1262) * The automatically provided `OPTIONS` method is now correctly disabled if the user registered an overriding rule with the lowercase-version `options`. [#1288](https://github.com/pallets/flask/issues/1288) * `flask.json.jsonify` now supports the `datetime.date` type. [#1326](https://github.com/pallets/flask/pull/1326) * Don’t leak exception info of already caught exceptions to context teardown handlers. [#1393](https://github.com/pallets/flask/pull/1393) * Allow custom Jinja environment subclasses. [#1422](https://github.com/pallets/flask/pull/1422) * Updated extension dev guidelines. * `flask.g` now has `pop()` and `setdefault` methods. * Turn on autoescape for `flask.templating.render_template_string` by default. [#1515](https://github.com/pallets/flask/pull/1515) * `flask.ext` is now deprecated. [#1484](https://github.com/pallets/flask/pull/1484) * `send_from_directory` now raises BadRequest if the filename is invalid on the server OS. [#1763](https://github.com/pallets/flask/pull/1763) * Added the `JSONIFY_MIMETYPE` configuration variable. [#1728](https://github.com/pallets/flask/pull/1728) * Exceptions during teardown handling will no longer leave bad application contexts lingering around. * Fixed broken `test_appcontext_signals()` test case. * Raise an `AttributeError` in `helpers.find_package` with a useful message explaining why it is raised when a [**PEP 302**](https://peps.python.org/pep-0302/) import hook is used without an `is_package()` method. * Fixed an issue causing exceptions raised before entering a request or app context to be passed to teardown handlers. * Fixed an issue with query parameters getting removed from requests in the test client when absolute URLs were requested. * Made `@before_first_request` into a decorator as intended. * Fixed an etags bug when sending a file streams with a name. * Fixed `send_from_directory` not expanding to the application root path correctly. * Changed logic of before first request handlers to flip the flag after invoking. This will allow some uses that are potentially dangerous but should probably be permitted. * Fixed Python 3 bug when a handler from `app.url_build_error_handlers` reraises the `BuildError`. Version 0.10.1 -------------- Released 2013-06-14 * Fixed an issue where `|tojson` was not quoting single quotes which made the filter not work properly in HTML attributes. Now it’s possible to use that filter in single quoted attributes. This should make using that filter with angular.js easier. * Added support for byte strings back to the session system. This broke compatibility with the common case of people putting binary data for token verification into the session. * Fixed an issue where registering the same method twice for the same endpoint would trigger an exception incorrectly. Version 0.10 ------------ Released 2013-06-13, codename Limoncello * Changed default cookie serialization format from pickle to JSON to limit the impact an attacker can do if the secret key leaks. * Added `template_test` methods in addition to the already existing `template_filter` method family. * Added `template_global` methods in addition to the already existing `template_filter` method family. * Set the content-length header for x-sendfile. * `tojson` filter now does not escape script blocks in HTML5 parsers. * `tojson` used in templates is now safe by default. This was allowed due to the different escaping behavior. * Flask will now raise an error if you attempt to register a new function on an already used endpoint. * Added wrapper module around simplejson and added default serialization of datetime objects. This allows much easier customization of how JSON is handled by Flask or any Flask extension. * Removed deprecated internal `flask.session` module alias. Use `flask.sessions` instead to get the session module. This is not to be confused with `flask.session` the session proxy. * Templates can now be rendered without request context. The behavior is slightly different as the `request`, `session` and `g` objects will not be available and blueprint’s context processors are not called. * The config object is now available to the template as a real global and not through a context processor which makes it available even in imported templates by default. * Added an option to generate non-ascii encoded JSON which should result in less bytes being transmitted over the network. It’s disabled by default to not cause confusion with existing libraries that might expect `flask.json.dumps` to return bytes by default. * `flask.g` is now stored on the app context instead of the request context. * `flask.g` now gained a `get()` method for not erroring out on non existing items. * `flask.g` now can be used with the `in` operator to see what’s defined and it now is iterable and will yield all attributes stored. * `flask.Flask.request_globals_class` got renamed to `flask.Flask.app_ctx_globals_class` which is a better name to what it does since 0.10. * `request`, `session` and `g` are now also added as proxies to the template context which makes them available in imported templates. One has to be very careful with those though because usage outside of macros might cause caching. * Flask will no longer invoke the wrong error handlers if a proxy exception is passed through. * Added a workaround for chrome’s cookies in localhost not working as intended with domain names. * Changed logic for picking defaults for cookie values from sessions to work better with Google Chrome. * Added `message_flashed` signal that simplifies flashing testing. * Added support for copying of request contexts for better working with greenlets. * Removed custom JSON HTTP exception subclasses. If you were relying on them you can reintroduce them again yourself trivially. Using them however is strongly discouraged as the interface was flawed. * Python requirements changed: requiring Python 2.6 or 2.7 now to prepare for Python 3.3 port. * Changed how the teardown system is informed about exceptions. This is now more reliable in case something handles an exception halfway through the error handling process. * Request context preservation in debug mode now keeps the exception information around which means that teardown handlers are able to distinguish error from success cases. * Added the `JSONIFY_PRETTYPRINT_REGULAR` configuration variable. * Flask now orders JSON keys by default to not trash HTTP caches due to different hash seeds between different workers. * Added `appcontext_pushed` and `appcontext_popped` signals. * The builtin run method now takes the `SERVER_NAME` into account when picking the default port to run on. * Added `flask.request.get_json()` as a replacement for the old `flask.request.json` property. Version 0.9 ----------- Released 2012-07-01, codename Campari * The `Request.on_json_loading_failed` now returns a JSON formatted response by default. * The `url_for` function now can generate anchors to the generated links. * The `url_for` function now can also explicitly generate URL rules specific to a given HTTP method. * Logger now only returns the debug log setting if it was not set explicitly. * Unregister a circular dependency between the WSGI environment and the request object when shutting down the request. This means that environ `werkzeug.request` will be `None` after the response was returned to the WSGI server but has the advantage that the garbage collector is not needed on CPython to tear down the request unless the user created circular dependencies themselves. * Session is now stored after callbacks so that if the session payload is stored in the session you can still modify it in an after request callback. * The `Flask` class will avoid importing the provided import name if it can (the required first parameter), to benefit tools which build Flask instances programmatically. The Flask class will fall back to using import on systems with custom module hooks, e.g. Google App Engine, or when the import name is inside a zip archive (usually an egg) prior to Python 2.7. * Blueprints now have a decorator to add custom template filters application wide, `Blueprint.app_template_filter`. * The Flask and Blueprint classes now have a non-decorator method for adding custom template filters application wide, `Flask.add_template_filter` and `Blueprint.add_app_template_filter`. * The `get_flashed_messages` function now allows rendering flashed message categories in separate blocks, through a `category_filter` argument. * The `Flask.run` method now accepts `None` for `host` and `port` arguments, using default values when `None`. This allows for calling run using configuration values, e.g. `app.run(app.config.get('MYHOST'), app.config.get('MYPORT'))`, with proper behavior whether or not a config file is provided. * The `render_template` method now accepts a either an iterable of template names or a single template name. Previously, it only accepted a single template name. On an iterable, the first template found is rendered. * Added `Flask.app_context` which works very similar to the request context but only provides access to the current application. This also adds support for URL generation without an active request context. * View functions can now return a tuple with the first instance being an instance of `Response`. This allows for returning `jsonify(error="error msg"), 400` from a view function. * `Flask` and `Blueprint` now provide a `get_send_file_max_age` hook for subclasses to override behavior of serving static files from Flask when using `Flask.send_static_file` (used for the default static file handler) and `helpers.send_file`. This hook is provided a filename, which for example allows changing cache controls by file extension. The default max-age for `send_file` and static files can be configured through a new `SEND_FILE_MAX_AGE_DEFAULT` configuration variable, which is used in the default `get_send_file_max_age` implementation. * Fixed an assumption in sessions implementation which could break message flashing on sessions implementations which use external storage. * Changed the behavior of tuple return values from functions. They are no longer arguments to the response object, they now have a defined meaning. * Added `Flask.request_globals_class` to allow a specific class to be used on creation of the `g` instance of each request. * Added `required_methods` attribute to view functions to force-add methods on registration. * Added `flask.after_this_request`. * Added `flask.stream_with_context` and the ability to push contexts multiple times without producing unexpected behavior. Version 0.8.1 ------------- Released 2012-07-01 * Fixed an issue with the undocumented `flask.session` module to not work properly on Python 2.5. It should not be used but did cause some problems for package managers. Version 0.8 ----------- Released 2011-09-29, codename Rakija * Refactored session support into a session interface so that the implementation of the sessions can be changed without having to override the Flask class. * Empty session cookies are now deleted properly automatically. * View functions can now opt out of getting the automatic OPTIONS implementation. * HTTP exceptions and Bad Request errors can now be trapped so that they show up normally in the traceback. * Flask in debug mode is now detecting some common problems and tries to warn you about them. * Flask in debug mode will now complain with an assertion error if a view was attached after the first request was handled. This gives earlier feedback when users forget to import view code ahead of time. * Added the ability to register callbacks that are only triggered once at the beginning of the first request with `Flask.before_first_request`. * Malformed JSON data will now trigger a bad request HTTP exception instead of a value error which usually would result in a 500 internal server error if not handled. This is a backwards incompatible change. * Applications now not only have a root path where the resources and modules are located but also an instance path which is the designated place to drop files that are modified at runtime (uploads etc.). Also this is conceptually only instance depending and outside version control so it’s the perfect place to put configuration files etc. * Added the `APPLICATION_ROOT` configuration variable. * Implemented `TestClient.session_transaction` to easily modify sessions from the test environment. * Refactored test client internally. The `APPLICATION_ROOT` configuration variable as well as `SERVER_NAME` are now properly used by the test client as defaults. * Added `View.decorators` to support simpler decorating of pluggable (class-based) views. * Fixed an issue where the test client if used with the “with” statement did not trigger the execution of the teardown handlers. * Added finer control over the session cookie parameters. * HEAD requests to a method view now automatically dispatch to the `get` method if no handler was implemented. * Implemented the virtual `flask.ext` package to import extensions from. * The context preservation on exceptions is now an integral component of Flask itself and no longer of the test client. This cleaned up some internal logic and lowers the odds of runaway request contexts in unittests. * Fixed the Jinja2 environment’s `list_templates` method not returning the correct names when blueprints or modules were involved. Version 0.7.2 ------------- Released 2011-07-06 * Fixed an issue with URL processors not properly working on blueprints. Version 0.7.1 ------------- Released 2011-06-29 * Added missing future import that broke 2.5 compatibility. * Fixed an infinite redirect issue with blueprints. Version 0.7 ----------- Released 2011-06-28, codename Grappa * Added `Flask.make_default_options_response` which can be used by subclasses to alter the default behavior for `OPTIONS` responses. * Unbound locals now raise a proper `RuntimeError` instead of an `AttributeError`. * Mimetype guessing and etag support based on file objects is now deprecated for `send_file` because it was unreliable. Pass filenames instead or attach your own etags and provide a proper mimetype by hand. * Static file handling for modules now requires the name of the static folder to be supplied explicitly. The previous autodetection was not reliable and caused issues on Google’s App Engine. Until 1.0 the old behavior will continue to work but issue dependency warnings. * Fixed a problem for Flask to run on jython. * Added a `PROPAGATE_EXCEPTIONS` configuration variable that can be used to flip the setting of exception propagation which previously was linked to `DEBUG` alone and is now linked to either `DEBUG` or `TESTING`. * Flask no longer internally depends on rules being added through the `add_url_rule` function and can now also accept regular werkzeug rules added to the url map. * Added an `endpoint` method to the flask application object which allows one to register a callback to an arbitrary endpoint with a decorator. * Use Last-Modified for static file sending instead of Date which was incorrectly introduced in 0.6. * Added `create_jinja_loader` to override the loader creation process. * Implemented a silent flag for `config.from_pyfile`. * Added `teardown_request` decorator, for functions that should run at the end of a request regardless of whether an exception occurred. Also the behavior for `after_request` was changed. It’s now no longer executed when an exception is raised. * Implemented `has_request_context`. * Deprecated `init_jinja_globals`. Override the `Flask.create_jinja_environment` method instead to achieve the same functionality. * Added `safe_join`. * The automatic JSON request data unpacking now looks at the charset mimetype parameter. * Don’t modify the session on `get_flashed_messages` if there are no messages in the session. * `before_request` handlers are now able to abort requests with errors. * It is not possible to define user exception handlers. That way you can provide custom error messages from a central hub for certain errors that might occur during request processing (for instance database connection errors, timeouts from remote resources etc.). * Blueprints can provide blueprint specific error handlers. * Implemented generic class-based views. Version 0.6.1 ------------- Released 2010-12-31 * Fixed an issue where the default `OPTIONS` response was not exposing all valid methods in the `Allow` header. * Jinja2 template loading syntax now allows “./” in front of a template load path. Previously this caused issues with module setups. * Fixed an issue where the subdomain setting for modules was ignored for the static folder. * Fixed a security problem that allowed clients to download arbitrary files if the host server was a windows based operating system and the client uses backslashes to escape the directory the files where exposed from. Version 0.6 ----------- Released 2010-07-27, codename Whisky * After request functions are now called in reverse order of registration. * OPTIONS is now automatically implemented by Flask unless the application explicitly adds ‘OPTIONS’ as method to the URL rule. In this case no automatic OPTIONS handling kicks in. * Static rules are now even in place if there is no static folder for the module. This was implemented to aid GAE which will remove the static folder if it’s part of a mapping in the .yml file. * `Flask.config` is now available in the templates as `config`. * Context processors will no longer override values passed directly to the render function. * Added the ability to limit the incoming request data with the new `MAX_CONTENT_LENGTH` configuration value. * The endpoint for the `Module.add_url_rule` method is now optional to be consistent with the function of the same name on the application object. * Added a `make_response` function that simplifies creating response object instances in views. * Added signalling support based on blinker. This feature is currently optional and supposed to be used by extensions and applications. If you want to use it, make sure to have `blinker` installed. * Refactored the way URL adapters are created. This process is now fully customizable with the `Flask.create_url_adapter` method. * Modules can now register for a subdomain instead of just an URL prefix. This makes it possible to bind a whole module to a configurable subdomain. Version 0.5.2 ------------- Released 2010-07-15 * Fixed another issue with loading templates from directories when modules were used. Version 0.5.1 ------------- Released 2010-07-06 * Fixes an issue with template loading from directories when modules where used. Version 0.5 ----------- Released 2010-07-06, codename Calvados * Fixed a bug with subdomains that was caused by the inability to specify the server name. The server name can now be set with the `SERVER_NAME` config key. This key is now also used to set the session cookie cross-subdomain wide. * Autoescaping is no longer active for all templates. Instead it is only active for `.html`, `.htm`, `.xml` and `.xhtml`. Inside templates this behavior can be changed with the `autoescape` tag. * Refactored Flask internally. It now consists of more than a single file. * `send_file` now emits etags and has the ability to do conditional responses builtin. * (temporarily) dropped support for zipped applications. This was a rarely used feature and led to some confusing behavior. * Added support for per-package template and static-file directories. * Removed support for `create_jinja_loader` which is no longer used in 0.5 due to the improved module support. * Added a helper function to expose files from any directory. Version 0.4 ----------- Released 2010-06-18, codename Rakia * Added the ability to register application wide error handlers from modules. * `Flask.after_request` handlers are now also invoked if the request dies with an exception and an error handling page kicks in. * Test client has not the ability to preserve the request context for a little longer. This can also be used to trigger custom requests that do not pop the request stack for testing. * Because the Python standard library caches loggers, the name of the logger is configurable now to better support unittests. * Added `TESTING` switch that can activate unittesting helpers. * The logger switches to `DEBUG` mode now if debug is enabled. Version 0.3.1 ------------- Released 2010-05-28 * Fixed a error reporting bug with `Config.from_envvar`. * Removed some unused code. * Release does no longer include development leftover files (.git folder for themes, built documentation in zip and pdf file and some .pyc files) Version 0.3 ----------- Released 2010-05-28, codename Schnaps * Added support for categories for flashed messages. * The application now configures a `logging.Handler` and will log request handling exceptions to that logger when not in debug mode. This makes it possible to receive mails on server errors for example. * Added support for context binding that does not require the use of the with statement for playing in the console. * The request context is now available within the with statement making it possible to further push the request context or pop it. * Added support for configurations. Version 0.2 ----------- Released 2010-05-12, codename J?germeister * Various bugfixes * Integrated JSON support * Added `get_template_attribute` helper function. * `Flask.add_url_rule` can now also register a view function. * Refactored internal request dispatching. * Server listens on 127.0.0.1 by default now to fix issues with chrome. * Added external URL support. * Added support for `send_file`. * Module support and internal request handling refactoring to better support pluggable applications. * Sessions can be set to be permanent now on a per-session basis. * Better error reporting on missing secret keys. * Added support for Google Appengine. Version 0.1 ----------- Released 2010-04-16 * First public preview release.
programming_docs
flask Signals Signals ======= Changelog New in version 0.6. Starting with Flask 0.6, there is integrated support for signalling in Flask. This support is provided by the excellent [blinker](https://pypi.org/project/blinker/) library and will gracefully fall back if it is not available. What are signals? Signals help you decouple applications by sending notifications when actions occur elsewhere in the core framework or another Flask extensions. In short, signals allow certain senders to notify subscribers that something happened. Flask comes with a couple of signals and other extensions might provide more. Also keep in mind that signals are intended to notify subscribers and should not encourage subscribers to modify data. You will notice that there are signals that appear to do the same thing like some of the builtin decorators do (eg: [`request_started`](../api/index#flask.request_started "flask.request_started") is very similar to [`before_request()`](../api/index#flask.Flask.before_request "flask.Flask.before_request")). However, there are differences in how they work. The core [`before_request()`](../api/index#flask.Flask.before_request "flask.Flask.before_request") handler, for example, is executed in a specific order and is able to abort the request early by returning a response. In contrast all signal handlers are executed in undefined order and do not modify any data. The big advantage of signals over handlers is that you can safely subscribe to them for just a split second. These temporary subscriptions are helpful for unit testing for example. Say you want to know what templates were rendered as part of a request: signals allow you to do exactly that. Subscribing to Signals ---------------------- To subscribe to a signal, you can use the [`connect()`](https://blinker.readthedocs.io/en/stable/#blinker.base.Signal.connect "(in Blinker v1.5)") method of a signal. The first argument is the function that should be called when the signal is emitted, the optional second argument specifies a sender. To unsubscribe from a signal, you can use the [`disconnect()`](https://blinker.readthedocs.io/en/stable/#blinker.base.Signal.disconnect "(in Blinker v1.5)") method. For all core Flask signals, the sender is the application that issued the signal. When you subscribe to a signal, be sure to also provide a sender unless you really want to listen for signals from all applications. This is especially true if you are developing an extension. For example, here is a helper context manager that can be used in a unit test to determine which templates were rendered and what variables were passed to the template: ``` from flask import template_rendered from contextlib import contextmanager @contextmanager def captured_templates(app): recorded = [] def record(sender, template, context, **extra): recorded.append((template, context)) template_rendered.connect(record, app) try: yield recorded finally: template_rendered.disconnect(record, app) ``` This can now easily be paired with a test client: ``` with captured_templates(app) as templates: rv = app.test_client().get('/') assert rv.status_code == 200 assert len(templates) == 1 template, context = templates[0] assert template.name == 'index.html' assert len(context['items']) == 10 ``` Make sure to subscribe with an extra `**extra` argument so that your calls don’t fail if Flask introduces new arguments to the signals. All the template rendering in the code issued by the application `app` in the body of the `with` block will now be recorded in the `templates` variable. Whenever a template is rendered, the template object as well as context are appended to it. Additionally there is a convenient helper method ([`connected_to()`](https://blinker.readthedocs.io/en/stable/#blinker.base.Signal.connected_to "(in Blinker v1.5)")) that allows you to temporarily subscribe a function to a signal with a context manager on its own. Because the return value of the context manager cannot be specified that way, you have to pass the list in as an argument: ``` from flask import template_rendered def captured_templates(app, recorded, **extra): def record(sender, template, context): recorded.append((template, context)) return template_rendered.connected_to(record, app) ``` The example above would then look like this: ``` templates = [] with captured_templates(app, templates, **extra): ... template, context = templates[0] ``` Blinker API Changes The [`connected_to()`](https://blinker.readthedocs.io/en/stable/#blinker.base.Signal.connected_to "(in Blinker v1.5)") method arrived in Blinker with version 1.1. Creating Signals ---------------- If you want to use signals in your own application, you can use the blinker library directly. The most common use case are named signals in a custom [`Namespace`](https://blinker.readthedocs.io/en/stable/#blinker.base.Namespace "(in Blinker v1.5)").. This is what is recommended most of the time: ``` from blinker import Namespace my_signals = Namespace() ``` Now you can create new signals like this: ``` model_saved = my_signals.signal('model-saved') ``` The name for the signal here makes it unique and also simplifies debugging. You can access the name of the signal with the [`name`](https://blinker.readthedocs.io/en/stable/#blinker.base.NamedSignal.name "(in Blinker v1.5)") attribute. For Extension Developers If you are writing a Flask extension and you want to gracefully degrade for missing blinker installations, you can do so by using the [`flask.signals.Namespace`](../api/index#flask.signals.Namespace "flask.signals.Namespace") class. Sending Signals --------------- If you want to emit a signal, you can do so by calling the [`send()`](https://blinker.readthedocs.io/en/stable/#blinker.base.Signal.send "(in Blinker v1.5)") method. It accepts a sender as first argument and optionally some keyword arguments that are forwarded to the signal subscribers: ``` class Model(object): ... def save(self): model_saved.send(self) ``` Try to always pick a good sender. If you have a class that is emitting a signal, pass `self` as sender. If you are emitting a signal from a random function, you can pass `current_app._get_current_object()` as sender. Passing Proxies as Senders Never pass [`current_app`](../api/index#flask.current_app "flask.current_app") as sender to a signal. Use `current_app._get_current_object()` instead. The reason for this is that [`current_app`](../api/index#flask.current_app "flask.current_app") is a proxy and not the real application object. Signals and Flask’s Request Context ----------------------------------- Signals fully support [The Request Context](../reqcontext/index) when receiving signals. Context-local variables are consistently available between [`request_started`](../api/index#flask.request_started "flask.request_started") and [`request_finished`](../api/index#flask.request_finished "flask.request_finished"), so you can rely on [`flask.g`](../api/index#flask.g "flask.g") and others as needed. Note the limitations described in [Sending Signals](#signals-sending) and the [`request_tearing_down`](../api/index#flask.request_tearing_down "flask.request_tearing_down") signal. Decorator Based Signal Subscriptions ------------------------------------ With Blinker 1.1 you can also easily subscribe to signals by using the new `connect_via()` decorator: ``` from flask import template_rendered @template_rendered.connect_via(app) def when_template_rendered(sender, template, context, **extra): print(f'Template {template.name} is rendered with {context}') ``` Core Signals ------------ Take a look at [Signals](../api/index#core-signals-list) for a list of all builtin signals. flask Debugging Application Errors Debugging Application Errors ============================ In Production ------------- **Do not run the development server, or enable the built-in debugger, in a production environment.** The debugger allows executing arbitrary Python code from the browser. It’s protected by a pin, but that should not be relied on for security. Use an error logging tool, such as Sentry, as described in [Error Logging Tools](../errorhandling/index#error-logging-tools), or enable logging and notifications as described in [Logging](../logging/index). If you have access to the server, you could add some code to start an external debugger if `request.remote_addr` matches your IP. Some IDE debuggers also have a remote mode so breakpoints on the server can be interacted with locally. Only enable a debugger temporarily. The Built-In Debugger --------------------- The built-in Werkzeug development server provides a debugger which shows an interactive traceback in the browser when an unhandled error occurs during a request. This debugger should only be used during development. Warning The debugger allows executing arbitrary Python code from the browser. It is protected by a pin, but still represents a major security risk. Do not run the development server or debugger in a production environment. The debugger is enabled by default when the development server is run in debug mode. ``` $ flask --app hello --debug run ``` When running from Python code, passing `debug=True` enables debug mode, which is mostly equivalent. ``` app.run(debug=True) ``` [Development Server](../server/index) and [Command Line Interface](../cli/index) have more information about running the debugger and debug mode. More information about the debugger can be found in the [Werkzeug documentation](https://werkzeug.palletsprojects.com/debug/). External Debuggers ------------------ External debuggers, such as those provided by IDEs, can offer a more powerful debugging experience than the built-in debugger. They can also be used to step through code during a request before an error is raised, or if no error is raised. Some even have a remote mode so you can debug code running on another machine. When using an external debugger, the app should still be in debug mode, but it can be useful to disable the built-in debugger and reloader, which can interfere. ``` $ flask --app hello --debug run --no-debugger --no-reload ``` When running from Python: ``` app.run(debug=True, use_debugger=False, use_reloader=False) ``` Disabling these isn’t required, an external debugger will continue to work with the following caveats. If the built-in debugger is not disabled, it will catch unhandled exceptions before the external debugger can. If the reloader is not disabled, it could cause an unexpected reload if code changes during debugging. flask The Request Context The Request Context =================== The request context keeps track of the request-level data during a request. Rather than passing the request object to each function that runs during a request, the [`request`](../api/index#flask.request "flask.request") and [`session`](../api/index#flask.session "flask.session") proxies are accessed instead. This is similar to [The Application Context](../appcontext/index), which keeps track of the application-level data independent of a request. A corresponding application context is pushed when a request context is pushed. Purpose of the Context ---------------------- When the [`Flask`](../api/index#flask.Flask "flask.Flask") application handles a request, it creates a [`Request`](../api/index#flask.Request "flask.Request") object based on the environment it received from the WSGI server. Because a *worker* (thread, process, or coroutine depending on the server) handles only one request at a time, the request data can be considered global to that worker during that request. Flask uses the term *context local* for this. Flask automatically *pushes* a request context when handling a request. View functions, error handlers, and other functions that run during a request will have access to the [`request`](../api/index#flask.request "flask.request") proxy, which points to the request object for the current request. Lifetime of the Context ----------------------- When a Flask application begins handling a request, it pushes a request context, which also pushes an [app context](../appcontext/index). When the request ends it pops the request context then the application context. The context is unique to each thread (or other worker type). [`request`](../api/index#flask.request "flask.request") cannot be passed to another thread, the other thread has a different context space and will not know about the request the parent thread was pointing to. Context locals are implemented using Python’s [`contextvars`](https://docs.python.org/3/library/contextvars.html#module-contextvars "(in Python v3.10)") and Werkzeug’s [`LocalProxy`](https://werkzeug.palletsprojects.com/en/2.2.x/local/#werkzeug.local.LocalProxy "(in Werkzeug v2.2.x)"). Python manages the lifetime of context vars automatically, and local proxy wraps that low-level interface to make the data easier to work with. Manually Push a Context ----------------------- If you try to access [`request`](../api/index#flask.request "flask.request"), or anything that uses it, outside a request context, you’ll get this error message: ``` RuntimeError: Working outside of request context. This typically means that you attempted to use functionality that needed an active HTTP request. Consult the documentation on testing for information about how to avoid this problem. ``` This should typically only happen when testing code that expects an active request. One option is to use the [`test client`](../api/index#flask.Flask.test_client "flask.Flask.test_client") to simulate a full request. Or you can use [`test_request_context()`](../api/index#flask.Flask.test_request_context "flask.Flask.test_request_context") in a `with` block, and everything that runs in the block will have access to [`request`](../api/index#flask.request "flask.request"), populated with your test data. ``` def generate_report(year): format = request.args.get('format') ... with app.test_request_context( '/make_report/2017', data={'format': 'short'}): generate_report() ``` If you see that error somewhere else in your code not related to testing, it most likely indicates that you should move that code into a view function. For information on how to use the request context from the interactive Python shell, see [Working with the Shell](../shell/index). How the Context Works --------------------- The [`Flask.wsgi_app()`](../api/index#flask.Flask.wsgi_app "flask.Flask.wsgi_app") method is called to handle each request. It manages the contexts during the request. Internally, the request and application contexts work like stacks. When contexts are pushed, the proxies that depend on them are available and point at information from the top item. When the request starts, a [`RequestContext`](../api/index#flask.ctx.RequestContext "flask.ctx.RequestContext") is created and pushed, which creates and pushes an [`AppContext`](../api/index#flask.ctx.AppContext "flask.ctx.AppContext") first if a context for that application is not already the top context. While these contexts are pushed, the [`current_app`](../api/index#flask.current_app "flask.current_app"), [`g`](../api/index#flask.g "flask.g"), [`request`](../api/index#flask.request "flask.request"), and [`session`](../api/index#flask.session "flask.session") proxies are available to the original thread handling the request. Other contexts may be pushed to change the proxies during a request. While this is not a common pattern, it can be used in advanced applications to, for example, do internal redirects or chain different applications together. After the request is dispatched and a response is generated and sent, the request context is popped, which then pops the application context. Immediately before they are popped, the [`teardown_request()`](../api/index#flask.Flask.teardown_request "flask.Flask.teardown_request") and [`teardown_appcontext()`](../api/index#flask.Flask.teardown_appcontext "flask.Flask.teardown_appcontext") functions are executed. These execute even if an unhandled exception occurred during dispatch. Callbacks and Errors -------------------- Flask dispatches a request in multiple stages which can affect the request, response, and how errors are handled. The contexts are active during all of these stages. A [`Blueprint`](../api/index#flask.Blueprint "flask.Blueprint") can add handlers for these events that are specific to the blueprint. The handlers for a blueprint will run if the blueprint owns the route that matches the request. 1. Before each request, [`before_request()`](../api/index#flask.Flask.before_request "flask.Flask.before_request") functions are called. If one of these functions return a value, the other functions are skipped. The return value is treated as the response and the view function is not called. 2. If the [`before_request()`](../api/index#flask.Flask.before_request "flask.Flask.before_request") functions did not return a response, the view function for the matched route is called and returns a response. 3. The return value of the view is converted into an actual response object and passed to the [`after_request()`](../api/index#flask.Flask.after_request "flask.Flask.after_request") functions. Each function returns a modified or new response object. 4. After the response is returned, the contexts are popped, which calls the [`teardown_request()`](../api/index#flask.Flask.teardown_request "flask.Flask.teardown_request") and [`teardown_appcontext()`](../api/index#flask.Flask.teardown_appcontext "flask.Flask.teardown_appcontext") functions. These functions are called even if an unhandled exception was raised at any point above. If an exception is raised before the teardown functions, Flask tries to match it with an [`errorhandler()`](../api/index#flask.Flask.errorhandler "flask.Flask.errorhandler") function to handle the exception and return a response. If no error handler is found, or the handler itself raises an exception, Flask returns a generic `500 Internal Server Error` response. The teardown functions are still called, and are passed the exception object. If debug mode is enabled, unhandled exceptions are not converted to a `500` response and instead are propagated to the WSGI server. This allows the development server to present the interactive debugger with the traceback. ### Teardown Callbacks The teardown callbacks are independent of the request dispatch, and are instead called by the contexts when they are popped. The functions are called even if there is an unhandled exception during dispatch, and for manually pushed contexts. This means there is no guarantee that any other parts of the request dispatch have run first. Be sure to write these functions in a way that does not depend on other callbacks and will not fail. During testing, it can be useful to defer popping the contexts after the request ends, so that their data can be accessed in the test function. Use the [`test_client()`](../api/index#flask.Flask.test_client "flask.Flask.test_client") as a `with` block to preserve the contexts until the `with` block exits. ``` from flask import Flask, request app = Flask(__name__) @app.route('/') def hello(): print('during view') return 'Hello, World!' @app.teardown_request def show_teardown(exception): print('after with block') with app.test_request_context(): print('during with block') # teardown functions are called after the context with block exits with app.test_client() as client: client.get('/') # the contexts are not popped even though the request ended print(request.path) # the contexts are popped and teardown functions are called after # the client with block exits ``` ### Signals If [`signals_available`](../api/index#flask.signals.signals_available "flask.signals.signals_available") is true, the following signals are sent: 1. [`request_started`](../api/index#flask.request_started "flask.request_started") is sent before the [`before_request()`](../api/index#flask.Flask.before_request "flask.Flask.before_request") functions are called. 2. [`request_finished`](../api/index#flask.request_finished "flask.request_finished") is sent after the [`after_request()`](../api/index#flask.Flask.after_request "flask.Flask.after_request") functions are called. 3. [`got_request_exception`](../api/index#flask.got_request_exception "flask.got_request_exception") is sent when an exception begins to be handled, but before an [`errorhandler()`](../api/index#flask.Flask.errorhandler "flask.Flask.errorhandler") is looked up or called. 4. [`request_tearing_down`](../api/index#flask.request_tearing_down "flask.request_tearing_down") is sent after the [`teardown_request()`](../api/index#flask.Flask.teardown_request "flask.Flask.teardown_request") functions are called. Notes On Proxies ---------------- Some of the objects provided by Flask are proxies to other objects. The proxies are accessed in the same way for each worker thread, but point to the unique object bound to each worker behind the scenes as described on this page. Most of the time you don’t have to care about that, but there are some exceptions where it is good to know that this object is actually a proxy: * The proxy objects cannot fake their type as the actual object types. If you want to perform instance checks, you have to do that on the object being proxied. * The reference to the proxied object is needed in some situations, such as sending [Signals](../signals/index) or passing data to a background thread. If you need to access the underlying object that is proxied, use the `_get_current_object()` method: ``` app = current_app._get_current_object() my_signal.send(app) ```
programming_docs
flask Using async and await Using async and await ===================== Changelog New in version 2.0. Routes, error handlers, before request, after request, and teardown functions can all be coroutine functions if Flask is installed with the `async` extra (`pip install flask[async]`). This allows views to be defined with `async def` and use `await`. ``` @app.route("/get-data") async def get_data(): data = await async_db_query(...) return jsonify(data) ``` Pluggable class-based views also support handlers that are implemented as coroutines. This applies to the [`dispatch_request()`](../api/index#flask.views.View.dispatch_request "flask.views.View.dispatch_request") method in views that inherit from the [`flask.views.View`](../api/index#flask.views.View "flask.views.View") class, as well as all the HTTP method handlers in views that inherit from the [`flask.views.MethodView`](../api/index#flask.views.MethodView "flask.views.MethodView") class. Using `async` on Windows on Python 3.8 Python 3.8 has a bug related to asyncio on Windows. If you encounter something like `ValueError: set_wakeup_fd only works in main thread`, please upgrade to Python 3.9. Using `async` with greenlet When using gevent or eventlet to serve an application or patch the runtime, greenlet>=1.0 is required. When using PyPy, PyPy>=7.3.7 is required. Performance ----------- Async functions require an event loop to run. Flask, as a WSGI application, uses one worker to handle one request/response cycle. When a request comes in to an async view, Flask will start an event loop in a thread, run the view function there, then return the result. Each request still ties up one worker, even for async views. The upside is that you can run async code within a view, for example to make multiple concurrent database queries, HTTP requests to an external API, etc. However, the number of requests your application can handle at one time will remain the same. **Async is not inherently faster than sync code.** Async is beneficial when performing concurrent IO-bound tasks, but will probably not improve CPU-bound tasks. Traditional Flask views will still be appropriate for most use cases, but Flask’s async support enables writing and using code that wasn’t possible natively before. Background tasks ---------------- Async functions will run in an event loop until they complete, at which stage the event loop will stop. This means any additional spawned tasks that haven’t completed when the async function completes will be cancelled. Therefore you cannot spawn background tasks, for example via `asyncio.create_task`. If you wish to use background tasks it is best to use a task queue to trigger background work, rather than spawn tasks in a view function. With that in mind you can spawn asyncio tasks by serving Flask with an ASGI server and utilising the asgiref WsgiToAsgi adapter as described in [ASGI](../deploying/asgi/index). This works as the adapter creates an event loop that runs continually. When to use Quart instead ------------------------- Flask’s async support is less performant than async-first frameworks due to the way it is implemented. If you have a mainly async codebase it would make sense to consider [Quart](https://github.com/pallets/quart). Quart is a reimplementation of Flask based on the [ASGI](https://asgi.readthedocs.io/en/latest/) standard instead of WSGI. This allows it to handle many concurrent requests, long running requests, and websockets without requiring multiple worker processes or threads. It has also already been possible to run Flask with Gevent or Eventlet to get many of the benefits of async request handling. These libraries patch low-level Python functions to accomplish this, whereas `async`/ `await` and ASGI use standard, modern Python capabilities. Deciding whether you should use Flask, Quart, or something else is ultimately up to understanding the specific needs of your project. Extensions ---------- Flask extensions predating Flask’s async support do not expect async views. If they provide decorators to add functionality to views, those will probably not work with async views because they will not await the function or be awaitable. Other functions they provide will not be awaitable either and will probably be blocking if called within an async view. Extension authors can support async functions by utilising the [`flask.Flask.ensure_sync()`](../api/index#flask.Flask.ensure_sync "flask.Flask.ensure_sync") method. For example, if the extension provides a view function decorator add `ensure_sync` before calling the decorated function, ``` def extension(func): @wraps(func) def wrapper(*args, **kwargs): ... # Extension logic return current_app.ensure_sync(func)(*args, **kwargs) return wrapper ``` Check the changelog of the extension you want to use to see if they’ve implemented async support, or make a feature request or PR to them. Other event loops ----------------- At the moment Flask only supports [`asyncio`](https://docs.python.org/3/library/asyncio.html#module-asyncio "(in Python v3.10)"). It’s possible to override [`flask.Flask.ensure_sync()`](../api/index#flask.Flask.ensure_sync "flask.Flask.ensure_sync") to change how async functions are wrapped to use a different library. flask Development Server Development Server ================== Flask provides a `run` command to run the application with a development server. In debug mode, this server provides an interactive debugger and will reload when code is changed. Warning Do not use the development server when deploying to production. It is intended for use only during local development. It is not designed to be particularly efficient, stable, or secure. See [Deploying to Production](../deploying/index) for deployment options. Command Line ------------ The `flask run` CLI command is the recommended way to run the development server. Use the `--app` option to point to your application, and the `--debug` option to enable debug mode. ``` $ flask --app hello --debug run ``` This enables debug mode, including the interactive debugger and reloader, and then starts the server on <http://localhost:5000/>. Use `flask run --help` to see the available options, and [Command Line Interface](../cli/index) for detailed instructions about configuring and using the CLI. ### Address already in use If another program is already using port 5000, you’ll see an `OSError` when the server tries to start. It may have one of the following messages: * `OSError: [Errno 98] Address already in use` * `OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions` Either identify and stop the other program, or use `flask run --port 5001` to pick a different port. You can use `netstat` or `lsof` to identify what process id is using a port, then use other operating system tools stop that process. The following example shows that process id 6847 is using port 5000. ``` $ netstat -nlp | grep 5000 tcp 0 0 127.0.0.1:5000 0.0.0.0:* LISTEN 6847/python ``` ``` $ lsof -P -i :5000 Python 6847 IPv4 TCP localhost:5000 (LISTEN) ``` ``` > netstat -ano | findstr 5000 TCP 127.0.0.1:5000 0.0.0.0:0 LISTENING 6847 ``` macOS Monterey and later automatically starts a service that uses port 5000. To disable the service, go to System Preferences, Sharing, and disable “AirPlay Receiver”. ### Deferred Errors on Reload When using the `flask run` command with the reloader, the server will continue to run even if you introduce syntax errors or other initialization errors into the code. Accessing the site will show the interactive debugger for the error, rather than crashing the server. If a syntax error is already present when calling `flask run`, it will fail immediately and show the traceback rather than waiting until the site is accessed. This is intended to make errors more visible initially while still allowing the server to handle errors on reload. In Code ------- The development server can also be started from Python with the [`Flask.run()`](../api/index#flask.Flask.run "flask.Flask.run") method. This method takes arguments similar to the CLI options to control the server. The main difference from the CLI command is that the server will crash if there are errors when reloading. `debug=True` can be passed to enable debug mode. Place the call in a main block, otherwise it will interfere when trying to import and run the application with a production server later. ``` if __name__ == "__main__": app.run(debug=True) ``` ``` $ python hello.py ``` flask Installation Installation ============ Python Version -------------- We recommend using the latest version of Python. Flask supports Python 3.7 and newer. Dependencies ------------ These distributions will be installed automatically when installing Flask. * [Werkzeug](https://palletsprojects.com/p/werkzeug/) implements WSGI, the standard Python interface between applications and servers. * [Jinja](https://palletsprojects.com/p/jinja/) is a template language that renders the pages your application serves. * [MarkupSafe](https://palletsprojects.com/p/markupsafe/) comes with Jinja. It escapes untrusted input when rendering templates to avoid injection attacks. * [ItsDangerous](https://palletsprojects.com/p/itsdangerous/) securely signs data to ensure its integrity. This is used to protect Flask’s session cookie. * [Click](https://palletsprojects.com/p/click/) is a framework for writing command line applications. It provides the `flask` command and allows adding custom management commands. ### Optional dependencies These distributions will not be installed automatically. Flask will detect and use them if you install them. * [Blinker](https://pythonhosted.org/blinker/) provides support for [Signals](../signals/index). * [python-dotenv](https://github.com/theskumar/python-dotenv#readme) enables support for [Environment Variables From dotenv](../cli/index#dotenv) when running `flask` commands. * [Watchdog](https://pythonhosted.org/watchdog/) provides a faster, more efficient reloader for the development server. ### greenlet You may choose to use gevent or eventlet with your application. In this case, greenlet>=1.0 is required. When using PyPy, PyPy>=7.3.7 is required. These are not minimum supported versions, they only indicate the first versions that added necessary features. You should use the latest versions of each. Virtual environments -------------------- Use a virtual environment to manage the dependencies for your project, both in development and in production. What problem does a virtual environment solve? The more Python projects you have, the more likely it is that you need to work with different versions of Python libraries, or even Python itself. Newer versions of libraries for one project can break compatibility in another project. Virtual environments are independent groups of Python libraries, one for each project. Packages installed for one project will not affect other projects or the operating system’s packages. Python comes bundled with the [`venv`](https://docs.python.org/3/library/venv.html#module-venv "(in Python v3.10)") module to create virtual environments. ### Create an environment Create a project folder and a `venv` folder within: ``` $ mkdir myproject $ cd myproject $ python3 -m venv venv ``` ``` > mkdir myproject > cd myproject > py -3 -m venv venv ``` ### Activate the environment Before you work on your project, activate the corresponding environment: ``` $ . venv/bin/activate ``` ``` > venv\Scripts\activate ``` Your shell prompt will change to show the name of the activated environment. Install Flask ------------- Within the activated environment, use the following command to install Flask: ``` $ pip install Flask ``` Flask is now installed. Check out the [Quickstart](../quickstart/index) or go to the [Documentation Overview](https://flask.palletsprojects.com/en/2.2.x/). flask Templates Templates ========= Flask leverages Jinja2 as its template engine. You are obviously free to use a different template engine, but you still have to install Jinja2 to run Flask itself. This requirement is necessary to enable rich extensions. An extension can depend on Jinja2 being present. This section only gives a very quick introduction into how Jinja2 is integrated into Flask. If you want information on the template engine’s syntax itself, head over to the official [Jinja2 Template Documentation](https://jinja.palletsprojects.com/templates/) for more information. Jinja Setup ----------- Unless customized, Jinja2 is configured by Flask as follows: * autoescaping is enabled for all templates ending in `.html`, `.htm`, `.xml` as well as `.xhtml` when using `render_template()`. * autoescaping is enabled for all strings when using `render_template_string()`. * a template has the ability to opt in/out autoescaping with the `{% autoescape %}` tag. * Flask inserts a couple of global functions and helpers into the Jinja2 context, additionally to the values that are present by default. Standard Context ---------------- The following global variables are available within Jinja2 templates by default: config The current configuration object ([`flask.Flask.config`](../api/index#flask.Flask.config "flask.Flask.config")) Changelog Changed in version 0.10: This is now always available, even in imported templates. New in version 0.6. request The current request object ([`flask.request`](../api/index#flask.request "flask.request")). This variable is unavailable if the template was rendered without an active request context. session The current session object ([`flask.session`](../api/index#flask.session "flask.session")). This variable is unavailable if the template was rendered without an active request context. g The request-bound object for global variables ([`flask.g`](../api/index#flask.g "flask.g")). This variable is unavailable if the template was rendered without an active request context. url\_for() The [`flask.url_for()`](../api/index#flask.url_for "flask.url_for") function. get\_flashed\_messages() The [`flask.get_flashed_messages()`](../api/index#flask.get_flashed_messages "flask.get_flashed_messages") function. The Jinja Context Behavior These variables are added to the context of variables, they are not global variables. The difference is that by default these will not show up in the context of imported templates. This is partially caused by performance considerations, partially to keep things explicit. What does this mean for you? If you have a macro you want to import, that needs to access the request object you have two possibilities: 1. you explicitly pass the request to the macro as parameter, or the attribute of the request object you are interested in. 2. you import the macro “with context”. Importing with context looks like this: ``` {% from '_helpers.html' import my_macro with context %} ``` Controlling Autoescaping ------------------------ Autoescaping is the concept of automatically escaping special characters for you. Special characters in the sense of HTML (or XML, and thus XHTML) are `&`, `>`, `<`, `"` as well as `'`. Because these characters carry specific meanings in documents on their own you have to replace them by so called “entities” if you want to use them for text. Not doing so would not only cause user frustration by the inability to use these characters in text, but can also lead to security problems. (see [Cross-Site Scripting (XSS)](../security/index#security-xss)) Sometimes however you will need to disable autoescaping in templates. This can be the case if you want to explicitly inject HTML into pages, for example if they come from a system that generates secure HTML like a markdown to HTML converter. There are three ways to accomplish that: * In the Python code, wrap the HTML string in a [`Markup`](../api/index#flask.Markup "flask.Markup") object before passing it to the template. This is in general the recommended way. * Inside the template, use the `|safe` filter to explicitly mark a string as safe HTML (`{{ myvariable|safe }}`) * Temporarily disable the autoescape system altogether. To disable the autoescape system in templates, you can use the `{% autoescape %}` block: ``` {% autoescape false %} <p>autoescaping is disabled here <p>{{ will_not_be_escaped }} {% endautoescape %} ``` Whenever you do this, please be very cautious about the variables you are using in this block. Registering Filters ------------------- If you want to register your own filters in Jinja2 you have two ways to do that. You can either put them by hand into the [`jinja_env`](../api/index#flask.Flask.jinja_env "flask.Flask.jinja_env") of the application or use the [`template_filter()`](../api/index#flask.Flask.template_filter "flask.Flask.template_filter") decorator. The two following examples work the same and both reverse an object: ``` @app.template_filter('reverse') def reverse_filter(s): return s[::-1] def reverse_filter(s): return s[::-1] app.jinja_env.filters['reverse'] = reverse_filter ``` In case of the decorator the argument is optional if you want to use the function name as name of the filter. Once registered, you can use the filter in your templates in the same way as Jinja2’s builtin filters, for example if you have a Python list in context called `mylist`: ``` {% for x in mylist | reverse %} {% endfor %} ``` Context Processors ------------------ To inject new variables automatically into the context of a template, context processors exist in Flask. Context processors run before the template is rendered and have the ability to inject new values into the template context. A context processor is a function that returns a dictionary. The keys and values of this dictionary are then merged with the template context, for all templates in the app: ``` @app.context_processor def inject_user(): return dict(user=g.user) ``` The context processor above makes a variable called `user` available in the template with the value of `g.user`. This example is not very interesting because `g` is available in templates anyways, but it gives an idea how this works. Variables are not limited to values; a context processor can also make functions available to templates (since Python allows passing around functions): ``` @app.context_processor def utility_processor(): def format_price(amount, currency="€"): return f"{amount:.2f}{currency}" return dict(format_price=format_price) ``` The context processor above makes the `format_price` function available to all templates: ``` {{ format_price(0.33) }} ``` You could also build `format_price` as a template filter (see [Registering Filters](#registering-filters)), but this demonstrates how to pass functions in a context processor. Streaming --------- It can be useful to not render the whole template as one complete string, instead render it as a stream, yielding smaller incremental strings. This can be used for streaming HTML in chunks to speed up initial page load, or to save memory when rendering a very large template. The Jinja2 template engine supports rendering a template piece by piece, returning an iterator of strings. Flask provides the [`stream_template()`](../api/index#flask.stream_template "flask.stream_template") and [`stream_template_string()`](../api/index#flask.stream_template_string "flask.stream_template_string") functions to make this easier to use. ``` from flask import stream_template @app.get("/timeline") def timeline(): return stream_template("timeline.html") ``` These functions automatically apply the [`stream_with_context()`](../api/index#flask.stream_with_context "flask.stream_with_context") wrapper if a request is active, so that it remains available in the template.
programming_docs
flask Command Line Interface Command Line Interface ====================== Installing Flask installs the `flask` script, a [Click](https://click.palletsprojects.com/) command line interface, in your virtualenv. Executed from the terminal, this script gives access to built-in, extension, and application-defined commands. The `--help` option will give more information about any commands and options. Application Discovery --------------------- The `flask` command is installed by Flask, not your application; it must be told where to find your application in order to use it. The `--app` option is used to specify how to load the application. While `--app` supports a variety of options for specifying your application, most use cases should be simple. Here are the typical values: (nothing) The name “app” or “wsgi” is imported (as a “.py” file, or package), automatically detecting an app (`app` or `application`) or factory (`create_app` or `make_app`). `--app hello` The given name is imported, automatically detecting an app (`app` or `application`) or factory (`create_app` or `make_app`). `--app` has three parts: an optional path that sets the current working directory, a Python file or dotted import path, and an optional variable name of the instance or factory. If the name is a factory, it can optionally be followed by arguments in parentheses. The following values demonstrate these parts: `--app src/hello` Sets the current working directory to `src` then imports `hello`. `--app hello.web` Imports the path `hello.web`. `--app hello:app2` Uses the `app2` Flask instance in `hello`. `--app 'hello:create_app("dev")'` The `create_app` factory in `hello` is called with the string `'dev'` as the argument. If `--app` is not set, the command will try to import “app” or “wsgi” (as a “.py” file, or package) and try to detect an application instance or factory. Within the given import, the command looks for an application instance named `app` or `application`, then any application instance. If no instance is found, the command looks for a factory function named `create_app` or `make_app` that returns an instance. If parentheses follow the factory name, their contents are parsed as Python literals and passed as arguments and keyword arguments to the function. This means that strings must still be in quotes. Run the Development Server -------------------------- The [`run`](../api/index#flask.cli.run_command "flask.cli.run_command") command will start the development server. It replaces the [`Flask.run()`](../api/index#flask.Flask.run "flask.Flask.run") method in most cases. ``` $ flask --app hello run * Serving Flask app "hello" * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) ``` Warning Do not use this command to run your application in production. Only use the development server during development. The development server is provided for convenience, but is not designed to be particularly secure, stable, or efficient. See [Deploying to Production](../deploying/index) for how to run in production. If another program is already using port 5000, you’ll see `OSError: [Errno 98]` or `OSError: [WinError 10013]` when the server tries to start. See [Address already in use](../server/index#address-already-in-use) for how to handle that. ### Debug Mode In debug mode, the `flask run` command will enable the interactive debugger and the reloader by default, and make errors easier to see and debug. To enable debug mode, use the `--debug` option. ``` $ flask --app hello --debug run * Serving Flask app "hello" * Debug mode: on * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) * Restarting with inotify reloader * Debugger is active! * Debugger PIN: 223-456-919 ``` ### Watch and Ignore Files with the Reloader When using debug mode, the reloader will trigger whenever your Python code or imported modules change. The reloader can watch additional files with the `--extra-files` option. Multiple paths are separated with `:`, or `;` on Windows. ``` $ flask run --extra-files file1:dirA/file2:dirB/ * Running on http://127.0.0.1:8000/ * Detected change in '/path/to/file1', reloading ``` The reloader can also ignore files using [`fnmatch`](https://docs.python.org/3/library/fnmatch.html#module-fnmatch "(in Python v3.10)") patterns with the `--exclude-patterns` option. Multiple patterns are separated with `:`, or `;` on Windows. Open a Shell ------------ To explore the data in your application, you can start an interactive Python shell with the [`shell`](../api/index#flask.cli.shell_command "flask.cli.shell_command") command. An application context will be active, and the app instance will be imported. ``` $ flask shell Python 3.10.0 (default, Oct 27 2021, 06:59:51) [GCC 11.1.0] on linux App: example [production] Instance: /home/david/Projects/pallets/flask/instance >>> ``` Use [`shell_context_processor()`](../api/index#flask.Flask.shell_context_processor "flask.Flask.shell_context_processor") to add other automatic imports. Environment Variables From dotenv --------------------------------- The `flask` command supports setting any option for any command with environment variables. The variables are named like `FLASK_OPTION` or `FLASK_COMMAND_OPTION`, for example `FLASK_APP` or `FLASK_RUN_PORT`. Rather than passing options every time you run a command, or environment variables every time you open a new terminal, you can use Flask’s dotenv support to set environment variables automatically. If [python-dotenv](https://github.com/theskumar/python-dotenv#readme) is installed, running the `flask` command will set environment variables defined in the files `.env` and `.flaskenv`. You can also specify an extra file to load with the `--env-file` option. Dotenv files can be used to avoid having to set `--app` or `FLASK_APP` manually, and to set configuration using environment variables similar to how some deployment services work. Variables set on the command line are used over those set in `.env`, which are used over those set in `.flaskenv`. `.flaskenv` should be used for public variables, such as `FLASK_APP`, while `.env` should not be committed to your repository so that it can set private variables. Directories are scanned upwards from the directory you call `flask` from to locate the files. The files are only loaded by the `flask` command or calling [`run()`](../api/index#flask.Flask.run "flask.Flask.run"). If you would like to load these files when running in production, you should call [`load_dotenv()`](../api/index#flask.cli.load_dotenv "flask.cli.load_dotenv") manually. ### Setting Command Options Click is configured to load default values for command options from environment variables. The variables use the pattern `FLASK_COMMAND_OPTION`. For example, to set the port for the run command, instead of `flask run --port 8000`: ``` $ export FLASK_RUN_PORT=8000 $ flask run * Running on http://127.0.0.1:8000/ ``` ``` $ set -x FLASK_RUN_PORT 8000 $ flask run * Running on http://127.0.0.1:8000/ ``` ``` > set FLASK_RUN_PORT=8000 > flask run * Running on http://127.0.0.1:8000/ ``` ``` > $env:FLASK_RUN_PORT = 8000 > flask run * Running on http://127.0.0.1:8000/ ``` These can be added to the `.flaskenv` file just like `FLASK_APP` to control default command options. ### Disable dotenv The `flask` command will show a message if it detects dotenv files but python-dotenv is not installed. ``` $ flask run * Tip: There are .env files present. Do "pip install python-dotenv" to use them. ``` You can tell Flask not to load dotenv files even when python-dotenv is installed by setting the `FLASK_SKIP_DOTENV` environment variable. This can be useful if you want to load them manually, or if you’re using a project runner that loads them already. Keep in mind that the environment variables must be set before the app loads or it won’t configure as expected. ``` $ export FLASK_SKIP_DOTENV=1 $ flask run ``` ``` $ set -x FLASK_SKIP_DOTENV 1 $ flask run ``` ``` > set FLASK_SKIP_DOTENV=1 > flask run ``` ``` > $env:FLASK_SKIP_DOTENV = 1 > flask run ``` Environment Variables From virtualenv ------------------------------------- If you do not want to install dotenv support, you can still set environment variables by adding them to the end of the virtualenv’s `activate` script. Activating the virtualenv will set the variables. Unix Bash, `venv/bin/activate`: ``` $ export FLASK_APP=hello ``` Fish, `venv/bin/activate.fish`: ``` $ set -x FLASK_APP hello ``` Windows CMD, `venv\Scripts\activate.bat`: ``` > set FLASK_APP=hello ``` Windows Powershell, `venv\Scripts\activate.ps1`: ``` > $env:FLASK_APP = "hello" ``` It is preferred to use dotenv support over this, since `.flaskenv` can be committed to the repository so that it works automatically wherever the project is checked out. Custom Commands --------------- The `flask` command is implemented using [Click](https://click.palletsprojects.com/). See that project’s documentation for full information about writing commands. This example adds the command `create-user` that takes the argument `name`. ``` import click from flask import Flask app = Flask(__name__) @app.cli.command("create-user") @click.argument("name") def create_user(name): ... ``` ``` $ flask create-user admin ``` This example adds the same command, but as `user create`, a command in a group. This is useful if you want to organize multiple related commands. ``` import click from flask import Flask from flask.cli import AppGroup app = Flask(__name__) user_cli = AppGroup('user') @user_cli.command('create') @click.argument('name') def create_user(name): ... app.cli.add_command(user_cli) ``` ``` $ flask user create demo ``` See [Running Commands with the CLI Runner](../testing/index#testing-cli) for an overview of how to test your custom commands. ### Registering Commands with Blueprints If your application uses blueprints, you can optionally register CLI commands directly onto them. When your blueprint is registered onto your application, the associated commands will be available to the `flask` command. By default, those commands will be nested in a group matching the name of the blueprint. ``` from flask import Blueprint bp = Blueprint('students', __name__) @bp.cli.command('create') @click.argument('name') def create(name): ... app.register_blueprint(bp) ``` ``` $ flask students create alice ``` You can alter the group name by specifying the `cli_group` parameter when creating the [`Blueprint`](../api/index#flask.Blueprint "flask.Blueprint") object, or later with [`app.register_blueprint(bp, cli_group='...')`](../api/index#flask.Flask.register_blueprint "flask.Flask.register_blueprint"). The following are equivalent: ``` bp = Blueprint('students', __name__, cli_group='other') # or app.register_blueprint(bp, cli_group='other') ``` ``` $ flask other create alice ``` Specifying `cli_group=None` will remove the nesting and merge the commands directly to the application’s level: ``` bp = Blueprint('students', __name__, cli_group=None) # or app.register_blueprint(bp, cli_group=None) ``` ``` $ flask create alice ``` ### Application Context Commands added using the Flask app’s [`cli`](../api/index#flask.Flask.cli "flask.Flask.cli") or [`FlaskGroup`](../api/index#flask.cli.FlaskGroup "flask.cli.FlaskGroup") [`command()`](../api/index#flask.cli.AppGroup.command "flask.cli.AppGroup.command") decorator will be executed with an application context pushed, so your custom commands and parameters have access to the app and its configuration. The [`with_appcontext()`](../api/index#flask.cli.with_appcontext "flask.cli.with_appcontext") decorator can be used to get the same behavior, but is not needed in most cases. ``` import click from flask.cli import with_appcontext @click.command() @with_appcontext def do_work(): ... app.cli.add_command(do_work) ``` Plugins ------- Flask will automatically load commands specified in the `flask.commands` [entry point](https://packaging.python.org/tutorials/packaging-projects/#entry-points). This is useful for extensions that want to add commands when they are installed. Entry points are specified in `setup.py` ``` from setuptools import setup setup( name='flask-my-extension', ..., entry_points={ 'flask.commands': [ 'my-command=flask_my_extension.commands:cli' ], }, ) ``` Inside `flask_my_extension/commands.py` you can then export a Click object: ``` import click @click.command() def cli(): ... ``` Once that package is installed in the same virtualenv as your Flask project, you can run `flask my-command` to invoke the command. Custom Scripts -------------- When you are using the app factory pattern, it may be more convenient to define your own Click script. Instead of using `--app` and letting Flask load your application, you can create your own Click object and export it as a [console script](https://packaging.python.org/tutorials/packaging-projects/#console-scripts) entry point. Create an instance of [`FlaskGroup`](../api/index#flask.cli.FlaskGroup "flask.cli.FlaskGroup") and pass it the factory: ``` import click from flask import Flask from flask.cli import FlaskGroup def create_app(): app = Flask('wiki') # other setup return app @click.group(cls=FlaskGroup, create_app=create_app) def cli(): """Management script for the Wiki application.""" ``` Define the entry point in `setup.py`: ``` from setuptools import setup setup( name='flask-my-extension', ..., entry_points={ 'console_scripts': [ 'wiki=wiki:cli' ], }, ) ``` Install the application in the virtualenv in editable mode and the custom script is available. Note that you don’t need to set `--app`. ``` $ pip install -e . $ wiki run ``` Errors in Custom Scripts When using a custom script, if you introduce an error in your module-level code, the reloader will fail because it can no longer load the entry point. The `flask` command, being separate from your code, does not have this issue and is recommended in most cases. PyCharm Integration ------------------- PyCharm Professional provides a special Flask run configuration to run the development server. For the Community Edition, and for other commands besides `run`, you need to create a custom run configuration. These instructions should be similar for any other IDE you use. In PyCharm, with your project open, click on *Run* from the menu bar and go to *Edit Configurations*. You’ll see a screen similar to this: Once you create a configuration for the `flask run`, you can copy and change it to call any other command. Click the *+ (Add New Configuration)* button and select *Python*. Give the configuration a name such as “flask run”. Click the *Script path* dropdown and change it to *Module name*, then input `flask`. The *Parameters* field is set to the CLI command to execute along with any arguments. This example uses `--app hello --debug run`, which will run the development server in debug mode. `--app hello` should be the import or file with your Flask app. If you installed your project as a package in your virtualenv, you may uncheck the *PYTHONPATH* options. This will more accurately match how you deploy later. Click *OK* to save and close the configuration. Select the configuration in the main PyCharm window and click the play button next to it to run the server. Now that you have a configuration for `flask run`, you can copy that configuration and change the *Parameters* argument to run a different CLI command. flask Quickstart Quickstart ========== Eager to get started? This page gives a good introduction to Flask. Follow [Installation](../installation/index) to set up a project and install Flask first. A Minimal Application --------------------- A minimal Flask application looks something like this: ``` from flask import Flask app = Flask(__name__) @app.route("/") def hello_world(): return "<p>Hello, World!</p>" ``` So what did that code do? 1. First we imported the [`Flask`](../api/index#flask.Flask "flask.Flask") class. An instance of this class will be our WSGI application. 2. Next we create an instance of this class. The first argument is the name of the application’s module or package. `__name__` is a convenient shortcut for this that is appropriate for most cases. This is needed so that Flask knows where to look for resources such as templates and static files. 3. We then use the [`route()`](../api/index#flask.Flask.route "flask.Flask.route") decorator to tell Flask what URL should trigger our function. 4. The function returns the message we want to display in the user’s browser. The default content type is HTML, so HTML in the string will be rendered by the browser. Save it as `hello.py` or something similar. Make sure to not call your application `flask.py` because this would conflict with Flask itself. To run the application, use the `flask` command or `python -m flask`. You need to tell the Flask where your application is with the `--app` option. ``` $ flask --app hello run * Serving Flask app 'hello' * Running on http://127.0.0.1:5000 (Press CTRL+C to quit) ``` Application Discovery Behavior As a shortcut, if the file is named `app.py` or `wsgi.py`, you don’t have to use `--app`. See [Command Line Interface](../cli/index) for more details. This launches a very simple builtin server, which is good enough for testing but probably not what you want to use in production. For deployment options see [Deploying to Production](../deploying/index). Now head over to <http://127.0.0.1:5000/>, and you should see your hello world greeting. If another program is already using port 5000, you’ll see `OSError: [Errno 98]` or `OSError: [WinError 10013]` when the server tries to start. See [Address already in use](../server/index#address-already-in-use) for how to handle that. Externally Visible Server If you run the server you will notice that the server is only accessible from your own computer, not from any other in the network. This is the default because in debugging mode a user of the application can execute arbitrary Python code on your computer. If you have the debugger disabled or trust the users on your network, you can make the server publicly available simply by adding `--host=0.0.0.0` to the command line: ``` $ flask run --host=0.0.0.0 ``` This tells your operating system to listen on all public IPs. Debug Mode ---------- The `flask run` command can do more than just start the development server. By enabling debug mode, the server will automatically reload if code changes, and will show an interactive debugger in the browser if an error occurs during a request. Warning The debugger allows executing arbitrary Python code from the browser. It is protected by a pin, but still represents a major security risk. Do not run the development server or debugger in a production environment. To enable debug mode, use the `--debug` option. ``` $ flask --app hello --debug run * Serving Flask app 'hello' * Debug mode: on * Running on http://127.0.0.1:5000 (Press CTRL+C to quit) * Restarting with stat * Debugger is active! * Debugger PIN: nnn-nnn-nnn ``` See also: * [Development Server](../server/index) and [Command Line Interface](../cli/index) for information about running in debug mode. * [Debugging Application Errors](../debugging/index) for information about using the built-in debugger and other debuggers. * [Logging](../logging/index) and [Handling Application Errors](../errorhandling/index) to log errors and display nice error pages. HTML Escaping ------------- When returning HTML (the default response type in Flask), any user-provided values rendered in the output must be escaped to protect from injection attacks. HTML templates rendered with Jinja, introduced later, will do this automatically. `escape()`, shown here, can be used manually. It is omitted in most examples for brevity, but you should always be aware of how you’re using untrusted data. ``` from markupsafe import escape @app.route("/<name>") def hello(name): return f"Hello, {escape(name)}!" ``` If a user managed to submit the name `<script>alert("bad")</script>`, escaping causes it to be rendered as text, rather than running the script in the user’s browser. `<name>` in the route captures a value from the URL and passes it to the view function. These variable rules are explained below. Routing ------- Modern web applications use meaningful URLs to help users. Users are more likely to like a page and come back if the page uses a meaningful URL they can remember and use to directly visit a page. Use the [`route()`](../api/index#flask.Flask.route "flask.Flask.route") decorator to bind a function to a URL. ``` @app.route('/') def index(): return 'Index Page' @app.route('/hello') def hello(): return 'Hello, World' ``` You can do more! You can make parts of the URL dynamic and attach multiple rules to a function. ### Variable Rules You can add variable sections to a URL by marking sections with `<variable_name>`. Your function then receives the `<variable_name>` as a keyword argument. Optionally, you can use a converter to specify the type of the argument like `<converter:variable_name>`. ``` from markupsafe import escape @app.route('/user/<username>') def show_user_profile(username): # show the user profile for that user return f'User {escape(username)}' @app.route('/post/<int:post_id>') def show_post(post_id): # show the post with the given id, the id is an integer return f'Post {post_id}' @app.route('/path/<path:subpath>') def show_subpath(subpath): # show the subpath after /path/ return f'Subpath {escape(subpath)}' ``` Converter types: | | | | --- | --- | | `string` | (default) accepts any text without a slash | | `int` | accepts positive integers | | `float` | accepts positive floating point values | | `path` | like `string` but also accepts slashes | | `uuid` | accepts UUID strings | ### Unique URLs / Redirection Behavior The following two rules differ in their use of a trailing slash. ``` @app.route('/projects/') def projects(): return 'The project page' @app.route('/about') def about(): return 'The about page' ``` The canonical URL for the `projects` endpoint has a trailing slash. It’s similar to a folder in a file system. If you access the URL without a trailing slash (`/projects`), Flask redirects you to the canonical URL with the trailing slash (`/projects/`). The canonical URL for the `about` endpoint does not have a trailing slash. It’s similar to the pathname of a file. Accessing the URL with a trailing slash (`/about/`) produces a 404 “Not Found” error. This helps keep URLs unique for these resources, which helps search engines avoid indexing the same page twice. ### URL Building To build a URL to a specific function, use the [`url_for()`](../api/index#flask.url_for "flask.url_for") function. It accepts the name of the function as its first argument and any number of keyword arguments, each corresponding to a variable part of the URL rule. Unknown variable parts are appended to the URL as query parameters. Why would you want to build URLs using the URL reversing function [`url_for()`](../api/index#flask.url_for "flask.url_for") instead of hard-coding them into your templates? 1. Reversing is often more descriptive than hard-coding the URLs. 2. You can change your URLs in one go instead of needing to remember to manually change hard-coded URLs. 3. URL building handles escaping of special characters transparently. 4. The generated paths are always absolute, avoiding unexpected behavior of relative paths in browsers. 5. If your application is placed outside the URL root, for example, in `/myapplication` instead of `/`, [`url_for()`](../api/index#flask.url_for "flask.url_for") properly handles that for you. For example, here we use the [`test_request_context()`](../api/index#flask.Flask.test_request_context "flask.Flask.test_request_context") method to try out [`url_for()`](../api/index#flask.url_for "flask.url_for"). [`test_request_context()`](../api/index#flask.Flask.test_request_context "flask.Flask.test_request_context") tells Flask to behave as though it’s handling a request even while we use a Python shell. See [Context Locals](#context-locals). ``` from flask import url_for @app.route('/') def index(): return 'index' @app.route('/login') def login(): return 'login' @app.route('/user/<username>') def profile(username): return f'{username}\'s profile' with app.test_request_context(): print(url_for('index')) print(url_for('login')) print(url_for('login', next='/')) print(url_for('profile', username='John Doe')) ``` ``` / /login /login?next=/ /user/John%20Doe ``` ### HTTP Methods Web applications use different HTTP methods when accessing URLs. You should familiarize yourself with the HTTP methods as you work with Flask. By default, a route only answers to `GET` requests. You can use the `methods` argument of the [`route()`](../api/index#flask.Flask.route "flask.Flask.route") decorator to handle different HTTP methods. ``` from flask import request @app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': return do_the_login() else: return show_the_login_form() ``` The example above keeps all methods for the route within one function, which can be useful if each part uses some common data. You can also separate views for different methods into different functions. Flask provides a shortcut for decorating such routes with [`get()`](../api/index#flask.Flask.get "flask.Flask.get"), [`post()`](../api/index#flask.Flask.post "flask.Flask.post"), etc. for each common HTTP method. ``` @app.get('/login') def login_get(): return show_the_login_form() @app.post('/login') def login_post(): return do_the_login() ``` If `GET` is present, Flask automatically adds support for the `HEAD` method and handles `HEAD` requests according to the [HTTP RFC](https://www.ietf.org/rfc/rfc2068.txt). Likewise, `OPTIONS` is automatically implemented for you. Static Files ------------ Dynamic web applications also need static files. That’s usually where the CSS and JavaScript files are coming from. Ideally your web server is configured to serve them for you, but during development Flask can do that as well. Just create a folder called `static` in your package or next to your module and it will be available at `/static` on the application. To generate URLs for static files, use the special `'static'` endpoint name: ``` url_for('static', filename='style.css') ``` The file has to be stored on the filesystem as `static/style.css`. Rendering Templates ------------------- Generating HTML from within Python is not fun, and actually pretty cumbersome because you have to do the HTML escaping on your own to keep the application secure. Because of that Flask configures the [Jinja2](https://palletsprojects.com/p/jinja/) template engine for you automatically. Templates can be used to generate any type of text file. For web applications, you’ll primarily be generating HTML pages, but you can also generate markdown, plain text for emails, any anything else. For a reference to HTML, CSS, and other web APIs, use the [MDN Web Docs](https://developer.mozilla.org/). To render a template you can use the [`render_template()`](../api/index#flask.render_template "flask.render_template") method. All you have to do is provide the name of the template and the variables you want to pass to the template engine as keyword arguments. Here’s a simple example of how to render a template: ``` from flask import render_template @app.route('/hello/') @app.route('/hello/<name>') def hello(name=None): return render_template('hello.html', name=name) ``` Flask will look for templates in the `templates` folder. So if your application is a module, this folder is next to that module, if it’s a package it’s actually inside your package: **Case 1**: a module: ``` /application.py /templates /hello.html ``` **Case 2**: a package: ``` /application /__init__.py /templates /hello.html ``` For templates you can use the full power of Jinja2 templates. Head over to the official [Jinja2 Template Documentation](https://jinja.palletsprojects.com/templates/) for more information. Here is an example template: ``` <!doctype html> <title>Hello from Flask</title> {% if name %} <h1>Hello {{ name }}!</h1> {% else %} <h1>Hello, World!</h1> {% endif %} ``` Inside templates you also have access to the [`config`](../api/index#flask.Flask.config "flask.Flask.config"), [`request`](../api/index#flask.request "flask.request"), [`session`](../api/index#flask.session "flask.session") and [`g`](../api/index#flask.g "flask.g") [1](#id3) objects as well as the [`url_for()`](../api/index#flask.url_for "flask.url_for") and [`get_flashed_messages()`](../api/index#flask.get_flashed_messages "flask.get_flashed_messages") functions. Templates are especially useful if inheritance is used. If you want to know how that works, see [Template Inheritance](../patterns/templateinheritance/index). Basically template inheritance makes it possible to keep certain elements on each page (like header, navigation and footer). Automatic escaping is enabled, so if `name` contains HTML it will be escaped automatically. If you can trust a variable and you know that it will be safe HTML (for example because it came from a module that converts wiki markup to HTML) you can mark it as safe by using the [`Markup`](../api/index#flask.Markup "markupsafe.Markup") class or by using the `|safe` filter in the template. Head over to the Jinja 2 documentation for more examples. Here is a basic introduction to how the [`Markup`](../api/index#flask.Markup "markupsafe.Markup") class works: ``` >>> from markupsafe import Markup >>> Markup('<strong>Hello %s!</strong>') % '<blink>hacker</blink>' Markup('<strong>Hello &lt;blink&gt;hacker&lt;/blink&gt;!</strong>') >>> Markup.escape('<blink>hacker</blink>') Markup('&lt;blink&gt;hacker&lt;/blink&gt;') >>> Markup('<em>Marked up</em> &raquo; HTML').striptags() 'Marked up » HTML' ``` Changelog Changed in version 0.5: Autoescaping is no longer enabled for all templates. The following extensions for templates trigger autoescaping: `.html`, `.htm`, `.xml`, `.xhtml`. Templates loaded from a string will have autoescaping disabled. `1` Unsure what that [`g`](../api/index#flask.g "flask.g") object is? It’s something in which you can store information for your own needs. See the documentation for [`flask.g`](../api/index#flask.g "flask.g") and [Using SQLite 3 with Flask](../patterns/sqlite3/index). Accessing Request Data ---------------------- For web applications it’s crucial to react to the data a client sends to the server. In Flask this information is provided by the global [`request`](../api/index#flask.request "flask.request") object. If you have some experience with Python you might be wondering how that object can be global and how Flask manages to still be threadsafe. The answer is context locals: ### Context Locals Insider Information If you want to understand how that works and how you can implement tests with context locals, read this section, otherwise just skip it. Certain objects in Flask are global objects, but not of the usual kind. These objects are actually proxies to objects that are local to a specific context. What a mouthful. But that is actually quite easy to understand. Imagine the context being the handling thread. A request comes in and the web server decides to spawn a new thread (or something else, the underlying object is capable of dealing with concurrency systems other than threads). When Flask starts its internal request handling it figures out that the current thread is the active context and binds the current application and the WSGI environments to that context (thread). It does that in an intelligent way so that one application can invoke another application without breaking. So what does this mean to you? Basically you can completely ignore that this is the case unless you are doing something like unit testing. You will notice that code which depends on a request object will suddenly break because there is no request object. The solution is creating a request object yourself and binding it to the context. The easiest solution for unit testing is to use the [`test_request_context()`](../api/index#flask.Flask.test_request_context "flask.Flask.test_request_context") context manager. In combination with the `with` statement it will bind a test request so that you can interact with it. Here is an example: ``` from flask import request with app.test_request_context('/hello', method='POST'): # now you can do something with the request until the # end of the with block, such as basic assertions: assert request.path == '/hello' assert request.method == 'POST' ``` The other possibility is passing a whole WSGI environment to the [`request_context()`](../api/index#flask.Flask.request_context "flask.Flask.request_context") method: ``` with app.request_context(environ): assert request.method == 'POST' ``` ### The Request Object The request object is documented in the API section and we will not cover it here in detail (see [`Request`](../api/index#flask.Request "flask.Request")). Here is a broad overview of some of the most common operations. First of all you have to import it from the `flask` module: ``` from flask import request ``` The current request method is available by using the [`method`](../api/index#flask.Request.method "flask.Request.method") attribute. To access form data (data transmitted in a `POST` or `PUT` request) you can use the [`form`](../api/index#flask.Request.form "flask.Request.form") attribute. Here is a full example of the two attributes mentioned above: ``` @app.route('/login', methods=['POST', 'GET']) def login(): error = None if request.method == 'POST': if valid_login(request.form['username'], request.form['password']): return log_the_user_in(request.form['username']) else: error = 'Invalid username/password' # the code below is executed if the request method # was GET or the credentials were invalid return render_template('login.html', error=error) ``` What happens if the key does not exist in the `form` attribute? In that case a special [`KeyError`](https://docs.python.org/3/library/exceptions.html#KeyError "(in Python v3.10)") is raised. You can catch it like a standard [`KeyError`](https://docs.python.org/3/library/exceptions.html#KeyError "(in Python v3.10)") but if you don’t do that, a HTTP 400 Bad Request error page is shown instead. So for many situations you don’t have to deal with that problem. To access parameters submitted in the URL (`?key=value`) you can use the [`args`](../api/index#flask.Request.args "flask.Request.args") attribute: ``` searchword = request.args.get('key', '') ``` We recommend accessing URL parameters with `get` or by catching the [`KeyError`](https://docs.python.org/3/library/exceptions.html#KeyError "(in Python v3.10)") because users might change the URL and presenting them a 400 bad request page in that case is not user friendly. For a full list of methods and attributes of the request object, head over to the [`Request`](../api/index#flask.Request "flask.Request") documentation. ### File Uploads You can handle uploaded files with Flask easily. Just make sure not to forget to set the `enctype="multipart/form-data"` attribute on your HTML form, otherwise the browser will not transmit your files at all. Uploaded files are stored in memory or at a temporary location on the filesystem. You can access those files by looking at the `files` attribute on the request object. Each uploaded file is stored in that dictionary. It behaves just like a standard Python `file` object, but it also has a [`save()`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.FileStorage.save "(in Werkzeug v2.2.x)") method that allows you to store that file on the filesystem of the server. Here is a simple example showing how that works: ``` from flask import request @app.route('/upload', methods=['GET', 'POST']) def upload_file(): if request.method == 'POST': f = request.files['the_file'] f.save('/var/www/uploads/uploaded_file.txt') ... ``` If you want to know how the file was named on the client before it was uploaded to your application, you can access the [`filename`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.FileStorage.filename "(in Werkzeug v2.2.x)") attribute. However please keep in mind that this value can be forged so never ever trust that value. If you want to use the filename of the client to store the file on the server, pass it through the [`secure_filename()`](https://werkzeug.palletsprojects.com/en/2.2.x/utils/#werkzeug.utils.secure_filename "(in Werkzeug v2.2.x)") function that Werkzeug provides for you: ``` from werkzeug.utils import secure_filename @app.route('/upload', methods=['GET', 'POST']) def upload_file(): if request.method == 'POST': file = request.files['the_file'] file.save(f"/var/www/uploads/{secure_filename(file.filename)}") ... ``` For some better examples, see [Uploading Files](../patterns/fileuploads/index). ### Cookies To access cookies you can use the [`cookies`](../api/index#flask.Request.cookies "flask.Request.cookies") attribute. To set cookies you can use the [`set_cookie`](../api/index#flask.Response.set_cookie "flask.Response.set_cookie") method of response objects. The [`cookies`](../api/index#flask.Request.cookies "flask.Request.cookies") attribute of request objects is a dictionary with all the cookies the client transmits. If you want to use sessions, do not use the cookies directly but instead use the [Sessions](#sessions) in Flask that add some security on top of cookies for you. Reading cookies: ``` from flask import request @app.route('/') def index(): username = request.cookies.get('username') # use cookies.get(key) instead of cookies[key] to not get a # KeyError if the cookie is missing. ``` Storing cookies: ``` from flask import make_response @app.route('/') def index(): resp = make_response(render_template(...)) resp.set_cookie('username', 'the username') return resp ``` Note that cookies are set on response objects. Since you normally just return strings from the view functions Flask will convert them into response objects for you. If you explicitly want to do that you can use the [`make_response()`](../api/index#flask.make_response "flask.make_response") function and then modify it. Sometimes you might want to set a cookie at a point where the response object does not exist yet. This is possible by utilizing the [Deferred Request Callbacks](../patterns/deferredcallbacks/index) pattern. For this also see [About Responses](#about-responses). Redirects and Errors -------------------- To redirect a user to another endpoint, use the [`redirect()`](../api/index#flask.redirect "flask.redirect") function; to abort a request early with an error code, use the [`abort()`](../api/index#flask.abort "flask.abort") function: ``` from flask import abort, redirect, url_for @app.route('/') def index(): return redirect(url_for('login')) @app.route('/login') def login(): abort(401) this_is_never_executed() ``` This is a rather pointless example because a user will be redirected from the index to a page they cannot access (401 means access denied) but it shows how that works. By default a black and white error page is shown for each error code. If you want to customize the error page, you can use the [`errorhandler()`](../api/index#flask.Flask.errorhandler "flask.Flask.errorhandler") decorator: ``` from flask import render_template @app.errorhandler(404) def page_not_found(error): return render_template('page_not_found.html'), 404 ``` Note the `404` after the [`render_template()`](../api/index#flask.render_template "flask.render_template") call. This tells Flask that the status code of that page should be 404 which means not found. By default 200 is assumed which translates to: all went well. See [Handling Application Errors](../errorhandling/index) for more details. About Responses --------------- The return value from a view function is automatically converted into a response object for you. If the return value is a string it’s converted into a response object with the string as response body, a `200 OK` status code and a *text/html* mimetype. If the return value is a dict or list, `jsonify()` is called to produce a response. The logic that Flask applies to converting return values into response objects is as follows: 1. If a response object of the correct type is returned it’s directly returned from the view. 2. If it’s a string, a response object is created with that data and the default parameters. 3. If it’s an iterator or generator returning strings or bytes, it is treated as a streaming response. 4. If it’s a dict or list, a response object is created using [`jsonify()`](../api/index#flask.json.jsonify "flask.json.jsonify"). 5. If a tuple is returned the items in the tuple can provide extra information. Such tuples have to be in the form `(response, status)`, `(response, headers)`, or `(response, status, headers)`. The `status` value will override the status code and `headers` can be a list or dictionary of additional header values. 6. If none of that works, Flask will assume the return value is a valid WSGI application and convert that into a response object. If you want to get hold of the resulting response object inside the view you can use the [`make_response()`](../api/index#flask.make_response "flask.make_response") function. Imagine you have a view like this: ``` from flask import render_template @app.errorhandler(404) def not_found(error): return render_template('error.html'), 404 ``` You just need to wrap the return expression with [`make_response()`](../api/index#flask.make_response "flask.make_response") and get the response object to modify it, then return it: ``` from flask import make_response @app.errorhandler(404) def not_found(error): resp = make_response(render_template('error.html'), 404) resp.headers['X-Something'] = 'A value' return resp ``` ### APIs with JSON A common response format when writing an API is JSON. It’s easy to get started writing such an API with Flask. If you return a `dict` or `list` from a view, it will be converted to a JSON response. ``` @app.route("/me") def me_api(): user = get_current_user() return { "username": user.username, "theme": user.theme, "image": url_for("user_image", filename=user.image), } @app.route("/users") def users_api(): users = get_all_users() return [user.to_json() for user in users] ``` This is a shortcut to passing the data to the [`jsonify()`](../api/index#flask.json.jsonify "flask.json.jsonify") function, which will serialize any supported JSON data type. That means that all the data in the dict or list must be JSON serializable. For complex types such as database models, you’ll want to use a serialization library to convert the data to valid JSON types first. There are many serialization libraries and Flask API extensions maintained by the community that support more complex applications. Sessions -------- In addition to the request object there is also a second object called [`session`](../api/index#flask.session "flask.session") which allows you to store information specific to a user from one request to the next. This is implemented on top of cookies for you and signs the cookies cryptographically. What this means is that the user could look at the contents of your cookie but not modify it, unless they know the secret key used for signing. In order to use sessions you have to set a secret key. Here is how sessions work: ``` from flask import session # Set the secret key to some random bytes. Keep this really secret! app.secret_key = b'_5#y2L"F4Q8z\n\xec]/' @app.route('/') def index(): if 'username' in session: return f'Logged in as {session["username"]}' return 'You are not logged in' @app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': session['username'] = request.form['username'] return redirect(url_for('index')) return ''' <form method="post"> <p><input type=text name=username> <p><input type=submit value=Login> </form> ''' @app.route('/logout') def logout(): # remove the username from the session if it's there session.pop('username', None) return redirect(url_for('index')) ``` How to generate good secret keys A secret key should be as random as possible. Your operating system has ways to generate pretty random data based on a cryptographic random generator. Use the following command to quickly generate a value for `Flask.secret_key` (or [`SECRET_KEY`](../config/index#SECRET_KEY "SECRET_KEY")): ``` $ python -c 'import secrets; print(secrets.token_hex())' '192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf' ``` A note on cookie-based sessions: Flask will take the values you put into the session object and serialize them into a cookie. If you are finding some values do not persist across requests, cookies are indeed enabled, and you are not getting a clear error message, check the size of the cookie in your page responses compared to the size supported by web browsers. Besides the default client-side based sessions, if you want to handle sessions on the server-side instead, there are several Flask extensions that support this. Message Flashing ---------------- Good applications and user interfaces are all about feedback. If the user does not get enough feedback they will probably end up hating the application. Flask provides a really simple way to give feedback to a user with the flashing system. The flashing system basically makes it possible to record a message at the end of a request and access it on the next (and only the next) request. This is usually combined with a layout template to expose the message. To flash a message use the [`flash()`](../api/index#flask.flash "flask.flash") method, to get hold of the messages you can use [`get_flashed_messages()`](../api/index#flask.get_flashed_messages "flask.get_flashed_messages") which is also available in the templates. See [Message Flashing](../patterns/flashing/index) for a full example. Logging ------- Changelog New in version 0.3. Sometimes you might be in a situation where you deal with data that should be correct, but actually is not. For example you may have some client-side code that sends an HTTP request to the server but it’s obviously malformed. This might be caused by a user tampering with the data, or the client code failing. Most of the time it’s okay to reply with `400 Bad Request` in that situation, but sometimes that won’t do and the code has to continue working. You may still want to log that something fishy happened. This is where loggers come in handy. As of Flask 0.3 a logger is preconfigured for you to use. Here are some example log calls: ``` app.logger.debug('A value for debugging') app.logger.warning('A warning occurred (%d apples)', 42) app.logger.error('An error occurred') ``` The attached [`logger`](../api/index#flask.Flask.logger "flask.Flask.logger") is a standard logging [`Logger`](https://docs.python.org/3/library/logging.html#logging.Logger "(in Python v3.10)"), so head over to the official [`logging`](https://docs.python.org/3/library/logging.html#module-logging "(in Python v3.10)") docs for more information. See [Handling Application Errors](../errorhandling/index). Hooking in WSGI Middleware -------------------------- To add WSGI middleware to your Flask application, wrap the application’s `wsgi_app` attribute. For example, to apply Werkzeug’s [`ProxyFix`](https://werkzeug.palletsprojects.com/en/2.2.x/middleware/proxy_fix/#werkzeug.middleware.proxy_fix.ProxyFix "(in Werkzeug v2.2.x)") middleware for running behind Nginx: ``` from werkzeug.middleware.proxy_fix import ProxyFix app.wsgi_app = ProxyFix(app.wsgi_app) ``` Wrapping `app.wsgi_app` instead of `app` means that `app` still points at your Flask application, not at the middleware, so you can continue to use and configure `app` directly. Using Flask Extensions ---------------------- Extensions are packages that help you accomplish common tasks. For example, Flask-SQLAlchemy provides SQLAlchemy support that makes it simple and easy to use with Flask. For more on Flask extensions, see [Extensions](../extensions/index). Deploying to a Web Server ------------------------- Ready to deploy your new Flask app? See [Deploying to Production](../deploying/index).
programming_docs
flask Extensions Extensions ========== Extensions are extra packages that add functionality to a Flask application. For example, an extension might add support for sending email or connecting to a database. Some extensions add entire new frameworks to help build certain types of applications, like a REST API. Finding Extensions ------------------ Flask extensions are usually named “Flask-Foo” or “Foo-Flask”. You can search PyPI for packages tagged with [Framework :: Flask](https://pypi.org/search/?c=Framework+%3A%3A+Flask). Using Extensions ---------------- Consult each extension’s documentation for installation, configuration, and usage instructions. Generally, extensions pull their own configuration from [`app.config`](../api/index#flask.Flask.config "flask.Flask.config") and are passed an application instance during initialization. For example, an extension called “Flask-Foo” might be used like this: ``` from flask_foo import Foo foo = Foo() app = Flask(__name__) app.config.update( FOO_BAR='baz', FOO_SPAM='eggs', ) foo.init_app(app) ``` Building Extensions ------------------- While [PyPI](https://pypi.org/search/?c=Framework+%3A%3A+Flask) contains many Flask extensions, you may not find an extension that fits your need. If this is the case, you can create your own, and publish it for others to use as well. Read [Flask Extension Development](https://flask.palletsprojects.com/en/2.2.x/extensiondev/) to develop your own Flask extension. flask Testing Flask Applications Testing Flask Applications ========================== Flask provides utilities for testing an application. This documentation goes over techniques for working with different parts of the application in tests. We will use the [pytest](https://docs.pytest.org/) framework to set up and run our tests. ``` $ pip install pytest ``` The [tutorial](https://flask.palletsprojects.com/en/2.2.x/tutorial/) goes over how to write tests for 100% coverage of the sample Flaskr blog application. See [the tutorial on tests](https://flask.palletsprojects.com/en/2.2.x/tutorial/tests/) for a detailed explanation of specific tests for an application. Identifying Tests ----------------- Tests are typically located in the `tests` folder. Tests are functions that start with `test_`, in Python modules that start with `test_`. Tests can also be further grouped in classes that start with `Test`. It can be difficult to know what to test. Generally, try to test the code that you write, not the code of libraries that you use, since they are already tested. Try to extract complex behaviors as separate functions to test individually. Fixtures -------- Pytest *fixtures* allow writing pieces of code that are reusable across tests. A simple fixture returns a value, but a fixture can also do setup, yield a value, then do teardown. Fixtures for the application, test client, and CLI runner are shown below, they can be placed in `tests/conftest.py`. If you’re using an [application factory](../patterns/appfactories/index), define an `app` fixture to create and configure an app instance. You can add code before and after the `yield` to set up and tear down other resources, such as creating and clearing a database. If you’re not using a factory, you already have an app object you can import and configure directly. You can still use an `app` fixture to set up and tear down resources. ``` import pytest from my_project import create_app @pytest.fixture() def app(): app = create_app() app.config.update({ "TESTING": True, }) # other setup can go here yield app # clean up / reset resources here @pytest.fixture() def client(app): return app.test_client() @pytest.fixture() def runner(app): return app.test_cli_runner() ``` Sending Requests with the Test Client ------------------------------------- The test client makes requests to the application without running a live server. Flask’s client extends [Werkzeug’s client](https://werkzeug.palletsprojects.com/en/2.2.x/test/ "(in Werkzeug v2.2.x)"), see those docs for additional information. The `client` has methods that match the common HTTP request methods, such as `client.get()` and `client.post()`. They take many arguments for building the request; you can find the full documentation in [`EnvironBuilder`](https://werkzeug.palletsprojects.com/en/2.2.x/test/#werkzeug.test.EnvironBuilder "(in Werkzeug v2.2.x)"). Typically you’ll use `path`, `query_string`, `headers`, and `data` or `json`. To make a request, call the method the request should use with the path to the route to test. A [`TestResponse`](https://werkzeug.palletsprojects.com/en/2.2.x/test/#werkzeug.test.TestResponse "(in Werkzeug v2.2.x)") is returned to examine the response data. It has all the usual properties of a response object. You’ll usually look at `response.data`, which is the bytes returned by the view. If you want to use text, Werkzeug 2.1 provides `response.text`, or use `response.get_data(as_text=True)`. ``` def test_request_example(client): response = client.get("/posts") assert b"<h2>Hello, World!</h2>" in response.data ``` Pass a dict `query_string={"key": "value", ...}` to set arguments in the query string (after the `?` in the URL). Pass a dict `headers={}` to set request headers. To send a request body in a POST or PUT request, pass a value to `data`. If raw bytes are passed, that exact body is used. Usually, you’ll pass a dict to set form data. ### Form Data To send form data, pass a dict to `data`. The `Content-Type` header will be set to `multipart/form-data` or `application/x-www-form-urlencoded` automatically. If a value is a file object opened for reading bytes (`"rb"` mode), it will be treated as an uploaded file. To change the detected filename and content type, pass a `(file, filename, content_type)` tuple. File objects will be closed after making the request, so they do not need to use the usual `with open() as f:` pattern. It can be useful to store files in a `tests/resources` folder, then use `pathlib.Path` to get files relative to the current test file. ``` from pathlib import Path # get the resources folder in the tests folder resources = Path(__file__).parent / "resources" def test_edit_user(client): response = client.post("/user/2/edit", data={ "name": "Flask", "theme": "dark", "picture": (resources / "picture.png").open("rb"), }) assert response.status_code == 200 ``` ### JSON Data To send JSON data, pass an object to `json`. The `Content-Type` header will be set to `application/json` automatically. Similarly, if the response contains JSON data, the `response.json` attribute will contain the deserialized object. ``` def test_json_data(client): response = client.post("/graphql", json={ "query": """ query User($id: String!) { user(id: $id) { name theme picture_url } } """, variables={"id": 2}, }) assert response.json["data"]["user"]["name"] == "Flask" ``` Following Redirects ------------------- By default, the client does not make additional requests if the response is a redirect. By passing `follow_redirects=True` to a request method, the client will continue to make requests until a non-redirect response is returned. [`TestResponse.history`](https://werkzeug.palletsprojects.com/en/2.2.x/test/#werkzeug.test.TestResponse.history "(in Werkzeug v2.2.x)") is a tuple of the responses that led up to the final response. Each response has a [`request`](https://werkzeug.palletsprojects.com/en/2.2.x/test/#werkzeug.test.TestResponse.request "(in Werkzeug v2.2.x)") attribute which records the request that produced that response. ``` def test_logout_redirect(client): response = client.get("/logout") # Check that there was one redirect response. assert len(response.history) == 1 # Check that the second request was to the index page. assert response.request.path == "/index" ``` Accessing and Modifying the Session ----------------------------------- To access Flask’s context variables, mainly [`session`](../api/index#flask.session "flask.session"), use the client in a `with` statement. The app and request context will remain active *after* making a request, until the `with` block ends. ``` from flask import session def test_access_session(client): with client: client.post("/auth/login", data={"username": "flask"}) # session is still accessible assert session["user_id"] == 1 # session is no longer accessible ``` If you want to access or set a value in the session *before* making a request, use the client’s [`session_transaction()`](../api/index#flask.testing.FlaskClient.session_transaction "flask.testing.FlaskClient.session_transaction") method in a `with` statement. It returns a session object, and will save the session once the block ends. ``` from flask import session def test_modify_session(client): with client.session_transaction() as session: # set a user id without going through the login route session["user_id"] = 1 # session is saved now response = client.get("/users/me") assert response.json["username"] == "flask" ``` Running Commands with the CLI Runner ------------------------------------ Flask provides [`test_cli_runner()`](../api/index#flask.Flask.test_cli_runner "flask.Flask.test_cli_runner") to create a [`FlaskCliRunner`](../api/index#flask.testing.FlaskCliRunner "flask.testing.FlaskCliRunner"), which runs CLI commands in isolation and captures the output in a [`Result`](https://click.palletsprojects.com/en/8.1.x/api/#click.testing.Result "(in Click v8.1.x)") object. Flask’s runner extends [Click’s runner](https://click.palletsprojects.com/en/8.1.x/testing/ "(in Click v8.1.x)"), see those docs for additional information. Use the runner’s [`invoke()`](../api/index#flask.testing.FlaskCliRunner.invoke "flask.testing.FlaskCliRunner.invoke") method to call commands in the same way they would be called with the `flask` command from the command line. ``` import click @app.cli.command("hello") @click.option("--name", default="World") def hello_command(name): click.echo(f"Hello, {name}!") def test_hello_command(runner): result = runner.invoke(args="hello") assert "World" in result.output result = runner.invoke(args=["hello", "--name", "Flask"]) assert "Flask" in result.output ``` Tests that depend on an Active Context -------------------------------------- You may have functions that are called from views or commands, that expect an active [application context](../appcontext/index) or [request context](../reqcontext/index) because they access `request`, `session`, or `current_app`. Rather than testing them by making a request or invoking the command, you can create and activate a context directly. Use `with app.app_context()` to push an application context. For example, database extensions usually require an active app context to make queries. ``` def test_db_post_model(app): with app.app_context(): post = db.session.query(Post).get(1) ``` Use `with app.test_request_context()` to push a request context. It takes the same arguments as the test client’s request methods. ``` def test_validate_user_edit(app): with app.test_request_context( "/user/2/edit", method="POST", data={"name": ""} ): # call a function that accesses `request` messages = validate_edit_user() assert messages["name"][0] == "Name cannot be empty." ``` Creating a test request context doesn’t run any of the Flask dispatching code, so `before_request` functions are not called. If you need to call these, usually it’s better to make a full request instead. However, it’s possible to call them manually. ``` def test_auth_token(app): with app.test_request_context("/user/2/edit", headers={"X-Auth-Token": "1"}): app.preprocess_request() assert g.user.name == "Flask" ``` flask The Application Context The Application Context ======================= The application context keeps track of the application-level data during a request, CLI command, or other activity. Rather than passing the application around to each function, the [`current_app`](../api/index#flask.current_app "flask.current_app") and [`g`](../api/index#flask.g "flask.g") proxies are accessed instead. This is similar to [The Request Context](../reqcontext/index), which keeps track of request-level data during a request. A corresponding application context is pushed when a request context is pushed. Purpose of the Context ---------------------- The [`Flask`](../api/index#flask.Flask "flask.Flask") application object has attributes, such as [`config`](../api/index#flask.Flask.config "flask.Flask.config"), that are useful to access within views and [CLI commands](../cli/index). However, importing the `app` instance within the modules in your project is prone to circular import issues. When using the [app factory pattern](../patterns/appfactories/index) or writing reusable [blueprints](../blueprints/index) or [extensions](../extensions/index) there won’t be an `app` instance to import at all. Flask solves this issue with the *application context*. Rather than referring to an `app` directly, you use the [`current_app`](../api/index#flask.current_app "flask.current_app") proxy, which points to the application handling the current activity. Flask automatically *pushes* an application context when handling a request. View functions, error handlers, and other functions that run during a request will have access to [`current_app`](../api/index#flask.current_app "flask.current_app"). Flask will also automatically push an app context when running CLI commands registered with [`Flask.cli`](../api/index#flask.Flask.cli "flask.Flask.cli") using `@app.cli.command()`. Lifetime of the Context ----------------------- The application context is created and destroyed as necessary. When a Flask application begins handling a request, it pushes an application context and a [request context](../reqcontext/index). When the request ends it pops the request context then the application context. Typically, an application context will have the same lifetime as a request. See [The Request Context](../reqcontext/index) for more information about how the contexts work and the full life cycle of a request. Manually Push a Context ----------------------- If you try to access [`current_app`](../api/index#flask.current_app "flask.current_app"), or anything that uses it, outside an application context, you’ll get this error message: ``` RuntimeError: Working outside of application context. This typically means that you attempted to use functionality that needed to interface with the current application object in some way. To solve this, set up an application context with app.app_context(). ``` If you see that error while configuring your application, such as when initializing an extension, you can push a context manually since you have direct access to the `app`. Use [`app_context()`](../api/index#flask.Flask.app_context "flask.Flask.app_context") in a `with` block, and everything that runs in the block will have access to [`current_app`](../api/index#flask.current_app "flask.current_app"). ``` def create_app(): app = Flask(__name__) with app.app_context(): init_db() return app ``` If you see that error somewhere else in your code not related to configuring the application, it most likely indicates that you should move that code into a view function or CLI command. Storing Data ------------ The application context is a good place to store common data during a request or CLI command. Flask provides the [`g object`](../api/index#flask.g "flask.g") for this purpose. It is a simple namespace object that has the same lifetime as an application context. Note The `g` name stands for “global”, but that is referring to the data being global *within a context*. The data on `g` is lost after the context ends, and it is not an appropriate place to store data between requests. Use the [`session`](../api/index#flask.session "flask.session") or a database to store data across requests. A common use for [`g`](../api/index#flask.g "flask.g") is to manage resources during a request. 1. `get_X()` creates resource `X` if it does not exist, caching it as `g.X`. 2. `teardown_X()` closes or otherwise deallocates the resource if it exists. It is registered as a [`teardown_appcontext()`](../api/index#flask.Flask.teardown_appcontext "flask.Flask.teardown_appcontext") handler. For example, you can manage a database connection using this pattern: ``` from flask import g def get_db(): if 'db' not in g: g.db = connect_to_database() return g.db @app.teardown_appcontext def teardown_db(exception): db = g.pop('db', None) if db is not None: db.close() ``` During a request, every call to `get_db()` will return the same connection, and it will be closed automatically at the end of the request. You can use [`LocalProxy`](https://werkzeug.palletsprojects.com/en/2.2.x/local/#werkzeug.local.LocalProxy "(in Werkzeug v2.2.x)") to make a new context local from `get_db()`: ``` from werkzeug.local import LocalProxy db = LocalProxy(get_db) ``` Accessing `db` will call `get_db` internally, in the same way that [`current_app`](../api/index#flask.current_app "flask.current_app") works. Events and Signals ------------------ The application will call functions registered with [`teardown_appcontext()`](../api/index#flask.Flask.teardown_appcontext "flask.Flask.teardown_appcontext") when the application context is popped. If [`signals_available`](../api/index#flask.signals.signals_available "flask.signals.signals_available") is true, the following signals are sent: [`appcontext_pushed`](../api/index#flask.appcontext_pushed "flask.appcontext_pushed"), [`appcontext_tearing_down`](../api/index#flask.appcontext_tearing_down "flask.appcontext_tearing_down"), and [`appcontext_popped`](../api/index#flask.appcontext_popped "flask.appcontext_popped"). flask API API === This part of the documentation covers all the interfaces of Flask. For parts where Flask depends on external libraries, we document the most important right here and provide links to the canonical documentation. Application Object ------------------ `class flask.Flask(import_name, static_url_path=None, static_folder='static', static_host=None, host_matching=False, subdomain_matching=False, template_folder='templates', instance_path=None, instance_relative_config=False, root_path=None)` The flask object implements a WSGI application and acts as the central object. It is passed the name of the module or package of the application. Once it is created it will act as a central registry for the view functions, the URL rules, template configuration and much more. The name of the package is used to resolve resources from inside the package or the folder the module is contained in depending on if the package parameter resolves to an actual python package (a folder with an `__init__.py` file inside) or a standard module (just a `.py` file). For more information about resource loading, see [`open_resource()`](#flask.Flask.open_resource "flask.Flask.open_resource"). Usually you create a [`Flask`](#flask.Flask "flask.Flask") instance in your main module or in the `__init__.py` file of your package like this: ``` from flask import Flask app = Flask(__name__) ``` About the First Parameter The idea of the first parameter is to give Flask an idea of what belongs to your application. This name is used to find resources on the filesystem, can be used by extensions to improve debugging information and a lot more. So it’s important what you provide there. If you are using a single module, `__name__` is always the correct value. If you however are using a package, it’s usually recommended to hardcode the name of your package there. For example if your application is defined in `yourapplication/app.py` you should create it with one of the two versions below: ``` app = Flask('yourapplication') app = Flask(__name__.split('.')[0]) ``` Why is that? The application will work even with `__name__`, thanks to how resources are looked up. However it will make debugging more painful. Certain extensions can make assumptions based on the import name of your application. For example the Flask-SQLAlchemy extension will look for the code in your application that triggered an SQL query in debug mode. If the import name is not properly set up, that debugging information is lost. (For example it would only pick up SQL queries in `yourapplication.app` and not `yourapplication.views.frontend`) Changelog New in version 1.0: The `host_matching` and `static_host` parameters were added. New in version 1.0: The `subdomain_matching` parameter was added. Subdomain matching needs to be enabled manually now. Setting [`SERVER_NAME`](../config/index#SERVER_NAME "SERVER_NAME") does not implicitly enable it. New in version 0.11: The `root_path` parameter was added. New in version 0.8: The `instance_path` and `instance_relative_config` parameters were added. New in version 0.7: The `static_url_path`, `static_folder`, and `template_folder` parameters were added. Parameters * **import\_name** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – the name of the application package * **static\_url\_path** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – can be used to specify a different path for the static files on the web. Defaults to the name of the `static_folder` folder. * **static\_folder** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [os.PathLike](https://docs.python.org/3/library/os.html#os.PathLike "(in Python v3.10)")*]**]*) – The folder with static files that is served at `static_url_path`. Relative to the application `root_path` or an absolute path. Defaults to `'static'`. * **static\_host** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – the host to use when adding the static route. Defaults to None. Required when using `host_matching=True` with a `static_folder` configured. * **host\_matching** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – set `url_map.host_matching` attribute. Defaults to False. * **subdomain\_matching** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – consider the subdomain relative to [`SERVER_NAME`](../config/index#SERVER_NAME "SERVER_NAME") when matching routes. Defaults to False. * **template\_folder** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – the folder that contains the templates that should be used by the application. Defaults to `'templates'` folder in the root path of the application. * **instance\_path** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – An alternative instance path for the application. By default the folder `'instance'` next to the package or module is assumed to be the instance path. * **instance\_relative\_config** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – if set to `True` relative filenames for loading the config are assumed to be relative to the instance path instead of the application root. * **root\_path** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – The path to the root of the application files. This should only be set manually when it can’t be detected automatically, such as for namespace packages. `aborter` An instance of [`aborter_class`](#flask.Flask.aborter_class "flask.Flask.aborter_class") created by [`make_aborter()`](#flask.Flask.make_aborter "flask.Flask.make_aborter"). This is called by [`flask.abort()`](#flask.abort "flask.abort") to raise HTTP errors, and can be called directly as well. New in version 2.2: Moved from `flask.abort`, which calls this object. `aborter_class` alias of [`werkzeug.exceptions.Aborter`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.Aborter "(in Werkzeug v2.2.x)") `add_template_filter(f, name=None)` Register a custom template filter. Works exactly like the [`template_filter()`](#flask.Flask.template_filter "flask.Flask.template_filter") decorator. Parameters * **name** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – the optional name of the filter, otherwise the function name will be used. * **f** ([Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[**...**]**,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]*) – Return type None `add_template_global(f, name=None)` Register a custom template global function. Works exactly like the [`template_global()`](#flask.Flask.template_global "flask.Flask.template_global") decorator. Changelog New in version 0.10. Parameters * **name** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – the optional name of the global function, otherwise the function name will be used. * **f** ([Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[**...**]**,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]*) – Return type None `add_template_test(f, name=None)` Register a custom template test. Works exactly like the [`template_test()`](#flask.Flask.template_test "flask.Flask.template_test") decorator. Changelog New in version 0.10. Parameters * **name** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – the optional name of the test, otherwise the function name will be used. * **f** ([Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[**...**]**,* [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")*]*) – Return type None `add_url_rule(rule, endpoint=None, view_func=None, provide_automatic_options=None, **options)` Register a rule for routing incoming requests and building URLs. The [`route()`](#flask.Flask.route "flask.Flask.route") decorator is a shortcut to call this with the `view_func` argument. These are equivalent: ``` @app.route("/") def index(): ... ``` ``` def index(): ... app.add_url_rule("/", view_func=index) ``` See [URL Route Registrations](#url-route-registrations). The endpoint name for the route defaults to the name of the view function if the `endpoint` parameter isn’t passed. An error will be raised if a function has already been registered for the endpoint. The `methods` parameter defaults to `["GET"]`. `HEAD` is always added automatically, and `OPTIONS` is added automatically by default. `view_func` does not necessarily need to be passed, but if the rule should participate in routing an endpoint name must be associated with a view function at some point with the [`endpoint()`](#flask.Flask.endpoint "flask.Flask.endpoint") decorator. ``` app.add_url_rule("/", endpoint="index") @app.endpoint("index") def index(): ... ``` If `view_func` has a `required_methods` attribute, those methods are added to the passed and automatic methods. If it has a `provide_automatic_methods` attribute, it is used as the default if the parameter is not passed. Parameters * **rule** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – The URL rule string. * **endpoint** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – The endpoint name to associate with the rule and view function. Used when routing and building URLs. Defaults to `view_func.__name__`. * **view\_func** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[**...**]**,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[**Headers**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**,* [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")*[*[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**]**]**]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[**Headers**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**,* [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")*[*[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**]**]**]**,* *WSGIApplication**]**]**,* [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[**...**]**,* [Awaitable](https://docs.python.org/3/library/typing.html#typing.Awaitable "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[**Headers**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**,* [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")*[*[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**]**]**]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[**Headers**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**,* [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")*[*[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**]**]**]**,* *WSGIApplication**]**]**]**]**]*) – The view function to associate with the endpoint name. * **provide\_automatic\_options** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")*]*) – Add the `OPTIONS` method and respond to `OPTIONS` requests automatically. * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Extra options passed to the [`Rule`](https://werkzeug.palletsprojects.com/en/2.2.x/routing/#werkzeug.routing.Rule "(in Werkzeug v2.2.x)") object. Return type None `after_request(f)` Register a function to run after each request to this object. The function is called with the response object, and must return a response object. This allows the functions to modify or replace the response before it is sent. If a function raises an exception, any remaining `after_request` functions will not be called. Therefore, this should not be used for actions that must execute, such as to close resources. Use [`teardown_request()`](#flask.Flask.teardown_request "flask.Flask.teardown_request") for that. Parameters **f** (*flask.scaffold.T\_after\_request*) – Return type flask.scaffold.T\_after\_request `after_request_funcs: t.Dict[ft.AppOrBlueprintKey, t.List[ft.AfterRequestCallable]]` A data structure of functions to call at the end of each request, in the format `{scope: [functions]}`. The `scope` key is the name of a blueprint the functions are active for, or `None` for all requests. To register a function, use the [`after_request()`](#flask.Flask.after_request "flask.Flask.after_request") decorator. This data structure is internal. It should not be modified directly and its format may change at any time. `app_context()` Create an [`AppContext`](#flask.ctx.AppContext "flask.ctx.AppContext"). Use as a `with` block to push the context, which will make [`current_app`](#flask.current_app "flask.current_app") point at this application. An application context is automatically pushed by `RequestContext.push()` when handling a request, and when running a CLI command. Use this to manually create a context outside of these situations. ``` with app.app_context(): init_db() ``` See [The Application Context](../appcontext/index). Changelog New in version 0.9. Return type [flask.ctx.AppContext](#flask.ctx.AppContext "flask.ctx.AppContext") `app_ctx_globals_class` alias of [`flask.ctx._AppCtxGlobals`](#flask.ctx._AppCtxGlobals "flask.ctx._AppCtxGlobals") `async_to_sync(func)` Return a sync function that will run the coroutine function. ``` result = app.async_to_sync(func)(*args, **kwargs) ``` Override this method to change how the app converts async code to be synchronously callable. Changelog New in version 2.0. Parameters **func** ([Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[**...**]**,* [Coroutine](https://docs.python.org/3/library/typing.html#typing.Coroutine "(in Python v3.10)")*]*) – Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[…], [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")] `auto_find_instance_path()` Tries to locate the instance path if it was not provided to the constructor of the application class. It will basically calculate the path to a folder named `instance` next to your main file or the package. Changelog New in version 0.8. Return type [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") `before_first_request(f)` Registers a function to be run before the first request to this instance of the application. The function will be called without any arguments and its return value is ignored. Deprecated since version 2.2: Will be removed in Flask 2.3. Run setup code when creating the application instead. Changelog New in version 0.8. Parameters **f** (*flask.app.T\_before\_first\_request*) – Return type flask.app.T\_before\_first\_request `before_first_request_funcs: t.List[ft.BeforeFirstRequestCallable]` A list of functions that will be called at the beginning of the first request to this instance. To register a function, use the [`before_first_request()`](#flask.Flask.before_first_request "flask.Flask.before_first_request") decorator. Deprecated since version 2.2: Will be removed in Flask 2.3. Run setup code when creating the application instead. Changelog New in version 0.8. `before_request(f)` Register a function to run before each request. For example, this can be used to open a database connection, or to load the logged in user from the session. ``` @app.before_request def load_user(): if "user_id" in session: g.user = db.session.get(session["user_id"]) ``` The function will be called without any arguments. If it returns a non-`None` value, the value is handled as if it was the return value from the view, and further request handling is stopped. Parameters **f** (*flask.scaffold.T\_before\_request*) – Return type flask.scaffold.T\_before\_request `before_request_funcs: t.Dict[ft.AppOrBlueprintKey, t.List[ft.BeforeRequestCallable]]` A data structure of functions to call at the beginning of each request, in the format `{scope: [functions]}`. The `scope` key is the name of a blueprint the functions are active for, or `None` for all requests. To register a function, use the [`before_request()`](#flask.Flask.before_request "flask.Flask.before_request") decorator. This data structure is internal. It should not be modified directly and its format may change at any time. `blueprints: t.Dict[str, 'Blueprint']` Maps registered blueprint names to blueprint objects. The dict retains the order the blueprints were registered in. Blueprints can be registered multiple times, this dict does not track how often they were attached. Changelog New in version 0.7. `cli` The Click command group for registering CLI commands for this object. The commands are available from the `flask` command once the application has been discovered and blueprints have been registered. `config` The configuration dictionary as [`Config`](#flask.Config "flask.Config"). This behaves exactly like a regular dictionary but supports additional methods to load a config from files. `config_class` alias of [`flask.config.Config`](#flask.Config "flask.config.Config") `context_processor(f)` Registers a template context processor function. Parameters **f** (*flask.scaffold.T\_template\_context\_processor*) – Return type flask.scaffold.T\_template\_context\_processor `create_global_jinja_loader()` Creates the loader for the Jinja2 environment. Can be used to override just the loader and keeping the rest unchanged. It’s discouraged to override this function. Instead one should override the [`jinja_loader()`](#flask.Flask.jinja_loader "flask.Flask.jinja_loader") function instead. The global loader dispatches between the loaders of the application and the individual blueprints. Changelog New in version 0.7. Return type flask.templating.DispatchingJinjaLoader `create_jinja_environment()` Create the Jinja environment based on [`jinja_options`](#flask.Flask.jinja_options "flask.Flask.jinja_options") and the various Jinja-related methods of the app. Changing [`jinja_options`](#flask.Flask.jinja_options "flask.Flask.jinja_options") after this will have no effect. Also adds Flask-related globals and filters to the environment. Changelog Changed in version 0.11: `Environment.auto_reload` set in accordance with `TEMPLATES_AUTO_RELOAD` configuration option. New in version 0.5. Return type flask.templating.Environment `create_url_adapter(request)` Creates a URL adapter for the given request. The URL adapter is created at a point where the request context is not yet set up so the request is passed explicitly. Changelog Changed in version 1.0: [`SERVER_NAME`](../config/index#SERVER_NAME "SERVER_NAME") no longer implicitly enables subdomain matching. Use `subdomain_matching` instead. Changed in version 0.9: This can now also be called without a request object when the URL adapter is created for the application context. New in version 0.6. Parameters **request** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[flask.wrappers.Request](#flask.Request "flask.wrappers.Request")*]*) – Return type [Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")[[werkzeug.routing.map.MapAdapter](https://werkzeug.palletsprojects.com/en/2.2.x/routing/#werkzeug.routing.MapAdapter "(in Werkzeug v2.2.x)")] `property debug: bool` Whether debug mode is enabled. When using `flask run` to start the development server, an interactive debugger will be shown for unhandled exceptions, and the server will be reloaded when code changes. This maps to the [`DEBUG`](../config/index#DEBUG "DEBUG") config key. It may not behave as expected if set late. **Do not enable debug mode when deploying in production.** Default: `False` `default_config = {'APPLICATION_ROOT': '/', 'DEBUG': None, 'ENV': None, 'EXPLAIN_TEMPLATE_LOADING': False, 'JSONIFY_MIMETYPE': None, 'JSONIFY_PRETTYPRINT_REGULAR': None, 'JSON_AS_ASCII': None, 'JSON_SORT_KEYS': None, 'MAX_CONTENT_LENGTH': None, 'MAX_COOKIE_SIZE': 4093, 'PERMANENT_SESSION_LIFETIME': datetime.timedelta(days=31), 'PREFERRED_URL_SCHEME': 'http', 'PROPAGATE_EXCEPTIONS': None, 'SECRET_KEY': None, 'SEND_FILE_MAX_AGE_DEFAULT': None, 'SERVER_NAME': None, 'SESSION_COOKIE_DOMAIN': None, 'SESSION_COOKIE_HTTPONLY': True, 'SESSION_COOKIE_NAME': 'session', 'SESSION_COOKIE_PATH': None, 'SESSION_COOKIE_SAMESITE': None, 'SESSION_COOKIE_SECURE': False, 'SESSION_REFRESH_EACH_REQUEST': True, 'TEMPLATES_AUTO_RELOAD': None, 'TESTING': False, 'TRAP_BAD_REQUEST_ERRORS': None, 'TRAP_HTTP_EXCEPTIONS': False, 'USE_X_SENDFILE': False}` Default configuration parameters. `delete(rule, **options)` Shortcut for [`route()`](#flask.Flask.route "flask.Flask.route") with `methods=["DELETE"]`. Changelog New in version 2.0. Parameters * **rule** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.scaffold.T\_route], flask.scaffold.T\_route] `dispatch_request()` Does the request dispatching. Matches the URL and returns the return value of the view or error handler. This does not have to be a response object. In order to convert the return value to a proper response object, call [`make_response()`](#flask.make_response "flask.make_response"). Changelog Changed in version 0.7: This no longer does the exception handling, this code was moved to the new [`full_dispatch_request()`](#flask.Flask.full_dispatch_request "flask.Flask.full_dispatch_request"). Return type [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[Headers, [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]], [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]]]]], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[Headers, [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]], [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]]]]], WSGIApplication] `do_teardown_appcontext(exc=<object object>)` Called right before the application context is popped. When handling a request, the application context is popped after the request context. See [`do_teardown_request()`](#flask.Flask.do_teardown_request "flask.Flask.do_teardown_request"). This calls all functions decorated with [`teardown_appcontext()`](#flask.Flask.teardown_appcontext "flask.Flask.teardown_appcontext"). Then the [`appcontext_tearing_down`](#flask.appcontext_tearing_down "flask.appcontext_tearing_down") signal is sent. This is called by [`AppContext.pop()`](#flask.ctx.AppContext.pop "flask.ctx.AppContext.pop"). Changelog New in version 0.9. Parameters **exc** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[BaseException](https://docs.python.org/3/library/exceptions.html#BaseException "(in Python v3.10)")*]*) – Return type None `do_teardown_request(exc=<object object>)` Called after the request is dispatched and the response is returned, right before the request context is popped. This calls all functions decorated with [`teardown_request()`](#flask.Flask.teardown_request "flask.Flask.teardown_request"), and [`Blueprint.teardown_request()`](#flask.Blueprint.teardown_request "flask.Blueprint.teardown_request") if a blueprint handled the request. Finally, the [`request_tearing_down`](#flask.request_tearing_down "flask.request_tearing_down") signal is sent. This is called by [`RequestContext.pop()`](#flask.ctx.RequestContext.pop "flask.ctx.RequestContext.pop"), which may be delayed during testing to maintain access to resources. Parameters **exc** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[BaseException](https://docs.python.org/3/library/exceptions.html#BaseException "(in Python v3.10)")*]*) – An unhandled exception raised while dispatching the request. Detected from the current exception information if not passed. Passed to each teardown function. Return type None Changelog Changed in version 0.9: Added the `exc` argument. `endpoint(endpoint)` Decorate a view function to register it for the given endpoint. Used if a rule is added without a `view_func` with [`add_url_rule()`](#flask.Flask.add_url_rule "flask.Flask.add_url_rule"). ``` app.add_url_rule("/ex", endpoint="example") @app.endpoint("example") def example(): ... ``` Parameters **endpoint** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – The endpoint name to associate with the view function. Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.scaffold.F], flask.scaffold.F] `ensure_sync(func)` Ensure that the function is synchronous for WSGI workers. Plain `def` functions are returned as-is. `async def` functions are wrapped to run and wait for the response. Override this method to change how the app runs async views. Changelog New in version 2.0. Parameters **func** ([Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")) – Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)") `property env: str` What environment the app is running in. This maps to the [`ENV`](../config/index#ENV "ENV") config key. **Do not enable development when deploying in production.** Default: `'production'` Deprecated since version 2.2: Will be removed in Flask 2.3. `error_handler_spec: t.Dict[ft.AppOrBlueprintKey, t.Dict[t.Optional[int], t.Dict[t.Type[Exception], ft.ErrorHandlerCallable]]]` A data structure of registered error handlers, in the format `{scope: {code: {class: handler}}}`. The `scope` key is the name of a blueprint the handlers are active for, or `None` for all requests. The `code` key is the HTTP status code for `HTTPException`, or `None` for other exceptions. The innermost dictionary maps exception classes to handler functions. To register an error handler, use the [`errorhandler()`](#flask.Flask.errorhandler "flask.Flask.errorhandler") decorator. This data structure is internal. It should not be modified directly and its format may change at any time. `errorhandler(code_or_exception)` Register a function to handle errors by code or exception class. A decorator that is used to register a function given an error code. Example: ``` @app.errorhandler(404) def page_not_found(error): return 'This page does not exist', 404 ``` You can also register handlers for arbitrary exceptions: ``` @app.errorhandler(DatabaseError) def special_exception_handler(error): return 'Database connection failed', 500 ``` Changelog New in version 0.7: Use [`register_error_handler()`](#flask.Flask.register_error_handler "flask.Flask.register_error_handler") instead of modifying [`error_handler_spec`](#flask.Flask.error_handler_spec "flask.Flask.error_handler_spec") directly, for application wide error handlers. New in version 0.7: One can now additionally also register custom exception types that do not necessarily have to be a subclass of the [`HTTPException`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.HTTPException "(in Werkzeug v2.2.x)") class. Parameters **code\_or\_exception** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Type](https://docs.python.org/3/library/typing.html#typing.Type "(in Python v3.10)")*[*[Exception](https://docs.python.org/3/library/exceptions.html#Exception "(in Python v3.10)")*]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*]*) – the code as integer for the handler, or an arbitrary exception Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.scaffold.T\_error\_handler], flask.scaffold.T\_error\_handler] `extensions: dict` a place where extensions can store application specific state. For example this is where an extension could store database engines and similar things. The key must match the name of the extension module. For example in case of a “Flask-Foo” extension in `flask_foo`, the key would be `'foo'`. Changelog New in version 0.7. `full_dispatch_request()` Dispatches the request and on top of that performs request pre and postprocessing as well as HTTP exception catching and error handling. Changelog New in version 0.7. Return type [flask.wrappers.Response](#flask.Response "flask.wrappers.Response") `get(rule, **options)` Shortcut for [`route()`](#flask.Flask.route "flask.Flask.route") with `methods=["GET"]`. Changelog New in version 2.0. Parameters * **rule** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.scaffold.T\_route], flask.scaffold.T\_route] `get_send_file_max_age(filename)` Used by [`send_file()`](#flask.send_file "flask.send_file") to determine the `max_age` cache value for a given file path if it wasn’t passed. By default, this returns [`SEND_FILE_MAX_AGE_DEFAULT`](../config/index#SEND_FILE_MAX_AGE_DEFAULT "SEND_FILE_MAX_AGE_DEFAULT") from the configuration of [`current_app`](#flask.current_app "flask.current_app"). This defaults to `None`, which tells the browser to use conditional requests instead of a timed cache, which is usually preferable. Changelog Changed in version 2.0: The default configuration is `None` instead of 12 hours. New in version 0.9. Parameters **filename** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – Return type [Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")[[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")] `property got_first_request: bool` This attribute is set to `True` if the application started handling the first request. Changelog New in version 0.8. `handle_exception(e)` Handle an exception that did not have an error handler associated with it, or that was raised from an error handler. This always causes a 500 `InternalServerError`. Always sends the [`got_request_exception`](#flask.got_request_exception "flask.got_request_exception") signal. If [`propagate_exceptions`](#flask.Flask.propagate_exceptions "flask.Flask.propagate_exceptions") is `True`, such as in debug mode, the error will be re-raised so that the debugger can display it. Otherwise, the original exception is logged, and an [`InternalServerError`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.InternalServerError "(in Werkzeug v2.2.x)") is returned. If an error handler is registered for `InternalServerError` or `500`, it will be used. For consistency, the handler will always receive the `InternalServerError`. The original unhandled exception is available as `e.original_exception`. Changelog Changed in version 1.1.0: Always passes the `InternalServerError` instance to the handler, setting `original_exception` to the unhandled error. Changed in version 1.1.0: `after_request` functions and other finalization is done even for the default 500 response when there is no handler. New in version 0.3. Parameters **e** ([Exception](https://docs.python.org/3/library/exceptions.html#Exception "(in Python v3.10)")) – Return type [flask.wrappers.Response](#flask.Response "flask.wrappers.Response") `handle_http_exception(e)` Handles an HTTP exception. By default this will invoke the registered error handlers and fall back to returning the exception as response. Changelog Changed in version 1.0.3: `RoutingException`, used internally for actions such as slash redirects during routing, is not passed to error handlers. Changed in version 1.0: Exceptions are looked up by code *and* by MRO, so `HTTPException` subclasses can be handled with a catch-all handler for the base `HTTPException`. New in version 0.3. Parameters **e** ([werkzeug.exceptions.HTTPException](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.HTTPException "(in Werkzeug v2.2.x)")) – Return type [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[werkzeug.exceptions.HTTPException](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.HTTPException "(in Werkzeug v2.2.x)"), [Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[Headers, [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]], [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]]]]], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[Headers, [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]], [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]]]]], WSGIApplication] `handle_url_build_error(error, endpoint, values)` Called by [`url_for()`](#flask.Flask.url_for "flask.Flask.url_for") if a `BuildError` was raised. If this returns a value, it will be returned by `url_for`, otherwise the error will be re-raised. Each function in [`url_build_error_handlers`](#flask.Flask.url_build_error_handlers "flask.Flask.url_build_error_handlers") is called with `error`, `endpoint` and `values`. If a function returns `None` or raises a `BuildError`, it is skipped. Otherwise, its return value is returned by `url_for`. Parameters * **error** (*werkzeug.routing.exceptions.BuildError*) – The active `BuildError` being handled. * **endpoint** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – The endpoint being built. * **values** ([Dict](https://docs.python.org/3/library/typing.html#typing.Dict "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]*) – The keyword arguments passed to `url_for`. Return type [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") `handle_user_exception(e)` This method is called whenever an exception occurs that should be handled. A special case is `HTTPException` which is forwarded to the [`handle_http_exception()`](#flask.Flask.handle_http_exception "flask.Flask.handle_http_exception") method. This function will either return a response value or reraise the exception with the same traceback. Changelog Changed in version 1.0: Key errors raised from request data like `form` show the bad key in debug mode rather than a generic bad request message. New in version 0.7. Parameters **e** ([Exception](https://docs.python.org/3/library/exceptions.html#Exception "(in Python v3.10)")) – Return type [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[werkzeug.exceptions.HTTPException](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.HTTPException "(in Werkzeug v2.2.x)"), [Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[Headers, [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]], [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]]]]], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[Headers, [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]], [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]]]]], WSGIApplication] `property has_static_folder: bool` `True` if [`static_folder`](#flask.Flask.static_folder "flask.Flask.static_folder") is set. Changelog New in version 0.5. `import_name` The name of the package or module that this object belongs to. Do not change this once it is set by the constructor. `inject_url_defaults(endpoint, values)` Injects the URL defaults for the given endpoint directly into the values dictionary passed. This is used internally and automatically called on URL building. Changelog New in version 0.7. Parameters * **endpoint** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – * **values** ([dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.10)")) – Return type None `instance_path` Holds the path to the instance folder. Changelog New in version 0.8. `iter_blueprints()` Iterates over all blueprints by the order they were registered. Changelog New in version 0.11. Return type [ValuesView](https://docs.python.org/3/library/typing.html#typing.ValuesView "(in Python v3.10)")[[Blueprint](#flask.Blueprint "flask.Blueprint")] `property jinja_env: flask.templating.Environment` The Jinja environment used to load templates. The environment is created the first time this property is accessed. Changing [`jinja_options`](#flask.Flask.jinja_options "flask.Flask.jinja_options") after that will have no effect. `jinja_environment` alias of `flask.templating.Environment` `property jinja_loader: Optional[jinja2.loaders.FileSystemLoader]` The Jinja loader for this object’s templates. By default this is a class [`jinja2.loaders.FileSystemLoader`](https://jinja.palletsprojects.com/en/3.1.x/api/#jinja2.FileSystemLoader "(in Jinja v3.1.x)") to [`template_folder`](#flask.Flask.template_folder "flask.Flask.template_folder") if it is set. Changelog New in version 0.5. `jinja_options: dict = {}` Options that are passed to the Jinja environment in [`create_jinja_environment()`](#flask.Flask.create_jinja_environment "flask.Flask.create_jinja_environment"). Changing these options after the environment is created (accessing [`jinja_env`](#flask.Flask.jinja_env "flask.Flask.jinja_env")) will have no effect. Changelog Changed in version 1.1.0: This is a `dict` instead of an `ImmutableDict` to allow easier configuration. `json: JSONProvider` Provides access to JSON methods. Functions in `flask.json` will call methods on this provider when the application context is active. Used for handling JSON requests and responses. An instance of [`json_provider_class`](#flask.Flask.json_provider_class "flask.Flask.json_provider_class"). Can be customized by changing that attribute on a subclass, or by assigning to this attribute afterwards. The default, [`DefaultJSONProvider`](#flask.json.provider.DefaultJSONProvider "flask.json.provider.DefaultJSONProvider"), uses Python’s built-in [`json`](https://docs.python.org/3/library/json.html#module-json "(in Python v3.10)") library. A different provider can use a different JSON library. New in version 2.2. `property json_decoder: Type[json.decoder.JSONDecoder]` The JSON decoder class to use. Defaults to [`JSONDecoder`](#flask.json.JSONDecoder "flask.json.JSONDecoder"). Deprecated since version 2.2: Will be removed in Flask 2.3. Customize [`json_provider_class`](#flask.Flask.json_provider_class "flask.Flask.json_provider_class") instead. Changelog New in version 0.10. `property json_encoder: Type[json.encoder.JSONEncoder]` The JSON encoder class to use. Defaults to [`JSONEncoder`](#flask.json.JSONEncoder "flask.json.JSONEncoder"). Deprecated since version 2.2: Will be removed in Flask 2.3. Customize [`json_provider_class`](#flask.Flask.json_provider_class "flask.Flask.json_provider_class") instead. Changelog New in version 0.10. `json_provider_class` alias of [`flask.json.provider.DefaultJSONProvider`](#flask.json.provider.DefaultJSONProvider "flask.json.provider.DefaultJSONProvider") `log_exception(exc_info)` Logs an exception. This is called by [`handle_exception()`](#flask.Flask.handle_exception "flask.Flask.handle_exception") if debugging is disabled and right before the handler is called. The default implementation logs the exception as error on the [`logger`](#flask.Flask.logger "flask.Flask.logger"). Changelog New in version 0.8. Parameters **exc\_info** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[type](https://docs.python.org/3/library/functions.html#type "(in Python v3.10)")*,* [BaseException](https://docs.python.org/3/library/exceptions.html#BaseException "(in Python v3.10)")*,* [types.TracebackType](https://docs.python.org/3/library/types.html#types.TracebackType "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[**None**,* *None**,* *None**]**]*) – Return type None `property logger: logging.Logger` A standard Python [`Logger`](https://docs.python.org/3/library/logging.html#logging.Logger "(in Python v3.10)") for the app, with the same name as [`name`](#flask.Flask.name "flask.Flask.name"). In debug mode, the logger’s `level` will be set to `DEBUG`. If there are no handlers configured, a default handler will be added. See [Logging](../logging/index) for more information. Changelog Changed in version 1.1.0: The logger takes the same name as [`name`](#flask.Flask.name "flask.Flask.name") rather than hard-coding `"flask.app"`. Changed in version 1.0.0: Behavior was simplified. The logger is always named `"flask.app"`. The level is only set during configuration, it doesn’t check `app.debug` each time. Only one format is used, not different ones depending on `app.debug`. No handlers are removed, and a handler is only added if no handlers are already configured. New in version 0.3. `make_aborter()` Create the object to assign to [`aborter`](#flask.Flask.aborter "flask.Flask.aborter"). That object is called by [`flask.abort()`](#flask.abort "flask.abort") to raise HTTP errors, and can be called directly as well. By default, this creates an instance of [`aborter_class`](#flask.Flask.aborter_class "flask.Flask.aborter_class"), which defaults to [`werkzeug.exceptions.Aborter`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.Aborter "(in Werkzeug v2.2.x)"). New in version 2.2. Return type [werkzeug.exceptions.Aborter](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.Aborter "(in Werkzeug v2.2.x)") `make_config(instance_relative=False)` Used to create the config attribute by the Flask constructor. The `instance_relative` parameter is passed in from the constructor of Flask (there named `instance_relative_config`) and indicates if the config should be relative to the instance path or the root path of the application. Changelog New in version 0.8. Parameters **instance\_relative** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Return type [flask.config.Config](#flask.Config "flask.config.Config") `make_default_options_response()` This method is called to create the default `OPTIONS` response. This can be changed through subclassing to change the default behavior of `OPTIONS` responses. Changelog New in version 0.7. Return type [flask.wrappers.Response](#flask.Response "flask.wrappers.Response") `make_response(rv)` Convert the return value from a view function to an instance of [`response_class`](#flask.Flask.response_class "flask.Flask.response_class"). Parameters **rv** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[**Headers**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**,* [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")*[*[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**]**]**]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[**Headers**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**,* [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")*[*[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**]**]**]**,* *WSGIApplication**]*) – the return value from the view function. The view function must return a response. Returning `None`, or the view ending without returning, is not allowed. The following types are allowed for `view_rv`: `str` A response object is created with the string encoded to UTF-8 as the body. `bytes` A response object is created with the bytes as the body. `dict` A dictionary that will be jsonify’d before being returned. `list` A list that will be jsonify’d before being returned. `generator or iterator` A generator that returns `str` or `bytes` to be streamed as the response. `tuple` Either `(body, status, headers)`, `(body, status)`, or `(body, headers)`, where `body` is any of the other types allowed here, `status` is a string or an integer, and `headers` is a dictionary or a list of `(key, value)` tuples. If `body` is a [`response_class`](#flask.Flask.response_class "flask.Flask.response_class") instance, `status` overwrites the exiting value and `headers` are extended. [`response_class`](#flask.Flask.response_class "flask.Flask.response_class") The object is returned unchanged. `other Response class` The object is coerced to [`response_class`](#flask.Flask.response_class "flask.Flask.response_class"). [`callable()`](https://docs.python.org/3/library/functions.html#callable "(in Python v3.10)") The function is called as a WSGI application. The result is used to create a response object. Return type [flask.wrappers.Response](#flask.Response "flask.wrappers.Response") Changed in version 2.2: A generator will be converted to a streaming response. A list will be converted to a JSON response. Changelog Changed in version 1.1: A dict will be converted to a JSON response. Changed in version 0.9: Previously a tuple was interpreted as the arguments for the response object. `make_shell_context()` Returns the shell context for an interactive shell for this application. This runs all the registered shell context processors. Changelog New in version 0.11. Return type [dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.10)") `property name: str` The name of the application. This is usually the import name with the difference that it’s guessed from the run file if the import name is main. This name is used as a display name when Flask needs the name of the application. It can be set and overridden to change the value. Changelog New in version 0.8. `open_instance_resource(resource, mode='rb')` Opens a resource from the application’s instance folder ([`instance_path`](#flask.Flask.instance_path "flask.Flask.instance_path")). Otherwise works like [`open_resource()`](#flask.Flask.open_resource "flask.Flask.open_resource"). Instance resources can also be opened for writing. Parameters * **resource** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – the name of the resource. To access resources within subfolders use forward slashes as separator. * **mode** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – resource file opening mode, default is ‘rb’. Return type [IO](https://docs.python.org/3/library/typing.html#typing.IO "(in Python v3.10)") `open_resource(resource, mode='rb')` Open a resource file relative to [`root_path`](#flask.Flask.root_path "flask.Flask.root_path") for reading. For example, if the file `schema.sql` is next to the file `app.py` where the `Flask` app is defined, it can be opened with: ``` with app.open_resource("schema.sql") as f: conn.executescript(f.read()) ``` Parameters * **resource** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – Path to the resource relative to [`root_path`](#flask.Flask.root_path "flask.Flask.root_path"). * **mode** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – Open the file in this mode. Only reading is supported, valid values are “r” (or “rt”) and “rb”. Return type [IO](https://docs.python.org/3/library/typing.html#typing.IO "(in Python v3.10)") `patch(rule, **options)` Shortcut for [`route()`](#flask.Flask.route "flask.Flask.route") with `methods=["PATCH"]`. Changelog New in version 2.0. Parameters * **rule** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.scaffold.T\_route], flask.scaffold.T\_route] `permanent_session_lifetime` A [`timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta "(in Python v3.10)") which is used to set the expiration date of a permanent session. The default is 31 days which makes a permanent session survive for roughly one month. This attribute can also be configured from the config with the `PERMANENT_SESSION_LIFETIME` configuration key. Defaults to `timedelta(days=31)` `post(rule, **options)` Shortcut for [`route()`](#flask.Flask.route "flask.Flask.route") with `methods=["POST"]`. Changelog New in version 2.0. Parameters * **rule** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.scaffold.T\_route], flask.scaffold.T\_route] `preprocess_request()` Called before the request is dispatched. Calls [`url_value_preprocessors`](#flask.Flask.url_value_preprocessors "flask.Flask.url_value_preprocessors") registered with the app and the current blueprint (if any). Then calls [`before_request_funcs`](#flask.Flask.before_request_funcs "flask.Flask.before_request_funcs") registered with the app and the blueprint. If any [`before_request()`](#flask.Flask.before_request "flask.Flask.before_request") handler returns a non-None value, the value is handled as if it was the return value from the view, and further request handling is stopped. Return type [Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[Headers, [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]], [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]]]]], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[Headers, [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]], [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]]]]], WSGIApplication]] `process_response(response)` Can be overridden in order to modify the response object before it’s sent to the WSGI server. By default this will call all the [`after_request()`](#flask.Flask.after_request "flask.Flask.after_request") decorated functions. Changelog Changed in version 0.5: As of Flask 0.5 the functions registered for after request execution are called in reverse order of registration. Parameters **response** ([flask.wrappers.Response](#flask.Response "flask.wrappers.Response")) – a [`response_class`](#flask.Flask.response_class "flask.Flask.response_class") object. Returns a new response object or the same, has to be an instance of [`response_class`](#flask.Flask.response_class "flask.Flask.response_class"). Return type [flask.wrappers.Response](#flask.Response "flask.wrappers.Response") `property propagate_exceptions: bool` Returns the value of the `PROPAGATE_EXCEPTIONS` configuration value in case it’s set, otherwise a sensible default is returned. Deprecated since version 2.2: Will be removed in Flask 2.3. Changelog New in version 0.7. `put(rule, **options)` Shortcut for [`route()`](#flask.Flask.route "flask.Flask.route") with `methods=["PUT"]`. Changelog New in version 2.0. Parameters * **rule** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.scaffold.T\_route], flask.scaffold.T\_route] `redirect(location, code=302)` Create a redirect response object. This is called by [`flask.redirect()`](#flask.redirect "flask.redirect"), and can be called directly as well. Parameters * **location** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – The URL to redirect to. * **code** ([int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")) – The status code for the redirect. Return type [werkzeug.wrappers.response.Response](https://werkzeug.palletsprojects.com/en/2.2.x/wrappers/#werkzeug.wrappers.Response "(in Werkzeug v2.2.x)") New in version 2.2: Moved from `flask.redirect`, which calls this method. `register_blueprint(blueprint, **options)` Register a [`Blueprint`](#flask.Blueprint "flask.Blueprint") on the application. Keyword arguments passed to this method will override the defaults set on the blueprint. Calls the blueprint’s [`register()`](#flask.Blueprint.register "flask.Blueprint.register") method after recording the blueprint in the application’s [`blueprints`](#flask.Flask.blueprints "flask.Flask.blueprints"). Parameters * **blueprint** ([Blueprint](#flask.Blueprint "flask.Blueprint")) – The blueprint to register. * **url\_prefix** – Blueprint routes will be prefixed with this. * **subdomain** – Blueprint routes will match on this subdomain. * **url\_defaults** – Blueprint routes will use these default values for view arguments. * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Additional keyword arguments are passed to [`BlueprintSetupState`](#flask.blueprints.BlueprintSetupState "flask.blueprints.BlueprintSetupState"). They can be accessed in [`record()`](#flask.Blueprint.record "flask.Blueprint.record") callbacks. Return type None Changelog Changed in version 2.0.1: The `name` option can be used to change the (pre-dotted) name the blueprint is registered with. This allows the same blueprint to be registered multiple times with unique names for `url_for`. New in version 0.7. `register_error_handler(code_or_exception, f)` Alternative error attach function to the [`errorhandler()`](#flask.Flask.errorhandler "flask.Flask.errorhandler") decorator that is more straightforward to use for non decorator usage. Changelog New in version 0.7. Parameters * **code\_or\_exception** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Type](https://docs.python.org/3/library/typing.html#typing.Type "(in Python v3.10)")*[*[Exception](https://docs.python.org/3/library/exceptions.html#Exception "(in Python v3.10)")*]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*]*) – * **f** ([Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[**Headers**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**,* [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")*[*[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**]**]**]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[**Headers**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**,* [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")*[*[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**]**]**]**,* *WSGIApplication**]**]*) – Return type None `request_class` alias of [`flask.wrappers.Request`](#flask.Request "flask.wrappers.Request") `request_context(environ)` Create a [`RequestContext`](#flask.ctx.RequestContext "flask.ctx.RequestContext") representing a WSGI environment. Use a `with` block to push the context, which will make [`request`](#flask.request "flask.request") point at this request. See [The Request Context](../reqcontext/index). Typically you should not call this from your own code. A request context is automatically pushed by the [`wsgi_app()`](#flask.Flask.wsgi_app "flask.Flask.wsgi_app") when handling a request. Use [`test_request_context()`](#flask.Flask.test_request_context "flask.Flask.test_request_context") to create an environment and context instead of this method. Parameters **environ** ([dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.10)")) – a WSGI environment Return type [flask.ctx.RequestContext](#flask.ctx.RequestContext "flask.ctx.RequestContext") `response_class` alias of [`flask.wrappers.Response`](#flask.Response "flask.wrappers.Response") `root_path` Absolute path to the package on the filesystem. Used to look up resources contained in the package. `route(rule, **options)` Decorate a view function to register it with the given URL rule and options. Calls [`add_url_rule()`](#flask.Flask.add_url_rule "flask.Flask.add_url_rule"), which has more details about the implementation. ``` @app.route("/") def index(): return "Hello, World!" ``` See [URL Route Registrations](#url-route-registrations). The endpoint name for the route defaults to the name of the view function if the `endpoint` parameter isn’t passed. The `methods` parameter defaults to `["GET"]`. `HEAD` and `OPTIONS` are added automatically. Parameters * **rule** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – The URL rule string. * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Extra options passed to the [`Rule`](https://werkzeug.palletsprojects.com/en/2.2.x/routing/#werkzeug.routing.Rule "(in Werkzeug v2.2.x)") object. Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.scaffold.T\_route], flask.scaffold.T\_route] `run(host=None, port=None, debug=None, load_dotenv=True, **options)` Runs the application on a local development server. Do not use `run()` in a production setting. It is not intended to meet security and performance requirements for a production server. Instead, see [Deploying to Production](../deploying/index) for WSGI server recommendations. If the [`debug`](#flask.Flask.debug "flask.Flask.debug") flag is set the server will automatically reload for code changes and show a debugger in case an exception happened. If you want to run the application in debug mode, but disable the code execution on the interactive debugger, you can pass `use_evalex=False` as parameter. This will keep the debugger’s traceback screen active, but disable code execution. It is not recommended to use this function for development with automatic reloading as this is badly supported. Instead you should be using the **flask** command line script’s `run` support. Keep in Mind Flask will suppress any server error with a generic error page unless it is in debug mode. As such to enable just the interactive debugger without the code reloading, you have to invoke [`run()`](#flask.Flask.run "flask.Flask.run") with `debug=True` and `use_reloader=False`. Setting `use_debugger` to `True` without being in debug mode won’t catch any exceptions because there won’t be any to catch. Parameters * **host** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – the hostname to listen on. Set this to `'0.0.0.0'` to have the server available externally as well. Defaults to `'127.0.0.1'` or the host in the `SERVER_NAME` config variable if present. * **port** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*]*) – the port of the webserver. Defaults to `5000` or the port defined in the `SERVER_NAME` config variable if present. * **debug** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")*]*) – if given, enable or disable debug mode. See [`debug`](#flask.Flask.debug "flask.Flask.debug"). * **load\_dotenv** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Load the nearest `.env` and `.flaskenv` files to set environment variables. Will also change the working directory to the directory containing the first file found. * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – the options to be forwarded to the underlying Werkzeug server. See [`werkzeug.serving.run_simple()`](https://werkzeug.palletsprojects.com/en/2.2.x/serving/#werkzeug.serving.run_simple "(in Werkzeug v2.2.x)") for more information. Return type None Changelog Changed in version 1.0: If installed, python-dotenv will be used to load environment variables from `.env` and `.flaskenv` files. The `FLASK_DEBUG` environment variable will override [`debug`](#flask.Flask.debug "flask.Flask.debug"). Threaded mode is enabled by default. Changed in version 0.10: The default port is now picked from the `SERVER_NAME` variable. `secret_key` If a secret key is set, cryptographic components can use this to sign cookies and other things. Set this to a complex random value when you want to use the secure cookie for instance. This attribute can also be configured from the config with the [`SECRET_KEY`](../config/index#SECRET_KEY "SECRET_KEY") configuration key. Defaults to `None`. `select_jinja_autoescape(filename)` Returns `True` if autoescaping should be active for the given template name. If no template name is given, returns `True`. Changelog New in version 0.5. Parameters **filename** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – Return type [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)") `property send_file_max_age_default: Optional[datetime.timedelta]` The default value for `max_age` for [`send_file()`](#flask.send_file "flask.send_file"). The default is `None`, which tells the browser to use conditional requests instead of a timed cache. Deprecated since version 2.2: Will be removed in Flask 2.3. Use `app.config["SEND_FILE_MAX_AGE_DEFAULT"]` instead. Changelog Changed in version 2.0: Defaults to `None` instead of 12 hours. `send_static_file(filename)` The view function used to serve files from [`static_folder`](#flask.Flask.static_folder "flask.Flask.static_folder"). A route is automatically registered for this view at [`static_url_path`](#flask.Flask.static_url_path "flask.Flask.static_url_path") if [`static_folder`](#flask.Flask.static_folder "flask.Flask.static_folder") is set. Changelog New in version 0.5. Parameters **filename** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – Return type [Response](#flask.Response "flask.Response") `property session_cookie_name: str` The name of the cookie set by the session interface. Deprecated since version 2.2: Will be removed in Flask 2.3. Use `app.config["SESSION_COOKIE_NAME"]` instead. `session_interface: flask.sessions.SessionInterface = <flask.sessions.SecureCookieSessionInterface object>` the session interface to use. By default an instance of [`SecureCookieSessionInterface`](#flask.sessions.SecureCookieSessionInterface "flask.sessions.SecureCookieSessionInterface") is used here. Changelog New in version 0.8. `shell_context_processor(f)` Registers a shell context processor function. Changelog New in version 0.11. Parameters **f** (*flask.app.T\_shell\_context\_processor*) – Return type flask.app.T\_shell\_context\_processor `shell_context_processors: t.List[ft.ShellContextProcessorCallable]` A list of shell context processor functions that should be run when a shell context is created. Changelog New in version 0.11. `should_ignore_error(error)` This is called to figure out if an error should be ignored or not as far as the teardown system is concerned. If this function returns `True` then the teardown handlers will not be passed the error. Changelog New in version 0.10. Parameters **error** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[BaseException](https://docs.python.org/3/library/exceptions.html#BaseException "(in Python v3.10)")*]*) – Return type [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)") `property static_folder: Optional[str]` The absolute path to the configured static folder. `None` if no static folder is set. `property static_url_path: Optional[str]` The URL prefix that the static route will be accessible from. If it was not configured during init, it is derived from [`static_folder`](#flask.Flask.static_folder "flask.Flask.static_folder"). `teardown_appcontext(f)` Registers a function to be called when the application context is popped. The application context is typically popped after the request context for each request, at the end of CLI commands, or after a manually pushed context ends. ``` with app.app_context(): ... ``` When the `with` block exits (or `ctx.pop()` is called), the teardown functions are called just before the app context is made inactive. Since a request context typically also manages an application context it would also be called when you pop a request context. When a teardown function was called because of an unhandled exception it will be passed an error object. If an [`errorhandler()`](#flask.Flask.errorhandler "flask.Flask.errorhandler") is registered, it will handle the exception and the teardown will not receive it. Teardown functions must avoid raising exceptions. If they execute code that might fail they must surround that code with a `try`/`except` block and log any errors. The return values of teardown functions are ignored. Changelog New in version 0.9. Parameters **f** (*flask.app.T\_teardown*) – Return type flask.app.T\_teardown `teardown_appcontext_funcs: t.List[ft.TeardownCallable]` A list of functions that are called when the application context is destroyed. Since the application context is also torn down if the request ends this is the place to store code that disconnects from databases. Changelog New in version 0.9. `teardown_request(f)` Register a function to be called when the request context is popped. Typically this happens at the end of each request, but contexts may be pushed manually as well during testing. ``` with app.test_request_context(): ... ``` When the `with` block exits (or `ctx.pop()` is called), the teardown functions are called just before the request context is made inactive. When a teardown function was called because of an unhandled exception it will be passed an error object. If an [`errorhandler()`](#flask.Flask.errorhandler "flask.Flask.errorhandler") is registered, it will handle the exception and the teardown will not receive it. Teardown functions must avoid raising exceptions. If they execute code that might fail they must surround that code with a `try`/`except` block and log any errors. The return values of teardown functions are ignored. Parameters **f** (*flask.scaffold.T\_teardown*) – Return type flask.scaffold.T\_teardown `teardown_request_funcs: t.Dict[ft.AppOrBlueprintKey, t.List[ft.TeardownCallable]]` A data structure of functions to call at the end of each request even if an exception is raised, in the format `{scope: [functions]}`. The `scope` key is the name of a blueprint the functions are active for, or `None` for all requests. To register a function, use the [`teardown_request()`](#flask.Flask.teardown_request "flask.Flask.teardown_request") decorator. This data structure is internal. It should not be modified directly and its format may change at any time. `template_context_processors: t.Dict[ft.AppOrBlueprintKey, t.List[ft.TemplateContextProcessorCallable]]` A data structure of functions to call to pass extra context values when rendering templates, in the format `{scope: [functions]}`. The `scope` key is the name of a blueprint the functions are active for, or `None` for all requests. To register a function, use the [`context_processor()`](#flask.Flask.context_processor "flask.Flask.context_processor") decorator. This data structure is internal. It should not be modified directly and its format may change at any time. `template_filter(name=None)` A decorator that is used to register custom template filter. You can specify a name for the filter, otherwise the function name will be used. Example: ``` @app.template_filter() def reverse(s): return s[::-1] ``` Parameters **name** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – the optional name of the filter, otherwise the function name will be used. Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.app.T\_template\_filter], flask.app.T\_template\_filter] `template_folder` The path to the templates folder, relative to [`root_path`](#flask.Flask.root_path "flask.Flask.root_path"), to add to the template loader. `None` if templates should not be added. `template_global(name=None)` A decorator that is used to register a custom template global function. You can specify a name for the global function, otherwise the function name will be used. Example: ``` @app.template_global() def double(n): return 2 * n ``` Changelog New in version 0.10. Parameters **name** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – the optional name of the global function, otherwise the function name will be used. Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.app.T\_template\_global], flask.app.T\_template\_global] `template_test(name=None)` A decorator that is used to register custom template test. You can specify a name for the test, otherwise the function name will be used. Example: ``` @app.template_test() def is_prime(n): if n == 2: return True for i in range(2, int(math.ceil(math.sqrt(n))) + 1): if n % i == 0: return False return True ``` Changelog New in version 0.10. Parameters **name** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – the optional name of the test, otherwise the function name will be used. Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.app.T\_template\_test], flask.app.T\_template\_test] `property templates_auto_reload: bool` Reload templates when they are changed. Used by [`create_jinja_environment()`](#flask.Flask.create_jinja_environment "flask.Flask.create_jinja_environment"). It is enabled by default in debug mode. Deprecated since version 2.2: Will be removed in Flask 2.3. Use `app.config["TEMPLATES_AUTO_RELOAD"]` instead. Changelog New in version 1.0: This property was added but the underlying config and behavior already existed. `test_cli_runner(**kwargs)` Create a CLI runner for testing CLI commands. See [Running Commands with the CLI Runner](../testing/index#testing-cli). Returns an instance of [`test_cli_runner_class`](#flask.Flask.test_cli_runner_class "flask.Flask.test_cli_runner_class"), by default [`FlaskCliRunner`](#flask.testing.FlaskCliRunner "flask.testing.FlaskCliRunner"). The Flask app object is passed as the first argument. Changelog New in version 1.0. Parameters **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [FlaskCliRunner](#flask.testing.FlaskCliRunner "flask.testing.FlaskCliRunner") `test_cli_runner_class: Optional[Type[FlaskCliRunner]] = None` The [`CliRunner`](https://click.palletsprojects.com/en/8.1.x/api/#click.testing.CliRunner "(in Click v8.1.x)") subclass, by default [`FlaskCliRunner`](#flask.testing.FlaskCliRunner "flask.testing.FlaskCliRunner") that is used by [`test_cli_runner()`](#flask.Flask.test_cli_runner "flask.Flask.test_cli_runner"). Its `__init__` method should take a Flask app object as the first argument. Changelog New in version 1.0. `test_client(use_cookies=True, **kwargs)` Creates a test client for this application. For information about unit testing head over to [Testing Flask Applications](../testing/index). Note that if you are testing for assertions or exceptions in your application code, you must set `app.testing = True` in order for the exceptions to propagate to the test client. Otherwise, the exception will be handled by the application (not visible to the test client) and the only indication of an AssertionError or other exception will be a 500 status code response to the test client. See the [`testing`](#flask.Flask.testing "flask.Flask.testing") attribute. For example: ``` app.testing = True client = app.test_client() ``` The test client can be used in a `with` block to defer the closing down of the context until the end of the `with` block. This is useful if you want to access the context locals for testing: ``` with app.test_client() as c: rv = c.get('/?vodka=42') assert request.args['vodka'] == '42' ``` Additionally, you may pass optional keyword arguments that will then be passed to the application’s [`test_client_class`](#flask.Flask.test_client_class "flask.Flask.test_client_class") constructor. For example: ``` from flask.testing import FlaskClient class CustomClient(FlaskClient): def __init__(self, *args, **kwargs): self._authentication = kwargs.pop("authentication") super(CustomClient,self).__init__( *args, **kwargs) app.test_client_class = CustomClient client = app.test_client(authentication='Basic ....') ``` See [`FlaskClient`](#flask.testing.FlaskClient "flask.testing.FlaskClient") for more information. Changelog Changed in version 0.11: Added `**kwargs` to support passing additional keyword arguments to the constructor of [`test_client_class`](#flask.Flask.test_client_class "flask.Flask.test_client_class"). New in version 0.7: The `use_cookies` parameter was added as well as the ability to override the client to be used by setting the [`test_client_class`](#flask.Flask.test_client_class "flask.Flask.test_client_class") attribute. Changed in version 0.4: added support for `with` block usage for the client. Parameters * **use\_cookies** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [FlaskClient](#flask.testing.FlaskClient "flask.testing.FlaskClient") `test_client_class: Optional[Type[FlaskClient]] = None` The [`test_client()`](#flask.Flask.test_client "flask.Flask.test_client") method creates an instance of this test client class. Defaults to [`FlaskClient`](#flask.testing.FlaskClient "flask.testing.FlaskClient"). Changelog New in version 0.7. `test_request_context(*args, **kwargs)` Create a [`RequestContext`](#flask.ctx.RequestContext "flask.ctx.RequestContext") for a WSGI environment created from the given values. This is mostly useful during testing, where you may want to run a function that uses request data without dispatching a full request. See [The Request Context](../reqcontext/index). Use a `with` block to push the context, which will make [`request`](#flask.request "flask.request") point at the request for the created environment. ``` with test_request_context(...): generate_report() ``` When using the shell, it may be easier to push and pop the context manually to avoid indentation. ``` ctx = app.test_request_context(...) ctx.push() ... ctx.pop() ``` Takes the same arguments as Werkzeug’s [`EnvironBuilder`](https://werkzeug.palletsprojects.com/en/2.2.x/test/#werkzeug.test.EnvironBuilder "(in Werkzeug v2.2.x)"), with some defaults from the application. See the linked Werkzeug docs for most of the available arguments. Flask-specific behavior is listed here. Parameters * **path** – URL path being requested. * **base\_url** – Base URL where the app is being served, which `path` is relative to. If not given, built from [`PREFERRED_URL_SCHEME`](../config/index#PREFERRED_URL_SCHEME "PREFERRED_URL_SCHEME"), `subdomain`, [`SERVER_NAME`](../config/index#SERVER_NAME "SERVER_NAME"), and [`APPLICATION_ROOT`](../config/index#APPLICATION_ROOT "APPLICATION_ROOT"). * **subdomain** – Subdomain name to append to [`SERVER_NAME`](../config/index#SERVER_NAME "SERVER_NAME"). * **url\_scheme** – Scheme to use instead of [`PREFERRED_URL_SCHEME`](../config/index#PREFERRED_URL_SCHEME "PREFERRED_URL_SCHEME"). * **data** – The request body, either as a string or a dict of form keys and values. * **json** – If given, this is serialized as JSON and passed as `data`. Also defaults `content_type` to `application/json`. * **args** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – other positional arguments passed to [`EnvironBuilder`](https://werkzeug.palletsprojects.com/en/2.2.x/test/#werkzeug.test.EnvironBuilder "(in Werkzeug v2.2.x)"). * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – other keyword arguments passed to [`EnvironBuilder`](https://werkzeug.palletsprojects.com/en/2.2.x/test/#werkzeug.test.EnvironBuilder "(in Werkzeug v2.2.x)"). Return type [flask.ctx.RequestContext](#flask.ctx.RequestContext "flask.ctx.RequestContext") `testing` The testing flag. Set this to `True` to enable the test mode of Flask extensions (and in the future probably also Flask itself). For example this might activate test helpers that have an additional runtime cost which should not be enabled by default. If this is enabled and PROPAGATE\_EXCEPTIONS is not changed from the default it’s implicitly enabled. This attribute can also be configured from the config with the `TESTING` configuration key. Defaults to `False`. `trap_http_exception(e)` Checks if an HTTP exception should be trapped or not. By default this will return `False` for all exceptions except for a bad request key error if `TRAP_BAD_REQUEST_ERRORS` is set to `True`. It also returns `True` if `TRAP_HTTP_EXCEPTIONS` is set to `True`. This is called for all HTTP exceptions raised by a view function. If it returns `True` for any exception the error handler for this exception is not called and it shows up as regular exception in the traceback. This is helpful for debugging implicitly raised HTTP exceptions. Changelog Changed in version 1.0: Bad request errors are not trapped by default in debug mode. New in version 0.8. Parameters **e** ([Exception](https://docs.python.org/3/library/exceptions.html#Exception "(in Python v3.10)")) – Return type [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)") `update_template_context(context)` Update the template context with some commonly used variables. This injects request, session, config and g into the template context as well as everything template context processors want to inject. Note that the as of Flask 0.6, the original values in the context will not be overridden if a context processor decides to return a value with the same key. Parameters **context** ([dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.10)")) – the context as a dictionary that is updated in place to add extra variables. Return type None `url_build_error_handlers: t.List[t.Callable[[Exception, str, t.Dict[str, t.Any]], str]]` A list of functions that are called by [`handle_url_build_error()`](#flask.Flask.handle_url_build_error "flask.Flask.handle_url_build_error") when [`url_for()`](#flask.Flask.url_for "flask.Flask.url_for") raises a `BuildError`. Each function is called with `error`, `endpoint` and `values`. If a function returns `None` or raises a `BuildError`, it is skipped. Otherwise, its return value is returned by `url_for`. Changelog New in version 0.9. `url_default_functions: t.Dict[ft.AppOrBlueprintKey, t.List[ft.URLDefaultCallable]]` A data structure of functions to call to modify the keyword arguments when generating URLs, in the format `{scope: [functions]}`. The `scope` key is the name of a blueprint the functions are active for, or `None` for all requests. To register a function, use the [`url_defaults()`](#flask.Flask.url_defaults "flask.Flask.url_defaults") decorator. This data structure is internal. It should not be modified directly and its format may change at any time. `url_defaults(f)` Callback function for URL defaults for all view functions of the application. It’s called with the endpoint and values and should update the values passed in place. Parameters **f** (*flask.scaffold.T\_url\_defaults*) – Return type flask.scaffold.T\_url\_defaults `url_for(endpoint, *, _anchor=None, _method=None, _scheme=None, _external=None, **values)` Generate a URL to the given endpoint with the given values. This is called by [`flask.url_for()`](#flask.url_for "flask.url_for"), and can be called directly as well. An *endpoint* is the name of a URL rule, usually added with [`@app.route()`](#flask.Flask.route "flask.Flask.route"), and usually the same name as the view function. A route defined in a [`Blueprint`](#flask.Blueprint "flask.Blueprint") will prepend the blueprint’s name separated by a `.` to the endpoint. In some cases, such as email messages, you want URLs to include the scheme and domain, like `https://example.com/hello`. When not in an active request, URLs will be external by default, but this requires setting [`SERVER_NAME`](../config/index#SERVER_NAME "SERVER_NAME") so Flask knows what domain to use. [`APPLICATION_ROOT`](../config/index#APPLICATION_ROOT "APPLICATION_ROOT") and [`PREFERRED_URL_SCHEME`](../config/index#PREFERRED_URL_SCHEME "PREFERRED_URL_SCHEME") should also be configured as needed. This config is only used when not in an active request. Functions can be decorated with [`url_defaults()`](#flask.Flask.url_defaults "flask.Flask.url_defaults") to modify keyword arguments before the URL is built. If building fails for some reason, such as an unknown endpoint or incorrect values, the app’s [`handle_url_build_error()`](#flask.Flask.handle_url_build_error "flask.Flask.handle_url_build_error") method is called. If that returns a string, that is returned, otherwise a `BuildError` is raised. Parameters * **endpoint** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – The endpoint name associated with the URL to generate. If this starts with a `.`, the current blueprint name (if any) will be used. * **\_anchor** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – If given, append this as `#anchor` to the URL. * **\_method** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – If given, generate the URL associated with this method for the endpoint. * **\_scheme** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – If given, the URL will have this scheme if it is external. * **\_external** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")*]*) – If given, prefer the URL to be internal (False) or require it to be external (True). External URLs include the scheme and domain. When not in an active request, URLs are external by default. * **values** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Values to use for the variable parts of the URL rule. Unknown keys are appended as query string arguments, like `?a=b&c=d`. Return type [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") New in version 2.2: Moved from `flask.url_for`, which calls this method. `url_map` The [`Map`](https://werkzeug.palletsprojects.com/en/2.2.x/routing/#werkzeug.routing.Map "(in Werkzeug v2.2.x)") for this instance. You can use this to change the routing converters after the class was created but before any routes are connected. Example: ``` from werkzeug.routing import BaseConverter class ListConverter(BaseConverter): def to_python(self, value): return value.split(',') def to_url(self, values): return ','.join(super(ListConverter, self).to_url(value) for value in values) app = Flask(__name__) app.url_map.converters['list'] = ListConverter ``` `url_map_class` alias of [`werkzeug.routing.map.Map`](https://werkzeug.palletsprojects.com/en/2.2.x/routing/#werkzeug.routing.Map "(in Werkzeug v2.2.x)") `url_rule_class` alias of [`werkzeug.routing.rules.Rule`](https://werkzeug.palletsprojects.com/en/2.2.x/routing/#werkzeug.routing.Rule "(in Werkzeug v2.2.x)") `url_value_preprocessor(f)` Register a URL value preprocessor function for all view functions in the application. These functions will be called before the [`before_request()`](#flask.Flask.before_request "flask.Flask.before_request") functions. The function can modify the values captured from the matched url before they are passed to the view. For example, this can be used to pop a common language code value and place it in `g` rather than pass it to every view. The function is passed the endpoint name and values dict. The return value is ignored. Parameters **f** (*flask.scaffold.T\_url\_value\_preprocessor*) – Return type flask.scaffold.T\_url\_value\_preprocessor `url_value_preprocessors: t.Dict[ft.AppOrBlueprintKey, t.List[ft.URLValuePreprocessorCallable]]` A data structure of functions to call to modify the keyword arguments passed to the view function, in the format `{scope: [functions]}`. The `scope` key is the name of a blueprint the functions are active for, or `None` for all requests. To register a function, use the [`url_value_preprocessor()`](#flask.Flask.url_value_preprocessor "flask.Flask.url_value_preprocessor") decorator. This data structure is internal. It should not be modified directly and its format may change at any time. `property use_x_sendfile: bool` Enable this to use the `X-Sendfile` feature, assuming the server supports it, from [`send_file()`](#flask.send_file "flask.send_file"). Deprecated since version 2.2: Will be removed in Flask 2.3. Use `app.config["USE_X_SENDFILE"]` instead. `view_functions: t.Dict[str, t.Callable]` A dictionary mapping endpoint names to view functions. To register a view function, use the [`route()`](#flask.Flask.route "flask.Flask.route") decorator. This data structure is internal. It should not be modified directly and its format may change at any time. `wsgi_app(environ, start_response)` The actual WSGI application. This is not implemented in `__call__()` so that middlewares can be applied without losing a reference to the app object. Instead of doing this: ``` app = MyMiddleware(app) ``` It’s a better idea to do this instead: ``` app.wsgi_app = MyMiddleware(app.wsgi_app) ``` Then you still have the original application object around and can continue to call methods on it. Changelog Changed in version 0.7: Teardown events for the request and app contexts are called even if an unhandled error occurs. Other events may not be called depending on when an error occurs during dispatch. See [Callbacks and Errors](../reqcontext/index#callbacks-and-errors). Parameters * **environ** ([dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.10)")) – A WSGI environment. * **start\_response** ([Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")) – A callable accepting a status code, a list of headers, and an optional exception context to start the response. Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") Blueprint Objects ----------------- `class flask.Blueprint(name, import_name, static_folder=None, static_url_path=None, template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, root_path=None, cli_group=<object object>)` Represents a blueprint, a collection of routes and other app-related functions that can be registered on a real application later. A blueprint is an object that allows defining application functions without requiring an application object ahead of time. It uses the same decorators as [`Flask`](#flask.Flask "flask.Flask"), but defers the need for an application by recording them for later registration. Decorating a function with a blueprint creates a deferred function that is called with [`BlueprintSetupState`](#flask.blueprints.BlueprintSetupState "flask.blueprints.BlueprintSetupState") when the blueprint is registered on an application. See [Modular Applications with Blueprints](../blueprints/index) for more information. Parameters * **name** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – The name of the blueprint. Will be prepended to each endpoint name. * **import\_name** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – The name of the blueprint package, usually `__name__`. This helps locate the `root_path` for the blueprint. * **static\_folder** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [os.PathLike](https://docs.python.org/3/library/os.html#os.PathLike "(in Python v3.10)")*]**]*) – A folder with static files that should be served by the blueprint’s static route. The path is relative to the blueprint’s root path. Blueprint static files are disabled by default. * **static\_url\_path** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – The url to serve static files from. Defaults to `static_folder`. If the blueprint does not have a `url_prefix`, the app’s static route will take precedence, and the blueprint’s static files won’t be accessible. * **template\_folder** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – A folder with templates that should be added to the app’s template search path. The path is relative to the blueprint’s root path. Blueprint templates are disabled by default. Blueprint templates have a lower precedence than those in the app’s templates folder. * **url\_prefix** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – A path to prepend to all of the blueprint’s URLs, to make them distinct from the rest of the app’s routes. * **subdomain** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – A subdomain that blueprint routes will match on by default. * **url\_defaults** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.10)")*]*) – A dict of default values that blueprint routes will receive by default. * **root\_path** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – By default, the blueprint will automatically set this based on `import_name`. In certain situations this automatic detection can fail, so the path can be specified manually instead. * **cli\_group** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – Changelog Changed in version 1.1.0: Blueprints have a `cli` group to register nested CLI commands. The `cli_group` parameter controls the name of the group under the `flask` command. New in version 0.7. `add_app_template_filter(f, name=None)` Register a custom template filter, available application wide. Like [`Flask.add_template_filter()`](#flask.Flask.add_template_filter "flask.Flask.add_template_filter") but for a blueprint. Works exactly like the [`app_template_filter()`](#flask.Blueprint.app_template_filter "flask.Blueprint.app_template_filter") decorator. Parameters * **name** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – the optional name of the filter, otherwise the function name will be used. * **f** ([Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[**...**]**,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]*) – Return type None `add_app_template_global(f, name=None)` Register a custom template global, available application wide. Like [`Flask.add_template_global()`](#flask.Flask.add_template_global "flask.Flask.add_template_global") but for a blueprint. Works exactly like the [`app_template_global()`](#flask.Blueprint.app_template_global "flask.Blueprint.app_template_global") decorator. Changelog New in version 0.10. Parameters * **name** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – the optional name of the global, otherwise the function name will be used. * **f** ([Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[**...**]**,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]*) – Return type None `add_app_template_test(f, name=None)` Register a custom template test, available application wide. Like [`Flask.add_template_test()`](#flask.Flask.add_template_test "flask.Flask.add_template_test") but for a blueprint. Works exactly like the [`app_template_test()`](#flask.Blueprint.app_template_test "flask.Blueprint.app_template_test") decorator. Changelog New in version 0.10. Parameters * **name** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – the optional name of the test, otherwise the function name will be used. * **f** ([Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[**...**]**,* [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")*]*) – Return type None `add_url_rule(rule, endpoint=None, view_func=None, provide_automatic_options=None, **options)` Like [`Flask.add_url_rule()`](#flask.Flask.add_url_rule "flask.Flask.add_url_rule") but for a blueprint. The endpoint for the [`url_for()`](#flask.url_for "flask.url_for") function is prefixed with the name of the blueprint. Parameters * **rule** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – * **endpoint** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – * **view\_func** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[**...**]**,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[**Headers**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**,* [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")*[*[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**]**]**]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[**Headers**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**,* [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")*[*[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**]**]**]**,* *WSGIApplication**]**]**,* [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[**...**]**,* [Awaitable](https://docs.python.org/3/library/typing.html#typing.Awaitable "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[**Headers**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**,* [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")*[*[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**]**]**]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[**Headers**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**,* [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")*[*[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**]**]**]**,* *WSGIApplication**]**]**]**]**]*) – * **provide\_automatic\_options** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")*]*) – * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type None `after_app_request(f)` Like [`Flask.after_request()`](#flask.Flask.after_request "flask.Flask.after_request") but for a blueprint. Such a function is executed after each request, even if outside of the blueprint. Parameters **f** (*flask.blueprints.T\_after\_request*) – Return type flask.blueprints.T\_after\_request `after_request(f)` Register a function to run after each request to this object. The function is called with the response object, and must return a response object. This allows the functions to modify or replace the response before it is sent. If a function raises an exception, any remaining `after_request` functions will not be called. Therefore, this should not be used for actions that must execute, such as to close resources. Use [`teardown_request()`](#flask.Blueprint.teardown_request "flask.Blueprint.teardown_request") for that. Parameters **f** (*flask.scaffold.T\_after\_request*) – Return type flask.scaffold.T\_after\_request `after_request_funcs: t.Dict[ft.AppOrBlueprintKey, t.List[ft.AfterRequestCallable]]` A data structure of functions to call at the end of each request, in the format `{scope: [functions]}`. The `scope` key is the name of a blueprint the functions are active for, or `None` for all requests. To register a function, use the [`after_request()`](#flask.Blueprint.after_request "flask.Blueprint.after_request") decorator. This data structure is internal. It should not be modified directly and its format may change at any time. `app_context_processor(f)` Like [`Flask.context_processor()`](#flask.Flask.context_processor "flask.Flask.context_processor") but for a blueprint. Such a function is executed each request, even if outside of the blueprint. Parameters **f** (*flask.blueprints.T\_template\_context\_processor*) – Return type flask.blueprints.T\_template\_context\_processor `app_errorhandler(code)` Like [`Flask.errorhandler()`](#flask.Flask.errorhandler "flask.Flask.errorhandler") but for a blueprint. This handler is used for all requests, even if outside of the blueprint. Parameters **code** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Type](https://docs.python.org/3/library/typing.html#typing.Type "(in Python v3.10)")*[*[Exception](https://docs.python.org/3/library/exceptions.html#Exception "(in Python v3.10)")*]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*]*) – Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.blueprints.T\_error\_handler], flask.blueprints.T\_error\_handler] `app_template_filter(name=None)` Register a custom template filter, available application wide. Like [`Flask.template_filter()`](#flask.Flask.template_filter "flask.Flask.template_filter") but for a blueprint. Parameters **name** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – the optional name of the filter, otherwise the function name will be used. Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.blueprints.T\_template\_filter], flask.blueprints.T\_template\_filter] `app_template_global(name=None)` Register a custom template global, available application wide. Like [`Flask.template_global()`](#flask.Flask.template_global "flask.Flask.template_global") but for a blueprint. Changelog New in version 0.10. Parameters **name** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – the optional name of the global, otherwise the function name will be used. Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.blueprints.T\_template\_global], flask.blueprints.T\_template\_global] `app_template_test(name=None)` Register a custom template test, available application wide. Like [`Flask.template_test()`](#flask.Flask.template_test "flask.Flask.template_test") but for a blueprint. Changelog New in version 0.10. Parameters **name** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – the optional name of the test, otherwise the function name will be used. Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.blueprints.T\_template\_test], flask.blueprints.T\_template\_test] `app_url_defaults(f)` Same as [`url_defaults()`](#flask.Blueprint.url_defaults "flask.Blueprint.url_defaults") but application wide. Parameters **f** (*flask.blueprints.T\_url\_defaults*) – Return type flask.blueprints.T\_url\_defaults `app_url_value_preprocessor(f)` Same as [`url_value_preprocessor()`](#flask.Blueprint.url_value_preprocessor "flask.Blueprint.url_value_preprocessor") but application wide. Parameters **f** (*flask.blueprints.T\_url\_value\_preprocessor*) – Return type flask.blueprints.T\_url\_value\_preprocessor `before_app_first_request(f)` Like [`Flask.before_first_request()`](#flask.Flask.before_first_request "flask.Flask.before_first_request"). Such a function is executed before the first request to the application. Deprecated since version 2.2: Will be removed in Flask 2.3. Run setup code when creating the application instead. Parameters **f** (*flask.blueprints.T\_before\_first\_request*) – Return type flask.blueprints.T\_before\_first\_request `before_app_request(f)` Like [`Flask.before_request()`](#flask.Flask.before_request "flask.Flask.before_request"). Such a function is executed before each request, even if outside of a blueprint. Parameters **f** (*flask.blueprints.T\_before\_request*) – Return type flask.blueprints.T\_before\_request `before_request(f)` Register a function to run before each request. For example, this can be used to open a database connection, or to load the logged in user from the session. ``` @app.before_request def load_user(): if "user_id" in session: g.user = db.session.get(session["user_id"]) ``` The function will be called without any arguments. If it returns a non-`None` value, the value is handled as if it was the return value from the view, and further request handling is stopped. Parameters **f** (*flask.scaffold.T\_before\_request*) – Return type flask.scaffold.T\_before\_request `before_request_funcs: t.Dict[ft.AppOrBlueprintKey, t.List[ft.BeforeRequestCallable]]` A data structure of functions to call at the beginning of each request, in the format `{scope: [functions]}`. The `scope` key is the name of a blueprint the functions are active for, or `None` for all requests. To register a function, use the [`before_request()`](#flask.Blueprint.before_request "flask.Blueprint.before_request") decorator. This data structure is internal. It should not be modified directly and its format may change at any time. `cli` The Click command group for registering CLI commands for this object. The commands are available from the `flask` command once the application has been discovered and blueprints have been registered. `context_processor(f)` Registers a template context processor function. Parameters **f** (*flask.scaffold.T\_template\_context\_processor*) – Return type flask.scaffold.T\_template\_context\_processor `delete(rule, **options)` Shortcut for [`route()`](#flask.Blueprint.route "flask.Blueprint.route") with `methods=["DELETE"]`. Changelog New in version 2.0. Parameters * **rule** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.scaffold.T\_route], flask.scaffold.T\_route] `endpoint(endpoint)` Decorate a view function to register it for the given endpoint. Used if a rule is added without a `view_func` with [`add_url_rule()`](#flask.Blueprint.add_url_rule "flask.Blueprint.add_url_rule"). ``` app.add_url_rule("/ex", endpoint="example") @app.endpoint("example") def example(): ... ``` Parameters **endpoint** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – The endpoint name to associate with the view function. Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.scaffold.F], flask.scaffold.F] `error_handler_spec: t.Dict[ft.AppOrBlueprintKey, t.Dict[t.Optional[int], t.Dict[t.Type[Exception], ft.ErrorHandlerCallable]]]` A data structure of registered error handlers, in the format `{scope: {code: {class: handler}}}`. The `scope` key is the name of a blueprint the handlers are active for, or `None` for all requests. The `code` key is the HTTP status code for `HTTPException`, or `None` for other exceptions. The innermost dictionary maps exception classes to handler functions. To register an error handler, use the [`errorhandler()`](#flask.Blueprint.errorhandler "flask.Blueprint.errorhandler") decorator. This data structure is internal. It should not be modified directly and its format may change at any time. `errorhandler(code_or_exception)` Register a function to handle errors by code or exception class. A decorator that is used to register a function given an error code. Example: ``` @app.errorhandler(404) def page_not_found(error): return 'This page does not exist', 404 ``` You can also register handlers for arbitrary exceptions: ``` @app.errorhandler(DatabaseError) def special_exception_handler(error): return 'Database connection failed', 500 ``` Changelog New in version 0.7: Use [`register_error_handler()`](#flask.Blueprint.register_error_handler "flask.Blueprint.register_error_handler") instead of modifying [`error_handler_spec`](#flask.Blueprint.error_handler_spec "flask.Blueprint.error_handler_spec") directly, for application wide error handlers. New in version 0.7: One can now additionally also register custom exception types that do not necessarily have to be a subclass of the [`HTTPException`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.HTTPException "(in Werkzeug v2.2.x)") class. Parameters **code\_or\_exception** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Type](https://docs.python.org/3/library/typing.html#typing.Type "(in Python v3.10)")*[*[Exception](https://docs.python.org/3/library/exceptions.html#Exception "(in Python v3.10)")*]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*]*) – the code as integer for the handler, or an arbitrary exception Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.scaffold.T\_error\_handler], flask.scaffold.T\_error\_handler] `get(rule, **options)` Shortcut for [`route()`](#flask.Blueprint.route "flask.Blueprint.route") with `methods=["GET"]`. Changelog New in version 2.0. Parameters * **rule** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.scaffold.T\_route], flask.scaffold.T\_route] `get_send_file_max_age(filename)` Used by [`send_file()`](#flask.send_file "flask.send_file") to determine the `max_age` cache value for a given file path if it wasn’t passed. By default, this returns [`SEND_FILE_MAX_AGE_DEFAULT`](../config/index#SEND_FILE_MAX_AGE_DEFAULT "SEND_FILE_MAX_AGE_DEFAULT") from the configuration of [`current_app`](#flask.current_app "flask.current_app"). This defaults to `None`, which tells the browser to use conditional requests instead of a timed cache, which is usually preferable. Changelog Changed in version 2.0: The default configuration is `None` instead of 12 hours. New in version 0.9. Parameters **filename** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – Return type [Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")[[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")] `property has_static_folder: bool` `True` if [`static_folder`](#flask.Blueprint.static_folder "flask.Blueprint.static_folder") is set. Changelog New in version 0.5. `import_name` The name of the package or module that this object belongs to. Do not change this once it is set by the constructor. `property jinja_loader: Optional[jinja2.loaders.FileSystemLoader]` The Jinja loader for this object’s templates. By default this is a class [`jinja2.loaders.FileSystemLoader`](https://jinja.palletsprojects.com/en/3.1.x/api/#jinja2.FileSystemLoader "(in Jinja v3.1.x)") to [`template_folder`](#flask.Blueprint.template_folder "flask.Blueprint.template_folder") if it is set. Changelog New in version 0.5. `property json_decoder: Optional[Type[json.decoder.JSONDecoder]]` Blueprint-local JSON decoder class to use. Set to `None` to use the app’s. Deprecated since version 2.2: Will be removed in Flask 2.3. Customize `json_provider_class` instead. Changelog New in version 0.10. `property json_encoder: Optional[Type[json.encoder.JSONEncoder]]` Blueprint-local JSON encoder class to use. Set to `None` to use the app’s. Deprecated since version 2.2: Will be removed in Flask 2.3. Customize `json_provider_class` instead. Changelog New in version 0.10. `make_setup_state(app, options, first_registration=False)` Creates an instance of [`BlueprintSetupState()`](#flask.blueprints.BlueprintSetupState "flask.blueprints.BlueprintSetupState") object that is later passed to the register callback functions. Subclasses can override this to return a subclass of the setup state. Parameters * **app** ([Flask](#flask.Flask "flask.Flask")) – * **options** ([dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.10)")) – * **first\_registration** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Return type [flask.blueprints.BlueprintSetupState](#flask.blueprints.BlueprintSetupState "flask.blueprints.BlueprintSetupState") `open_resource(resource, mode='rb')` Open a resource file relative to [`root_path`](#flask.Blueprint.root_path "flask.Blueprint.root_path") for reading. For example, if the file `schema.sql` is next to the file `app.py` where the `Flask` app is defined, it can be opened with: ``` with app.open_resource("schema.sql") as f: conn.executescript(f.read()) ``` Parameters * **resource** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – Path to the resource relative to [`root_path`](#flask.Blueprint.root_path "flask.Blueprint.root_path"). * **mode** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – Open the file in this mode. Only reading is supported, valid values are “r” (or “rt”) and “rb”. Return type [IO](https://docs.python.org/3/library/typing.html#typing.IO "(in Python v3.10)") `patch(rule, **options)` Shortcut for [`route()`](#flask.Blueprint.route "flask.Blueprint.route") with `methods=["PATCH"]`. Changelog New in version 2.0. Parameters * **rule** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.scaffold.T\_route], flask.scaffold.T\_route] `post(rule, **options)` Shortcut for [`route()`](#flask.Blueprint.route "flask.Blueprint.route") with `methods=["POST"]`. Changelog New in version 2.0. Parameters * **rule** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.scaffold.T\_route], flask.scaffold.T\_route] `put(rule, **options)` Shortcut for [`route()`](#flask.Blueprint.route "flask.Blueprint.route") with `methods=["PUT"]`. Changelog New in version 2.0. Parameters * **rule** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.scaffold.T\_route], flask.scaffold.T\_route] `record(func)` Registers a function that is called when the blueprint is registered on the application. This function is called with the state as argument as returned by the [`make_setup_state()`](#flask.Blueprint.make_setup_state "flask.Blueprint.make_setup_state") method. Parameters **func** ([Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")) – Return type None `record_once(func)` Works like [`record()`](#flask.Blueprint.record "flask.Blueprint.record") but wraps the function in another function that will ensure the function is only called once. If the blueprint is registered a second time on the application, the function passed is not called. Parameters **func** ([Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")) – Return type None `register(app, options)` Called by [`Flask.register_blueprint()`](#flask.Flask.register_blueprint "flask.Flask.register_blueprint") to register all views and callbacks registered on the blueprint with the application. Creates a [`BlueprintSetupState`](#flask.blueprints.BlueprintSetupState "flask.blueprints.BlueprintSetupState") and calls each [`record()`](#flask.Blueprint.record "flask.Blueprint.record") callback with it. Parameters * **app** ([Flask](#flask.Flask "flask.Flask")) – The application this blueprint is being registered with. * **options** ([dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.10)")) – Keyword arguments forwarded from [`register_blueprint()`](#flask.Flask.register_blueprint "flask.Flask.register_blueprint"). Return type None Changelog Changed in version 2.0.1: Nested blueprints are registered with their dotted name. This allows different blueprints with the same name to be nested at different locations. Changed in version 2.0.1: The `name` option can be used to change the (pre-dotted) name the blueprint is registered with. This allows the same blueprint to be registered multiple times with unique names for `url_for`. Changed in version 2.0.1: Registering the same blueprint with the same name multiple times is deprecated and will become an error in Flask 2.1. `register_blueprint(blueprint, **options)` Register a [`Blueprint`](#flask.Blueprint "flask.Blueprint") on this blueprint. Keyword arguments passed to this method will override the defaults set on the blueprint. Changelog Changed in version 2.0.1: The `name` option can be used to change the (pre-dotted) name the blueprint is registered with. This allows the same blueprint to be registered multiple times with unique names for `url_for`. New in version 2.0. Parameters * **blueprint** ([flask.blueprints.Blueprint](#flask.Blueprint "flask.blueprints.Blueprint")) – * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type None `register_error_handler(code_or_exception, f)` Alternative error attach function to the [`errorhandler()`](#flask.Blueprint.errorhandler "flask.Blueprint.errorhandler") decorator that is more straightforward to use for non decorator usage. Changelog New in version 0.7. Parameters * **code\_or\_exception** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Type](https://docs.python.org/3/library/typing.html#typing.Type "(in Python v3.10)")*[*[Exception](https://docs.python.org/3/library/exceptions.html#Exception "(in Python v3.10)")*]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*]*) – * **f** ([Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[**Headers**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**,* [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")*[*[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**]**]**]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Response](#flask.Response "flask.Response")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]**,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[**Headers**,* [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**,* [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")*[*[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* *...**]**]**]**]**]**]**,* *WSGIApplication**]**]*) – Return type None `root_path` Absolute path to the package on the filesystem. Used to look up resources contained in the package. `route(rule, **options)` Decorate a view function to register it with the given URL rule and options. Calls [`add_url_rule()`](#flask.Blueprint.add_url_rule "flask.Blueprint.add_url_rule"), which has more details about the implementation. ``` @app.route("/") def index(): return "Hello, World!" ``` See [URL Route Registrations](#url-route-registrations). The endpoint name for the route defaults to the name of the view function if the `endpoint` parameter isn’t passed. The `methods` parameter defaults to `["GET"]`. `HEAD` and `OPTIONS` are added automatically. Parameters * **rule** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – The URL rule string. * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Extra options passed to the [`Rule`](https://werkzeug.palletsprojects.com/en/2.2.x/routing/#werkzeug.routing.Rule "(in Werkzeug v2.2.x)") object. Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.scaffold.T\_route], flask.scaffold.T\_route] `send_static_file(filename)` The view function used to serve files from [`static_folder`](#flask.Blueprint.static_folder "flask.Blueprint.static_folder"). A route is automatically registered for this view at [`static_url_path`](#flask.Blueprint.static_url_path "flask.Blueprint.static_url_path") if [`static_folder`](#flask.Blueprint.static_folder "flask.Blueprint.static_folder") is set. Changelog New in version 0.5. Parameters **filename** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – Return type [Response](#flask.Response "flask.Response") `property static_folder: Optional[str]` The absolute path to the configured static folder. `None` if no static folder is set. `property static_url_path: Optional[str]` The URL prefix that the static route will be accessible from. If it was not configured during init, it is derived from [`static_folder`](#flask.Blueprint.static_folder "flask.Blueprint.static_folder"). `teardown_app_request(f)` Like [`Flask.teardown_request()`](#flask.Flask.teardown_request "flask.Flask.teardown_request") but for a blueprint. Such a function is executed when tearing down each request, even if outside of the blueprint. Parameters **f** (*flask.blueprints.T\_teardown*) – Return type flask.blueprints.T\_teardown `teardown_request(f)` Register a function to be called when the request context is popped. Typically this happens at the end of each request, but contexts may be pushed manually as well during testing. ``` with app.test_request_context(): ... ``` When the `with` block exits (or `ctx.pop()` is called), the teardown functions are called just before the request context is made inactive. When a teardown function was called because of an unhandled exception it will be passed an error object. If an [`errorhandler()`](#flask.Blueprint.errorhandler "flask.Blueprint.errorhandler") is registered, it will handle the exception and the teardown will not receive it. Teardown functions must avoid raising exceptions. If they execute code that might fail they must surround that code with a `try`/`except` block and log any errors. The return values of teardown functions are ignored. Parameters **f** (*flask.scaffold.T\_teardown*) – Return type flask.scaffold.T\_teardown `teardown_request_funcs: t.Dict[ft.AppOrBlueprintKey, t.List[ft.TeardownCallable]]` A data structure of functions to call at the end of each request even if an exception is raised, in the format `{scope: [functions]}`. The `scope` key is the name of a blueprint the functions are active for, or `None` for all requests. To register a function, use the [`teardown_request()`](#flask.Blueprint.teardown_request "flask.Blueprint.teardown_request") decorator. This data structure is internal. It should not be modified directly and its format may change at any time. `template_context_processors: t.Dict[ft.AppOrBlueprintKey, t.List[ft.TemplateContextProcessorCallable]]` A data structure of functions to call to pass extra context values when rendering templates, in the format `{scope: [functions]}`. The `scope` key is the name of a blueprint the functions are active for, or `None` for all requests. To register a function, use the [`context_processor()`](#flask.Blueprint.context_processor "flask.Blueprint.context_processor") decorator. This data structure is internal. It should not be modified directly and its format may change at any time. `template_folder` The path to the templates folder, relative to [`root_path`](#flask.Blueprint.root_path "flask.Blueprint.root_path"), to add to the template loader. `None` if templates should not be added. `url_default_functions: t.Dict[ft.AppOrBlueprintKey, t.List[ft.URLDefaultCallable]]` A data structure of functions to call to modify the keyword arguments when generating URLs, in the format `{scope: [functions]}`. The `scope` key is the name of a blueprint the functions are active for, or `None` for all requests. To register a function, use the [`url_defaults()`](#flask.Blueprint.url_defaults "flask.Blueprint.url_defaults") decorator. This data structure is internal. It should not be modified directly and its format may change at any time. `url_defaults(f)` Callback function for URL defaults for all view functions of the application. It’s called with the endpoint and values and should update the values passed in place. Parameters **f** (*flask.scaffold.T\_url\_defaults*) – Return type flask.scaffold.T\_url\_defaults `url_value_preprocessor(f)` Register a URL value preprocessor function for all view functions in the application. These functions will be called before the [`before_request()`](#flask.Blueprint.before_request "flask.Blueprint.before_request") functions. The function can modify the values captured from the matched url before they are passed to the view. For example, this can be used to pop a common language code value and place it in `g` rather than pass it to every view. The function is passed the endpoint name and values dict. The return value is ignored. Parameters **f** (*flask.scaffold.T\_url\_value\_preprocessor*) – Return type flask.scaffold.T\_url\_value\_preprocessor `url_value_preprocessors: t.Dict[ft.AppOrBlueprintKey, t.List[ft.URLValuePreprocessorCallable]]` A data structure of functions to call to modify the keyword arguments passed to the view function, in the format `{scope: [functions]}`. The `scope` key is the name of a blueprint the functions are active for, or `None` for all requests. To register a function, use the [`url_value_preprocessor()`](#flask.Blueprint.url_value_preprocessor "flask.Blueprint.url_value_preprocessor") decorator. This data structure is internal. It should not be modified directly and its format may change at any time. `view_functions: t.Dict[str, t.Callable]` A dictionary mapping endpoint names to view functions. To register a view function, use the [`route()`](#flask.Blueprint.route "flask.Blueprint.route") decorator. This data structure is internal. It should not be modified directly and its format may change at any time. Incoming Request Data --------------------- `class flask.Request(environ, populate_request=True, shallow=False)` The request object used by default in Flask. Remembers the matched endpoint and view arguments. It is what ends up as [`request`](#flask.request "flask.request"). If you want to replace the request object used you can subclass this and set [`request_class`](#flask.Flask.request_class "flask.Flask.request_class") to your subclass. The request object is a [`Request`](https://werkzeug.palletsprojects.com/en/2.2.x/wrappers/#werkzeug.wrappers.Request "(in Werkzeug v2.2.x)") subclass and provides all of the attributes Werkzeug defines plus a few Flask specific ones. Parameters * **environ** (*WSGIEnvironment*) – * **populate\_request** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – * **shallow** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Return type None `property accept_charsets: werkzeug.datastructures.CharsetAccept` List of charsets this client supports as [`CharsetAccept`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.CharsetAccept "(in Werkzeug v2.2.x)") object. `property accept_encodings: werkzeug.datastructures.Accept` List of encodings this client accepts. Encodings in a HTTP term are compression encodings such as gzip. For charsets have a look at `accept_charset`. `property accept_languages: werkzeug.datastructures.LanguageAccept` List of languages this client accepts as [`LanguageAccept`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.LanguageAccept "(in Werkzeug v2.2.x)") object. `property accept_mimetypes: werkzeug.datastructures.MIMEAccept` List of mimetypes this client supports as [`MIMEAccept`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.MIMEAccept "(in Werkzeug v2.2.x)") object. `access_control_request_headers` Sent with a preflight request to indicate which headers will be sent with the cross origin request. Set `access_control_allow_headers` on the response to indicate which headers are allowed. `access_control_request_method` Sent with a preflight request to indicate which method will be used for the cross origin request. Set `access_control_allow_methods` on the response to indicate which methods are allowed. `property access_route: List[str]` If a forwarded header exists this is a list of all ip addresses from the client ip to the last proxy server. `classmethod application(f)` Decorate a function as responder that accepts the request as the last argument. This works like the `responder()` decorator but the function is passed the request object as the last argument and the request object will be closed automatically: ``` @Request.application def my_wsgi_app(request): return Response('Hello World!') ``` As of Werkzeug 0.14 HTTP exceptions are automatically caught and converted to responses instead of failing. Parameters **f** ([Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[*[Request](#flask.Request "flask.Request")*]**,* *WSGIApplication**]*) – the WSGI callable to decorate Returns a new WSGI callable Return type WSGIApplication `property args: werkzeug.datastructures.MultiDict[str, str]` The parsed URL parameters (the part in the URL after the question mark). By default an [`ImmutableMultiDict`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.ImmutableMultiDict "(in Werkzeug v2.2.x)") is returned from this function. This can be changed by setting [`parameter_storage_class`](#flask.Request.parameter_storage_class "flask.Request.parameter_storage_class") to a different type. This might be necessary if the order of the form data is important. `property authorization: Optional[werkzeug.datastructures.Authorization]` The `Authorization` object in parsed form. `property base_url: str` Like [`url`](#flask.Request.url "flask.Request.url") but without the query string. `property blueprint: Optional[str]` The registered name of the current blueprint. This will be `None` if the endpoint is not part of a blueprint, or if URL matching failed or has not been performed yet. This does not necessarily match the name the blueprint was created with. It may have been nested, or registered with a different name. `property blueprints: List[str]` The registered names of the current blueprint upwards through parent blueprints. This will be an empty list if there is no current blueprint, or if URL matching failed. Changelog New in version 2.0.1. `property cache_control: werkzeug.datastructures.RequestCacheControl` A [`RequestCacheControl`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.RequestCacheControl "(in Werkzeug v2.2.x)") object for the incoming cache control headers. `close()` Closes associated resources of this request object. This closes all file handles explicitly. You can also use the request object in a with statement which will automatically close it. Changelog New in version 0.9. Return type None `content_encoding` The Content-Encoding entity-header field is used as a modifier to the media-type. When present, its value indicates what additional content codings have been applied to the entity-body, and thus what decoding mechanisms must be applied in order to obtain the media-type referenced by the Content-Type header field. Changelog New in version 0.9. `property content_length: Optional[int]` The Content-Length entity-header field indicates the size of the entity-body in bytes or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET. `content_md5` The Content-MD5 entity-header field, as defined in RFC 1864, is an MD5 digest of the entity-body for the purpose of providing an end-to-end message integrity check (MIC) of the entity-body. (Note: a MIC is good for detecting accidental modification of the entity-body in transit, but is not proof against malicious attacks.) Changelog New in version 0.9. `content_type` The Content-Type entity-header field indicates the media type of the entity-body sent to the recipient or, in the case of the HEAD method, the media type that would have been sent had the request been a GET. `property cookies: werkzeug.datastructures.ImmutableMultiDict[str, str]` A [`dict`](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.10)") with the contents of all cookies transmitted with the request. `property data: bytes` Contains the incoming request data as string in case it came with a mimetype Werkzeug does not handle. `date` The Date general-header field represents the date and time at which the message was originated, having the same semantics as orig-date in RFC 822. Changelog Changed in version 2.0: The datetime object is timezone-aware. `dict_storage_class` alias of [`werkzeug.datastructures.ImmutableMultiDict`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.ImmutableMultiDict "(in Werkzeug v2.2.x)") `property endpoint: Optional[str]` The endpoint that matched the request URL. This will be `None` if matching failed or has not been performed yet. This in combination with [`view_args`](#flask.Request.view_args "flask.Request.view_args") can be used to reconstruct the same URL or a modified URL. `environ: WSGIEnvironment` The WSGI environment containing HTTP headers and information from the WSGI server. `property files: werkzeug.datastructures.ImmutableMultiDict[str, werkzeug.datastructures.FileStorage]` [`MultiDict`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.MultiDict "(in Werkzeug v2.2.x)") object containing all uploaded files. Each key in [`files`](#flask.Request.files "flask.Request.files") is the name from the `<input type="file" name="">`. Each value in [`files`](#flask.Request.files "flask.Request.files") is a Werkzeug [`FileStorage`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.FileStorage "(in Werkzeug v2.2.x)") object. It basically behaves like a standard file object you know from Python, with the difference that it also has a [`save()`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.FileStorage.save "(in Werkzeug v2.2.x)") function that can store the file on the filesystem. Note that [`files`](#flask.Request.files "flask.Request.files") will only contain data if the request method was POST, PUT or PATCH and the `<form>` that posted to the request had `enctype="multipart/form-data"`. It will be empty otherwise. See the [`MultiDict`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.MultiDict "(in Werkzeug v2.2.x)") / [`FileStorage`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.FileStorage "(in Werkzeug v2.2.x)") documentation for more details about the used data structure. `property form: werkzeug.datastructures.ImmutableMultiDict[str, str]` The form parameters. By default an [`ImmutableMultiDict`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.ImmutableMultiDict "(in Werkzeug v2.2.x)") is returned from this function. This can be changed by setting [`parameter_storage_class`](#flask.Request.parameter_storage_class "flask.Request.parameter_storage_class") to a different type. This might be necessary if the order of the form data is important. Please keep in mind that file uploads will not end up here, but instead in the [`files`](#flask.Request.files "flask.Request.files") attribute. Changelog Changed in version 0.9: Previous to Werkzeug 0.9 this would only contain form data for POST and PUT requests. `form_data_parser_class` alias of [`werkzeug.formparser.FormDataParser`](https://werkzeug.palletsprojects.com/en/2.2.x/http/#werkzeug.formparser.FormDataParser "(in Werkzeug v2.2.x)") `classmethod from_values(*args, **kwargs)` Create a new request object based on the values provided. If environ is given missing values are filled from there. This method is useful for small scripts when you need to simulate a request from an URL. Do not use this method for unittesting, there is a full featured client object (`Client`) that allows to create multipart requests, support for cookies etc. This accepts the same options as the [`EnvironBuilder`](https://werkzeug.palletsprojects.com/en/2.2.x/test/#werkzeug.test.EnvironBuilder "(in Werkzeug v2.2.x)"). Changelog Changed in version 0.5: This method now accepts the same arguments as [`EnvironBuilder`](https://werkzeug.palletsprojects.com/en/2.2.x/test/#werkzeug.test.EnvironBuilder "(in Werkzeug v2.2.x)"). Because of this the `environ` parameter is now called `environ_overrides`. Returns request object Parameters * **args** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [werkzeug.wrappers.request.Request](https://werkzeug.palletsprojects.com/en/2.2.x/wrappers/#werkzeug.wrappers.Request "(in Werkzeug v2.2.x)") `property full_path: str` Requested path, including the query string. `get_data(cache=True, as_text=False, parse_form_data=False)` This reads the buffered incoming data from the client into one bytes object. By default this is cached but that behavior can be changed by setting `cache` to `False`. Usually it’s a bad idea to call this method without checking the content length first as a client could send dozens of megabytes or more to cause memory problems on the server. Note that if the form data was already parsed this method will not return anything as form data parsing does not cache the data like this method does. To implicitly invoke form data parsing function set `parse_form_data` to `True`. When this is done the return value of this method will be an empty string if the form parser handles the data. This generally is not necessary as if the whole data is cached (which is the default) the form parser will used the cached data to parse the form data. Please be generally aware of checking the content length first in any case before calling this method to avoid exhausting server memory. If `as_text` is set to `True` the return value will be a decoded string. Changelog New in version 0.9. Parameters * **cache** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – * **as\_text** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – * **parse\_form\_data** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Return type [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")] `get_json(force=False, silent=False, cache=True)` Parse [`data`](#flask.Request.data "flask.Request.data") as JSON. If the mimetype does not indicate JSON (*application/json*, see [`is_json`](#flask.Request.is_json "flask.Request.is_json")), or parsing fails, [`on_json_loading_failed()`](#flask.Request.on_json_loading_failed "flask.Request.on_json_loading_failed") is called and its return value is used as the return value. By default this raises a 400 Bad Request error. Parameters * **force** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Ignore the mimetype and always try to parse JSON. * **silent** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Silence mimetype and parsing errors, and return `None` instead. * **cache** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Store the parsed JSON to return for subsequent calls. Return type [Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")] Changelog Changed in version 2.1: Raise a 400 error if the content type is incorrect. `headers` The headers received with the request. `property host: str` The host name the request was made to, including the port if it’s non-standard. Validated with `trusted_hosts`. `property host_url: str` The request URL scheme and host only. `property if_match: werkzeug.datastructures.ETags` An object containing all the etags in the `If-Match` header. Return type [`ETags`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.ETags "(in Werkzeug v2.2.x)") `property if_modified_since: Optional[datetime.datetime]` The parsed `If-Modified-Since` header as a datetime object. Changelog Changed in version 2.0: The datetime object is timezone-aware. `property if_none_match: werkzeug.datastructures.ETags` An object containing all the etags in the `If-None-Match` header. Return type [`ETags`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.ETags "(in Werkzeug v2.2.x)") `property if_range: werkzeug.datastructures.IfRange` The parsed `If-Range` header. Changelog Changed in version 2.0: `IfRange.date` is timezone-aware. New in version 0.7. `property if_unmodified_since: Optional[datetime.datetime]` The parsed `If-Unmodified-Since` header as a datetime object. Changelog Changed in version 2.0: The datetime object is timezone-aware. `input_stream` The WSGI input stream. In general it’s a bad idea to use this one because you can easily read past the boundary. Use the [`stream`](#flask.Request.stream "flask.Request.stream") instead. `property is_json: bool` Check if the mimetype indicates JSON data, either *application/json* or *application/\*+json*. `is_multiprocess` boolean that is `True` if the application is served by a WSGI server that spawns multiple processes. `is_multithread` boolean that is `True` if the application is served by a multithreaded WSGI server. `is_run_once` boolean that is `True` if the application will be executed only once in a process lifetime. This is the case for CGI for example, but it’s not guaranteed that the execution only happens one time. `property is_secure: bool` `True` if the request was made with a secure protocol (HTTPS or WSS). `property json: Optional[Any]` The parsed JSON data if [`mimetype`](#flask.Request.mimetype "flask.Request.mimetype") indicates JSON (*application/json*, see [`is_json`](#flask.Request.is_json "flask.Request.is_json")). Calls [`get_json()`](#flask.Request.get_json "flask.Request.get_json") with default arguments. If the request content type is not `application/json`, this will raise a 400 Bad Request error. Changelog Changed in version 2.1: Raise a 400 error if the content type is incorrect. `list_storage_class` alias of [`werkzeug.datastructures.ImmutableList`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.ImmutableList "(in Werkzeug v2.2.x)") `make_form_data_parser()` Creates the form data parser. Instantiates the [`form_data_parser_class`](#flask.Request.form_data_parser_class "flask.Request.form_data_parser_class") with some parameters. Changelog New in version 0.8. Return type [werkzeug.formparser.FormDataParser](https://werkzeug.palletsprojects.com/en/2.2.x/http/#werkzeug.formparser.FormDataParser "(in Werkzeug v2.2.x)") `property max_content_length: Optional[int]` Read-only view of the `MAX_CONTENT_LENGTH` config key. `max_forwards` The Max-Forwards request-header field provides a mechanism with the TRACE and OPTIONS methods to limit the number of proxies or gateways that can forward the request to the next inbound server. `method` The method the request was made with, such as `GET`. `property mimetype: str` Like [`content_type`](#flask.Request.content_type "flask.Request.content_type"), but without parameters (eg, without charset, type etc.) and always lowercase. For example if the content type is `text/HTML; charset=utf-8` the mimetype would be `'text/html'`. `property mimetype_params: Dict[str, str]` The mimetype parameters as dict. For example if the content type is `text/html; charset=utf-8` the params would be `{'charset': 'utf-8'}`. `on_json_loading_failed(e)` Called if [`get_json()`](#flask.Request.get_json "flask.Request.get_json") fails and isn’t silenced. If this method returns a value, it is used as the return value for [`get_json()`](#flask.Request.get_json "flask.Request.get_json"). The default implementation raises [`BadRequest`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.BadRequest "(in Werkzeug v2.2.x)"). Parameters **e** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[ValueError](https://docs.python.org/3/library/exceptions.html#ValueError "(in Python v3.10)")*]*) – If parsing failed, this is the exception. It will be `None` if the content type wasn’t `application/json`. Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") `origin` The host that the request originated from. Set `access_control_allow_origin` on the response to indicate which origins are allowed. `parameter_storage_class` alias of [`werkzeug.datastructures.ImmutableMultiDict`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.ImmutableMultiDict "(in Werkzeug v2.2.x)") `path` The path part of the URL after [`root_path`](#flask.Request.root_path "flask.Request.root_path"). This is the path used for routing within the application. `property pragma: werkzeug.datastructures.HeaderSet` The Pragma general-header field is used to include implementation-specific directives that might apply to any recipient along the request/response chain. All pragma directives specify optional behavior from the viewpoint of the protocol; however, some systems MAY require that behavior be consistent with the directives. `query_string` The part of the URL after the “?”. This is the raw value, use [`args`](#flask.Request.args "flask.Request.args") for the parsed values. `property range: Optional[werkzeug.datastructures.Range]` The parsed `Range` header. Changelog New in version 0.7. Return type [`Range`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.Range "(in Werkzeug v2.2.x)") `referrer` The Referer[sic] request-header field allows the client to specify, for the server’s benefit, the address (URI) of the resource from which the Request-URI was obtained (the “referrer”, although the header field is misspelled). `remote_addr` The address of the client sending the request. `remote_user` If the server supports user authentication, and the script is protected, this attribute contains the username the user has authenticated as. `root_path` The prefix that the application is mounted under, without a trailing slash. [`path`](#flask.Request.path "flask.Request.path") comes after this. `property root_url: str` The request URL scheme, host, and root path. This is the root that the application is accessed from. `routing_exception: Optional[Exception] = None` If matching the URL failed, this is the exception that will be raised / was raised as part of the request handling. This is usually a [`NotFound`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.NotFound "(in Werkzeug v2.2.x)") exception or something similar. `scheme` The URL scheme of the protocol the request used, such as `https` or `wss`. `property script_root: str` Alias for `self.root_path`. `environ["SCRIPT_ROOT"]` without a trailing slash. `server` The address of the server. `(host, port)`, `(path, None)` for unix sockets, or `None` if not known. `shallow: bool` Set when creating the request object. If `True`, reading from the request body will cause a `RuntimeException`. Useful to prevent modifying the stream from middleware. `property stream: IO[bytes]` If the incoming form data was not encoded with a known mimetype the data is stored unmodified in this stream for consumption. Most of the time it is a better idea to use [`data`](#flask.Request.data "flask.Request.data") which will give you that data as a string. The stream only returns the data once. Unlike [`input_stream`](#flask.Request.input_stream "flask.Request.input_stream") this stream is properly guarded that you can’t accidentally read past the length of the input. Werkzeug will internally always refer to this stream to read data which makes it possible to wrap this object with a stream that does filtering. Changelog Changed in version 0.9: This stream is now always available but might be consumed by the form parser later on. Previously the stream was only set if no parsing happened. `property url: str` The full request URL with the scheme, host, root path, path, and query string. `property url_charset: str` The charset that is assumed for URLs. Defaults to the value of `charset`. Changelog New in version 0.6. `property url_root: str` Alias for [`root_url`](#flask.Request.root_url "flask.Request.root_url"). The URL with scheme, host, and root path. For example, `https://example.com/app/`. `url_rule: Optional[Rule] = None` The internal URL rule that matched the request. This can be useful to inspect which methods are allowed for the URL from a before/after handler (`request.url_rule.methods`) etc. Though if the request’s method was invalid for the URL rule, the valid list is available in `routing_exception.valid_methods` instead (an attribute of the Werkzeug exception [`MethodNotAllowed`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.MethodNotAllowed "(in Werkzeug v2.2.x)")) because the request was never internally bound. Changelog New in version 0.6. `property user_agent: werkzeug.user_agent.UserAgent` The user agent. Use `user_agent.string` to get the header value. Set [`user_agent_class`](#flask.Request.user_agent_class "flask.Request.user_agent_class") to a subclass of [`UserAgent`](https://werkzeug.palletsprojects.com/en/2.2.x/utils/#werkzeug.user_agent.UserAgent "(in Werkzeug v2.2.x)") to provide parsing for the other properties or other extended data. Changelog Changed in version 2.0: The built in parser is deprecated and will be removed in Werkzeug 2.1. A `UserAgent` subclass must be set to parse data from the string. `user_agent_class` alias of [`werkzeug.user_agent.UserAgent`](https://werkzeug.palletsprojects.com/en/2.2.x/utils/#werkzeug.user_agent.UserAgent "(in Werkzeug v2.2.x)") `property values: werkzeug.datastructures.CombinedMultiDict[str, str]` A [`werkzeug.datastructures.CombinedMultiDict`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.CombinedMultiDict "(in Werkzeug v2.2.x)") that combines [`args`](#flask.Request.args "flask.Request.args") and [`form`](#flask.Request.form "flask.Request.form"). For GET requests, only `args` are present, not `form`. Changelog Changed in version 2.0: For GET requests, only `args` are present, not `form`. `view_args: Optional[Dict[str, Any]] = None` A dict of view arguments that matched the request. If an exception happened when matching, this will be `None`. `property want_form_data_parsed: bool` `True` if the request method carries content. By default this is true if a `Content-Type` is sent. Changelog New in version 0.8. `flask.request` To access incoming request data, you can use the global `request` object. Flask parses incoming request data for you and gives you access to it through that global object. Internally Flask makes sure that you always get the correct data for the active thread if you are in a multithreaded environment. This is a proxy. See [Notes On Proxies](../reqcontext/index#notes-on-proxies) for more information. The request object is an instance of a [`Request`](#flask.Request "flask.Request"). Response Objects ---------------- `class flask.Response(response=None, status=None, headers=None, mimetype=None, content_type=None, direct_passthrough=False)` The response object that is used by default in Flask. Works like the response object from Werkzeug but is set to have an HTML mimetype by default. Quite often you don’t have to create this object yourself because [`make_response()`](#flask.Flask.make_response "flask.Flask.make_response") will take care of that for you. If you want to replace the response object used you can subclass this and set [`response_class`](#flask.Flask.response_class "flask.Flask.response_class") to your subclass. Changelog Changed in version 1.0: JSON support is added to the response, like the request. This is useful when testing to get the test client response data as JSON. Changed in version 1.0: Added [`max_cookie_size`](#flask.Response.max_cookie_size "flask.Response.max_cookie_size"). Parameters * **response** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Iterable](https://docs.python.org/3/library/typing.html#typing.Iterable "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Iterable](https://docs.python.org/3/library/typing.html#typing.Iterable "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*]**]*) – * **status** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [http.HTTPStatus](https://docs.python.org/3/library/http.html#http.HTTPStatus "(in Python v3.10)")*]**]*) – * **headers** ([werkzeug.datastructures.Headers](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.Headers "(in Werkzeug v2.2.x)")) – * **mimetype** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – * **content\_type** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – * **direct\_passthrough** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Return type None `accept_ranges` The `Accept-Ranges` header. Even though the name would indicate that multiple values are supported, it must be one string token only. The values `'bytes'` and `'none'` are common. Changelog New in version 0.7. `property access_control_allow_credentials: bool` Whether credentials can be shared by the browser to JavaScript code. As part of the preflight request it indicates whether credentials can be used on the cross origin request. `access_control_allow_headers` Which headers can be sent with the cross origin request. `access_control_allow_methods` Which methods can be used for the cross origin request. `access_control_allow_origin` The origin or ‘\*’ for any origin that may make cross origin requests. `access_control_expose_headers` Which headers can be shared by the browser to JavaScript code. `access_control_max_age` The maximum age in seconds the access control settings can be cached for. `add_etag(overwrite=False, weak=False)` Add an etag for the current response if there is none yet. Changelog Changed in version 2.0: SHA-1 is used to generate the value. MD5 may not be available in some environments. Parameters * **overwrite** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – * **weak** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Return type None `age` The Age response-header field conveys the sender’s estimate of the amount of time since the response (or its revalidation) was generated at the origin server. Age values are non-negative decimal integers, representing time in seconds. `property allow: werkzeug.datastructures.HeaderSet` The Allow entity-header field lists the set of methods supported by the resource identified by the Request-URI. The purpose of this field is strictly to inform the recipient of valid methods associated with the resource. An Allow header field MUST be present in a 405 (Method Not Allowed) response. `property cache_control: werkzeug.datastructures.ResponseCacheControl` The Cache-Control general-header field is used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain. `calculate_content_length()` Returns the content length if available or `None` otherwise. Return type [Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")[[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")] `call_on_close(func)` Adds a function to the internal list of functions that should be called as part of closing down the response. Since 0.7 this function also returns the function that was passed so that this can be used as a decorator. Changelog New in version 0.6. Parameters **func** ([Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[**]**,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]*) – Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[], [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")] `close()` Close the wrapped response if possible. You can also use the object in a with statement which will automatically close it. Changelog New in version 0.9: Can now be used in a with statement. Return type None `content_encoding` The Content-Encoding entity-header field is used as a modifier to the media-type. When present, its value indicates what additional content codings have been applied to the entity-body, and thus what decoding mechanisms must be applied in order to obtain the media-type referenced by the Content-Type header field. `property content_language: werkzeug.datastructures.HeaderSet` The Content-Language entity-header field describes the natural language(s) of the intended audience for the enclosed entity. Note that this might not be equivalent to all the languages used within the entity-body. `content_length` The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET. `content_location` The Content-Location entity-header field MAY be used to supply the resource location for the entity enclosed in the message when that entity is accessible from a location separate from the requested resource’s URI. `content_md5` The Content-MD5 entity-header field, as defined in RFC 1864, is an MD5 digest of the entity-body for the purpose of providing an end-to-end message integrity check (MIC) of the entity-body. (Note: a MIC is good for detecting accidental modification of the entity-body in transit, but is not proof against malicious attacks.) `property content_range: werkzeug.datastructures.ContentRange` The `Content-Range` header as a [`ContentRange`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.ContentRange "(in Werkzeug v2.2.x)") object. Available even if the header is not set. Changelog New in version 0.7. `property content_security_policy: werkzeug.datastructures.ContentSecurityPolicy` The `Content-Security-Policy` header as a `ContentSecurityPolicy` object. Available even if the header is not set. The Content-Security-Policy header adds an additional layer of security to help detect and mitigate certain types of attacks. `property content_security_policy_report_only: werkzeug.datastructures.ContentSecurityPolicy` The `Content-Security-policy-report-only` header as a `ContentSecurityPolicy` object. Available even if the header is not set. The Content-Security-Policy-Report-Only header adds a csp policy that is not enforced but is reported thereby helping detect certain types of attacks. `content_type` The Content-Type entity-header field indicates the media type of the entity-body sent to the recipient or, in the case of the HEAD method, the media type that would have been sent had the request been a GET. `cross_origin_embedder_policy` Prevents a document from loading any cross-origin resources that do not explicitly grant the document permission. Values must be a member of the `werkzeug.http.COEP` enum. `cross_origin_opener_policy` Allows control over sharing of browsing context group with cross-origin documents. Values must be a member of the `werkzeug.http.COOP` enum. `property data: Union[bytes, str]` A descriptor that calls [`get_data()`](#flask.Response.get_data "flask.Response.get_data") and [`set_data()`](#flask.Response.set_data "flask.Response.set_data"). `date` The Date general-header field represents the date and time at which the message was originated, having the same semantics as orig-date in RFC 822. Changelog Changed in version 2.0: The datetime object is timezone-aware. `delete_cookie(key, path='/', domain=None, secure=False, httponly=False, samesite=None)` Delete a cookie. Fails silently if key doesn’t exist. Parameters * **key** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – the key (name) of the cookie to be deleted. * **path** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – if the cookie that should be deleted was limited to a path, the path has to be defined here. * **domain** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – if the cookie that should be deleted was limited to a domain, that domain has to be defined here. * **secure** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – If `True`, the cookie will only be available via HTTPS. * **httponly** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Disallow JavaScript access to the cookie. * **samesite** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – Limit the scope of the cookie to only be attached to requests that are “same-site”. Return type None `direct_passthrough` Pass the response body directly through as the WSGI iterable. This can be used when the body is a binary file or other iterator of bytes, to skip some unnecessary checks. Use [`send_file()`](https://werkzeug.palletsprojects.com/en/2.2.x/utils/#werkzeug.utils.send_file "(in Werkzeug v2.2.x)") instead of setting this manually. `expires` The Expires entity-header field gives the date/time after which the response is considered stale. A stale cache entry may not normally be returned by a cache. Changelog Changed in version 2.0: The datetime object is timezone-aware. `classmethod force_type(response, environ=None)` Enforce that the WSGI response is a response object of the current type. Werkzeug will use the [`Response`](#flask.Response "flask.Response") internally in many situations like the exceptions. If you call `get_response()` on an exception you will get back a regular [`Response`](#flask.Response "flask.Response") object, even if you are using a custom subclass. This method can enforce a given response type, and it will also convert arbitrary WSGI callables into response objects if an environ is provided: ``` # convert a Werkzeug response object into an instance of the # MyResponseClass subclass. response = MyResponseClass.force_type(response) # convert any WSGI application into a response object response = MyResponseClass.force_type(response, environ) ``` This is especially useful if you want to post-process responses in the main dispatcher and use functionality provided by your subclass. Keep in mind that this will modify response objects in place if possible! Parameters * **response** ([Response](#flask.Response "flask.Response")) – a response object or wsgi application. * **environ** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[**WSGIEnvironment**]*) – a WSGI environment object. Returns a response object. Return type [Response](#flask.Response "flask.Response") `freeze()` Make the response object ready to be pickled. Does the following: * Buffer the response into a list, ignoring `implicity_sequence_conversion` and [`direct_passthrough`](#flask.Response.direct_passthrough "flask.Response.direct_passthrough"). * Set the `Content-Length` header. * Generate an `ETag` header if one is not already set. Changelog Changed in version 2.1: Removed the `no_etag` parameter. Changed in version 2.0: An `ETag` header is added, the `no_etag` parameter is deprecated and will be removed in Werkzeug 2.1. Changed in version 0.6: The `Content-Length` header is set. Return type None `classmethod from_app(app, environ, buffered=False)` Create a new response object from an application output. This works best if you pass it an application that returns a generator all the time. Sometimes applications may use the `write()` callable returned by the `start_response` function. This tries to resolve such edge cases automatically. But if you don’t get the expected output you should set `buffered` to `True` which enforces buffering. Parameters * **app** (*WSGIApplication*) – the WSGI application to execute. * **environ** (*WSGIEnvironment*) – the WSGI environment to execute against. * **buffered** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – set to `True` to enforce buffering. Returns a response object. Return type [Response](#flask.Response "flask.Response") `get_app_iter(environ)` Returns the application iterator for the given environ. Depending on the request method and the current status code the return value might be an empty response rather than the one from the response. If the request method is `HEAD` or the status code is in a range where the HTTP specification requires an empty response, an empty iterable is returned. Changelog New in version 0.6. Parameters **environ** (*WSGIEnvironment*) – the WSGI environment of the request. Returns a response iterable. Return type [Iterable](https://docs.python.org/3/library/typing.html#typing.Iterable "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")] `get_data(as_text=False)` The string representation of the response body. Whenever you call this property the response iterable is encoded and flattened. This can lead to unwanted behavior if you stream big data. This behavior can be disabled by setting `implicit_sequence_conversion` to `False`. If `as_text` is set to `True` the return value will be a decoded string. Changelog New in version 0.9. Parameters **as\_text** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Return type [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")] `get_etag()` Return a tuple in the form `(etag, is_weak)`. If there is no ETag the return value is `(None, None)`. Return type [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[None, None]] `get_json(force=False, silent=False)` Parse [`data`](#flask.Response.data "flask.Response.data") as JSON. Useful during testing. If the mimetype does not indicate JSON (*application/json*, see [`is_json`](#flask.Response.is_json "flask.Response.is_json")), this returns `None`. Unlike [`Request.get_json()`](#flask.Request.get_json "flask.Request.get_json"), the result is not cached. Parameters * **force** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Ignore the mimetype and always try to parse JSON. * **silent** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Silence parsing errors and return `None` instead. Return type [Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")] `get_wsgi_headers(environ)` This is automatically called right before the response is started and returns headers modified for the given environment. It returns a copy of the headers from the response with some modifications applied if necessary. For example the location header (if present) is joined with the root URL of the environment. Also the content length is automatically set to zero here for certain status codes. Changelog Changed in version 0.6: Previously that function was called `fix_headers` and modified the response object in place. Also since 0.6, IRIs in location and content-location headers are handled properly. Also starting with 0.6, Werkzeug will attempt to set the content length if it is able to figure it out on its own. This is the case if all the strings in the response iterable are already encoded and the iterable is buffered. Parameters **environ** (*WSGIEnvironment*) – the WSGI environment of the request. Returns returns a new [`Headers`](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.Headers "(in Werkzeug v2.2.x)") object. Return type [werkzeug.datastructures.Headers](https://werkzeug.palletsprojects.com/en/2.2.x/datastructures/#werkzeug.datastructures.Headers "(in Werkzeug v2.2.x)") `get_wsgi_response(environ)` Returns the final WSGI response as tuple. The first item in the tuple is the application iterator, the second the status and the third the list of headers. The response returned is created specially for the given environment. For example if the request method in the WSGI environment is `'HEAD'` the response will be empty and only the headers and status code will be present. Changelog New in version 0.6. Parameters **environ** (*WSGIEnvironment*) – the WSGI environment of the request. Returns an `(app_iter, status, headers)` tuple. Return type [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Iterable](https://docs.python.org/3/library/typing.html#typing.Iterable "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")], [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")]]] `property is_json: bool` Check if the mimetype indicates JSON data, either *application/json* or *application/\*+json*. `property is_sequence: bool` If the iterator is buffered, this property will be `True`. A response object will consider an iterator to be buffered if the response attribute is a list or tuple. Changelog New in version 0.6. `property is_streamed: bool` If the response is streamed (the response is not an iterable with a length information) this property is `True`. In this case streamed means that there is no information about the number of iterations. This is usually `True` if a generator is passed to the response object. This is useful for checking before applying some sort of post filtering that should not take place for streamed responses. `iter_encoded()` Iter the response encoded with the encoding of the response. If the response object is invoked as WSGI application the return value of this method is used as application iterator unless [`direct_passthrough`](#flask.Response.direct_passthrough "flask.Response.direct_passthrough") was activated. Return type [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")] `property json: Optional[Any]` The parsed JSON data if [`mimetype`](#flask.Response.mimetype "flask.Response.mimetype") indicates JSON (*application/json*, see [`is_json`](#flask.Response.is_json "flask.Response.is_json")). Calls [`get_json()`](#flask.Response.get_json "flask.Response.get_json") with default arguments. `last_modified` The Last-Modified entity-header field indicates the date and time at which the origin server believes the variant was last modified. Changelog Changed in version 2.0: The datetime object is timezone-aware. `location` The Location response-header field is used to redirect the recipient to a location other than the Request-URI for completion of the request or identification of a new resource. `make_conditional(request_or_environ, accept_ranges=False, complete_length=None)` Make the response conditional to the request. This method works best if an etag was defined for the response already. The `add_etag` method can be used to do that. If called without etag just the date header is set. This does nothing if the request method in the request or environ is anything but GET or HEAD. For optimal performance when handling range requests, it’s recommended that your response data object implements `seekable`, `seek` and `tell` methods as described by [`io.IOBase`](https://docs.python.org/3/library/io.html#io.IOBase "(in Python v3.10)"). Objects returned by `wrap_file()` automatically implement those methods. It does not remove the body of the response because that’s something the `__call__()` function does for us automatically. Returns self so that you can do `return resp.make_conditional(req)` but modifies the object in-place. Parameters * **request\_or\_environ** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[**WSGIEnvironment**,* [Request](#flask.Request "flask.Request")*]*) – a request object or WSGI environment to be used to make the response conditional against. * **accept\_ranges** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – This parameter dictates the value of `Accept-Ranges` header. If `False` (default), the header is not set. If `True`, it will be set to `"bytes"`. If `None`, it will be set to `"none"`. If it’s a string, it will use this value. * **complete\_length** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*]*) – Will be used only in valid Range Requests. It will set `Content-Range` complete length value and compute `Content-Length` real value. This parameter is mandatory for successful Range Requests completion. Raises [`RequestedRangeNotSatisfiable`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.RequestedRangeNotSatisfiable "(in Werkzeug v2.2.x)") if `Range` header could not be parsed or satisfied. Return type [Response](#flask.Response "flask.Response") Changelog Changed in version 2.0: Range processing is skipped if length is 0 instead of raising a 416 Range Not Satisfiable error. `make_sequence()` Converts the response iterator in a list. By default this happens automatically if required. If `implicit_sequence_conversion` is disabled, this method is not automatically called and some properties might raise exceptions. This also encodes all the items. Changelog New in version 0.6. Return type None `property max_cookie_size: int` Read-only view of the [`MAX_COOKIE_SIZE`](../config/index#MAX_COOKIE_SIZE "MAX_COOKIE_SIZE") config key. See [`max_cookie_size`](https://werkzeug.palletsprojects.com/en/2.2.x/wrappers/#werkzeug.wrappers.Response.max_cookie_size "(in Werkzeug v2.2.x)") in Werkzeug’s docs. `property mimetype: Optional[str]` The mimetype (content type without charset etc.) `property mimetype_params: Dict[str, str]` The mimetype parameters as dict. For example if the content type is `text/html; charset=utf-8` the params would be `{'charset': 'utf-8'}`. Changelog New in version 0.5. `response: t.Union[t.Iterable[str], t.Iterable[bytes]]` The response body to send as the WSGI iterable. A list of strings or bytes represents a fixed-length response, any other iterable is a streaming response. Strings are encoded to bytes as UTF-8. Do not set to a plain string or bytes, that will cause sending the response to be very inefficient as it will iterate one byte at a time. `property retry_after: Optional[datetime.datetime]` The Retry-After response-header field can be used with a 503 (Service Unavailable) response to indicate how long the service is expected to be unavailable to the requesting client. Time in seconds until expiration or date. Changelog Changed in version 2.0: The datetime object is timezone-aware. `set_cookie(key, value='', max_age=None, expires=None, path='/', domain=None, secure=False, httponly=False, samesite=None)` Sets a cookie. A warning is raised if the size of the cookie header exceeds [`max_cookie_size`](#flask.Response.max_cookie_size "flask.Response.max_cookie_size"), but the header will still be set. Parameters * **key** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – the key (name) of the cookie to be set. * **value** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – the value of the cookie. * **max\_age** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[datetime.timedelta](https://docs.python.org/3/library/datetime.html#datetime.timedelta "(in Python v3.10)")*,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*]**]*) – should be a number of seconds, or `None` (default) if the cookie should last only as long as the client’s browser session. * **expires** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [datetime.datetime](https://docs.python.org/3/library/datetime.html#datetime.datetime "(in Python v3.10)")*,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*,* [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.10)")*]**]*) – should be a `datetime` object or UNIX timestamp. * **path** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – limits the cookie to a given path, per default it will span the whole domain. * **domain** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – if you want to set a cross-domain cookie. For example, `domain=".example.com"` will set a cookie that is readable by the domain `www.example.com`, `foo.example.com` etc. Otherwise, a cookie will only be readable by the domain that set it. * **secure** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – If `True`, the cookie will only be available via HTTPS. * **httponly** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Disallow JavaScript access to the cookie. * **samesite** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – Limit the scope of the cookie to only be attached to requests that are “same-site”. Return type None `set_data(value)` Sets a new string as response. The value must be a string or bytes. If a string is set it’s encoded to the charset of the response (utf-8 by default). Changelog New in version 0.9. Parameters **value** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – Return type None `set_etag(etag, weak=False)` Set the etag, and override the old one if there was one. Parameters * **etag** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – * **weak** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Return type None `property status: str` The HTTP status code as a string. `property status_code: int` The HTTP status code as a number. `property stream: werkzeug.wrappers.response.ResponseStream` The response iterable as write-only stream. `property vary: werkzeug.datastructures.HeaderSet` The Vary field value indicates the set of request-header fields that fully determines, while the response is fresh, whether a cache is permitted to use the response to reply to a subsequent request without revalidation. `property www_authenticate: werkzeug.datastructures.WWWAuthenticate` The `WWW-Authenticate` header in a parsed form. Sessions -------- If you have set [`Flask.secret_key`](#flask.Flask.secret_key "flask.Flask.secret_key") (or configured it from [`SECRET_KEY`](../config/index#SECRET_KEY "SECRET_KEY")) you can use sessions in Flask applications. A session makes it possible to remember information from one request to another. The way Flask does this is by using a signed cookie. The user can look at the session contents, but can’t modify it unless they know the secret key, so make sure to set that to something complex and unguessable. To access the current session you can use the [`session`](#flask.session "flask.session") object: `class flask.session` The session object works pretty much like an ordinary dict, with the difference that it keeps track of modifications. This is a proxy. See [Notes On Proxies](../reqcontext/index#notes-on-proxies) for more information. The following attributes are interesting: `new` `True` if the session is new, `False` otherwise. `modified` `True` if the session object detected a modification. Be advised that modifications on mutable structures are not picked up automatically, in that situation you have to explicitly set the attribute to `True` yourself. Here an example: ``` # this change is not picked up because a mutable object (here # a list) is changed. session['objects'].append(42) # so mark it as modified yourself session.modified = True ``` `permanent` If set to `True` the session lives for [`permanent_session_lifetime`](#flask.Flask.permanent_session_lifetime "flask.Flask.permanent_session_lifetime") seconds. The default is 31 days. If set to `False` (which is the default) the session will be deleted when the user closes the browser. Session Interface ----------------- Changelog New in version 0.8. The session interface provides a simple way to replace the session implementation that Flask is using. `class flask.sessions.SessionInterface` The basic interface you have to implement in order to replace the default session interface which uses werkzeug’s securecookie implementation. The only methods you have to implement are [`open_session()`](#flask.sessions.SessionInterface.open_session "flask.sessions.SessionInterface.open_session") and [`save_session()`](#flask.sessions.SessionInterface.save_session "flask.sessions.SessionInterface.save_session"), the others have useful defaults which you don’t need to change. The session object returned by the [`open_session()`](#flask.sessions.SessionInterface.open_session "flask.sessions.SessionInterface.open_session") method has to provide a dictionary like interface plus the properties and methods from the [`SessionMixin`](#flask.sessions.SessionMixin "flask.sessions.SessionMixin"). We recommend just subclassing a dict and adding that mixin: ``` class Session(dict, SessionMixin): pass ``` If [`open_session()`](#flask.sessions.SessionInterface.open_session "flask.sessions.SessionInterface.open_session") returns `None` Flask will call into [`make_null_session()`](#flask.sessions.SessionInterface.make_null_session "flask.sessions.SessionInterface.make_null_session") to create a session that acts as replacement if the session support cannot work because some requirement is not fulfilled. The default [`NullSession`](#flask.sessions.NullSession "flask.sessions.NullSession") class that is created will complain that the secret key was not set. To replace the session interface on an application all you have to do is to assign [`flask.Flask.session_interface`](#flask.Flask.session_interface "flask.Flask.session_interface"): ``` app = Flask(__name__) app.session_interface = MySessionInterface() ``` Multiple requests with the same session may be sent and handled concurrently. When implementing a new session interface, consider whether reads or writes to the backing store must be synchronized. There is no guarantee on the order in which the session for each request is opened or saved, it will occur in the order that requests begin and end processing. Changelog New in version 0.8. `get_cookie_domain(app)` Returns the domain that should be set for the session cookie. Uses `SESSION_COOKIE_DOMAIN` if it is configured, otherwise falls back to detecting the domain based on `SERVER_NAME`. Once detected (or if not set at all), `SESSION_COOKIE_DOMAIN` is updated to avoid re-running the logic. Parameters **app** ([Flask](#flask.Flask "flask.Flask")) – Return type [Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")] `get_cookie_httponly(app)` Returns True if the session cookie should be httponly. This currently just returns the value of the `SESSION_COOKIE_HTTPONLY` config var. Parameters **app** ([Flask](#flask.Flask "flask.Flask")) – Return type [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)") `get_cookie_name(app)` The name of the session cookie. Uses``app.config[“SESSION\_COOKIE\_NAME”]``. Parameters **app** ([Flask](#flask.Flask "flask.Flask")) – Return type [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") `get_cookie_path(app)` Returns the path for which the cookie should be valid. The default implementation uses the value from the `SESSION_COOKIE_PATH` config var if it’s set, and falls back to `APPLICATION_ROOT` or uses `/` if it’s `None`. Parameters **app** ([Flask](#flask.Flask "flask.Flask")) – Return type [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") `get_cookie_samesite(app)` Return `'Strict'` or `'Lax'` if the cookie should use the `SameSite` attribute. This currently just returns the value of the [`SESSION_COOKIE_SAMESITE`](../config/index#SESSION_COOKIE_SAMESITE "SESSION_COOKIE_SAMESITE") setting. Parameters **app** ([Flask](#flask.Flask "flask.Flask")) – Return type [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") `get_cookie_secure(app)` Returns True if the cookie should be secure. This currently just returns the value of the `SESSION_COOKIE_SECURE` setting. Parameters **app** ([Flask](#flask.Flask "flask.Flask")) – Return type [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)") `get_expiration_time(app, session)` A helper method that returns an expiration date for the session or `None` if the session is linked to the browser session. The default implementation returns now + the permanent session lifetime configured on the application. Parameters * **app** ([Flask](#flask.Flask "flask.Flask")) – * **session** ([flask.sessions.SessionMixin](#flask.sessions.SessionMixin "flask.sessions.SessionMixin")) – Return type [Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")[[datetime.datetime](https://docs.python.org/3/library/datetime.html#datetime.datetime "(in Python v3.10)")] `is_null_session(obj)` Checks if a given object is a null session. Null sessions are not asked to be saved. This checks if the object is an instance of [`null_session_class`](#flask.sessions.SessionInterface.null_session_class "flask.sessions.SessionInterface.null_session_class") by default. Parameters **obj** ([object](https://docs.python.org/3/library/functions.html#object "(in Python v3.10)")) – Return type [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)") `make_null_session(app)` Creates a null session which acts as a replacement object if the real session support could not be loaded due to a configuration error. This mainly aids the user experience because the job of the null session is to still support lookup without complaining but modifications are answered with a helpful error message of what failed. This creates an instance of [`null_session_class`](#flask.sessions.SessionInterface.null_session_class "flask.sessions.SessionInterface.null_session_class") by default. Parameters **app** ([Flask](#flask.Flask "flask.Flask")) – Return type [flask.sessions.NullSession](#flask.sessions.NullSession "flask.sessions.NullSession") `null_session_class` [`make_null_session()`](#flask.sessions.SessionInterface.make_null_session "flask.sessions.SessionInterface.make_null_session") will look here for the class that should be created when a null session is requested. Likewise the [`is_null_session()`](#flask.sessions.SessionInterface.is_null_session "flask.sessions.SessionInterface.is_null_session") method will perform a typecheck against this type. alias of [`flask.sessions.NullSession`](#flask.sessions.NullSession "flask.sessions.NullSession") `open_session(app, request)` This is called at the beginning of each request, after pushing the request context, before matching the URL. This must return an object which implements a dictionary-like interface as well as the [`SessionMixin`](#flask.sessions.SessionMixin "flask.sessions.SessionMixin") interface. This will return `None` to indicate that loading failed in some way that is not immediately an error. The request context will fall back to using [`make_null_session()`](#flask.sessions.SessionInterface.make_null_session "flask.sessions.SessionInterface.make_null_session") in this case. Parameters * **app** ([Flask](#flask.Flask "flask.Flask")) – * **request** ([Request](#flask.Request "flask.Request")) – Return type [Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")[[flask.sessions.SessionMixin](#flask.sessions.SessionMixin "flask.sessions.SessionMixin")] `pickle_based = False` A flag that indicates if the session interface is pickle based. This can be used by Flask extensions to make a decision in regards to how to deal with the session object. Changelog New in version 0.10. `save_session(app, session, response)` This is called at the end of each request, after generating a response, before removing the request context. It is skipped if [`is_null_session()`](#flask.sessions.SessionInterface.is_null_session "flask.sessions.SessionInterface.is_null_session") returns `True`. Parameters * **app** ([Flask](#flask.Flask "flask.Flask")) – * **session** ([flask.sessions.SessionMixin](#flask.sessions.SessionMixin "flask.sessions.SessionMixin")) – * **response** ([Response](#flask.Response "flask.Response")) – Return type None `should_set_cookie(app, session)` Used by session backends to determine if a `Set-Cookie` header should be set for this session cookie for this response. If the session has been modified, the cookie is set. If the session is permanent and the `SESSION_REFRESH_EACH_REQUEST` config is true, the cookie is always set. This check is usually skipped if the session was deleted. Changelog New in version 0.11. Parameters * **app** ([Flask](#flask.Flask "flask.Flask")) – * **session** ([flask.sessions.SessionMixin](#flask.sessions.SessionMixin "flask.sessions.SessionMixin")) – Return type [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)") `class flask.sessions.SecureCookieSessionInterface` The default session interface that stores sessions in signed cookies through the `itsdangerous` module. `static digest_method(string=b'', *, usedforsecurity=True)` the hash function to use for the signature. The default is sha1 `key_derivation = 'hmac'` the name of the itsdangerous supported key derivation. The default is hmac. `open_session(app, request)` This is called at the beginning of each request, after pushing the request context, before matching the URL. This must return an object which implements a dictionary-like interface as well as the [`SessionMixin`](#flask.sessions.SessionMixin "flask.sessions.SessionMixin") interface. This will return `None` to indicate that loading failed in some way that is not immediately an error. The request context will fall back to using `make_null_session()` in this case. Parameters * **app** ([Flask](#flask.Flask "flask.Flask")) – * **request** ([Request](#flask.Request "flask.Request")) – Return type [Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")[[flask.sessions.SecureCookieSession](#flask.sessions.SecureCookieSession "flask.sessions.SecureCookieSession")] `salt = 'cookie-session'` the salt that should be applied on top of the secret key for the signing of cookie based sessions. `save_session(app, session, response)` This is called at the end of each request, after generating a response, before removing the request context. It is skipped if `is_null_session()` returns `True`. Parameters * **app** ([Flask](#flask.Flask "flask.Flask")) – * **session** ([flask.sessions.SessionMixin](#flask.sessions.SessionMixin "flask.sessions.SessionMixin")) – * **response** ([Response](#flask.Response "flask.Response")) – Return type None `serializer = <flask.json.tag.TaggedJSONSerializer object>` A python serializer for the payload. The default is a compact JSON derived serializer with support for some extra Python types such as datetime objects or tuples. `session_class` alias of [`flask.sessions.SecureCookieSession`](#flask.sessions.SecureCookieSession "flask.sessions.SecureCookieSession") `class flask.sessions.SecureCookieSession(initial=None)` Base class for sessions based on signed cookies. This session backend will set the [`modified`](#flask.sessions.SecureCookieSession.modified "flask.sessions.SecureCookieSession.modified") and [`accessed`](#flask.sessions.SecureCookieSession.accessed "flask.sessions.SecureCookieSession.accessed") attributes. It cannot reliably track whether a session is new (vs. empty), so `new` remains hard coded to `False`. Parameters **initial** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type None `accessed = False` header, which allows caching proxies to cache different pages for different users. `get(key, default=None)` Return the value for key if key is in the dictionary, else default. Parameters * **key** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – * **default** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]*) – Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") `modified = False` When data is changed, this is set to `True`. Only the session dictionary itself is tracked; if the session contains mutable data (for example a nested dict) then this must be set to `True` manually when modifying that data. The session cookie will only be written to the response if this is `True`. `setdefault(key, default=None)` Insert key with a value of default if key is not in the dictionary. Return the value for key if key is in the dictionary, else default. Parameters * **key** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – * **default** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]*) – Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") `class flask.sessions.NullSession(initial=None)` Class used to generate nicer error messages if sessions are not available. Will still allow read-only access to the empty session but fail on setting. Parameters **initial** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type None `clear() → None. Remove all items from D.` Parameters * **args** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type te.NoReturn `pop(k[, d]) → v, remove specified key and return the corresponding value.` If the key is not found, return the default if given; otherwise, raise a KeyError. Parameters * **args** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type te.NoReturn `popitem(*args, **kwargs)` Remove and return a (key, value) pair as a 2-tuple. Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty. Parameters * **args** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type te.NoReturn `setdefault(*args, **kwargs)` Insert key with a value of default if key is not in the dictionary. Return the value for key if key is in the dictionary, else default. Parameters * **args** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type te.NoReturn `update([E, ]**F) → None. Update D from dict/iterable E and F.` If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k] Parameters * **args** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type te.NoReturn `class flask.sessions.SessionMixin` Expands a basic dictionary with session attributes. `accessed = True` Some implementations can detect when session data is read or written and set this when that happens. The mixin default is hard coded to `True`. `modified = True` Some implementations can detect changes to the session and set this when that happens. The mixin default is hard coded to `True`. `property permanent: bool` This reflects the `'_permanent'` key in the dict. Notice The [`PERMANENT_SESSION_LIFETIME`](../config/index#PERMANENT_SESSION_LIFETIME "PERMANENT_SESSION_LIFETIME") config can be an integer or `timedelta`. The [`permanent_session_lifetime`](#flask.Flask.permanent_session_lifetime "flask.Flask.permanent_session_lifetime") attribute is always a `timedelta`. Test Client ----------- `class flask.testing.FlaskClient(*args, **kwargs)` Works like a regular Werkzeug test client but has knowledge about Flask’s contexts to defer the cleanup of the request context until the end of a `with` block. For general information about how to use this class refer to [`werkzeug.test.Client`](https://werkzeug.palletsprojects.com/en/2.2.x/test/#werkzeug.test.Client "(in Werkzeug v2.2.x)"). Changelog Changed in version 0.12: `app.test_client()` includes preset default environment, which can be set after instantiation of the `app.test_client()` object in `client.environ_base`. Basic usage is outlined in the [Testing Flask Applications](../testing/index) chapter. Parameters * **args** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type None `open(*args, buffered=False, follow_redirects=False, **kwargs)` Generate an environ dict from the given arguments, make a request to the application using it, and return the response. Parameters * **args** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Passed to `EnvironBuilder` to create the environ for the request. If a single arg is passed, it can be an existing `EnvironBuilder` or an environ dict. * **buffered** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Convert the iterator returned by the app into a list. If the iterator has a `close()` method, it is called automatically. * **follow\_redirects** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Make additional requests to follow HTTP redirects until a non-redirect status is returned. `TestResponse.history` lists the intermediate responses. * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type TestResponse Changelog Changed in version 2.1: Removed the `as_tuple` parameter. Changed in version 2.0: `as_tuple` is deprecated and will be removed in Werkzeug 2.1. Use `TestResponse.request` and `request.environ` instead. Changed in version 2.0: The request input stream is closed when calling `response.close()`. Input streams for redirects are automatically closed. Changed in version 0.5: If a dict is provided as file in the dict for the `data` parameter the content type has to be called `content_type` instead of `mimetype`. This change was made for consistency with `werkzeug.FileWrapper`. Changed in version 0.5: Added the `follow_redirects` parameter. `session_transaction(*args, **kwargs)` When used in combination with a `with` statement this opens a session transaction. This can be used to modify the session that the test client uses. Once the `with` block is left the session is stored back. ``` with client.session_transaction() as session: session['value'] = 42 ``` Internally this is implemented by going through a temporary test request context and since session handling could depend on request variables this function accepts the same arguments as [`test_request_context()`](#flask.Flask.test_request_context "flask.Flask.test_request_context") which are directly passed through. Parameters * **args** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Generator](https://docs.python.org/3/library/typing.html#typing.Generator "(in Python v3.10)")[[flask.sessions.SessionMixin](#flask.sessions.SessionMixin "flask.sessions.SessionMixin"), None, None] Test CLI Runner --------------- `class flask.testing.FlaskCliRunner(app, **kwargs)` A [`CliRunner`](https://click.palletsprojects.com/en/8.1.x/api/#click.testing.CliRunner "(in Click v8.1.x)") for testing a Flask app’s CLI commands. Typically created using [`test_cli_runner()`](#flask.Flask.test_cli_runner "flask.Flask.test_cli_runner"). See [Running Commands with the CLI Runner](../testing/index#testing-cli). Parameters * **app** ([Flask](#flask.Flask "flask.Flask")) – * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type None `invoke(cli=None, args=None, **kwargs)` Invokes a CLI command in an isolated environment. See [`CliRunner.invoke`](https://click.palletsprojects.com/en/8.1.x/api/#click.testing.CliRunner.invoke "(in Click v8.1.x)") for full method documentation. See [Running Commands with the CLI Runner](../testing/index#testing-cli) for examples. If the `obj` argument is not given, passes an instance of [`ScriptInfo`](#flask.cli.ScriptInfo "flask.cli.ScriptInfo") that knows how to load the Flask app being tested. Parameters * **cli** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]*) – Command object to invoke. Default is the app’s `cli` group. * **args** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]*) – List of strings to invoke the command with. * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Returns a [`Result`](https://click.palletsprojects.com/en/8.1.x/api/#click.testing.Result "(in Click v8.1.x)") object. Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") Application Globals ------------------- To share data that is valid for one request only from one function to another, a global variable is not good enough because it would break in threaded environments. Flask provides you with a special object that ensures it is only valid for the active request and that will return different values for each request. In a nutshell: it does the right thing, like it does for [`request`](#flask.request "flask.request") and [`session`](#flask.session "flask.session"). `flask.g` A namespace object that can store data during an [application context](../appcontext/index). This is an instance of [`Flask.app_ctx_globals_class`](#flask.Flask.app_ctx_globals_class "flask.Flask.app_ctx_globals_class"), which defaults to [`ctx._AppCtxGlobals`](#flask.ctx._AppCtxGlobals "flask.ctx._AppCtxGlobals"). This is a good place to store resources during a request. For example, a `before_request` function could load a user object from a session id, then set `g.user` to be used in the view function. This is a proxy. See [Notes On Proxies](../reqcontext/index#notes-on-proxies) for more information. Changelog Changed in version 0.10: Bound to the application context instead of the request context. `class flask.ctx._AppCtxGlobals` A plain object. Used as a namespace for storing data during an application context. Creating an app context automatically creates this object, which is made available as the `g` proxy. 'key' in g Check whether an attribute is present. Changelog New in version 0.10. iter(g) Return an iterator over the attribute names. Changelog New in version 0.10. `get(name, default=None)` Get an attribute by name, or a default value. Like [`dict.get()`](https://docs.python.org/3/library/stdtypes.html#dict.get "(in Python v3.10)"). Parameters * **name** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – Name of attribute to get. * **default** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]*) – Value to return if the attribute is not present. Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") Changelog New in version 0.10. `pop(name, default=<object object>)` Get and remove an attribute by name. Like [`dict.pop()`](https://docs.python.org/3/library/stdtypes.html#dict.pop "(in Python v3.10)"). Parameters * **name** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – Name of attribute to pop. * **default** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Value to return if the attribute is not present, instead of raising a `KeyError`. Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") Changelog New in version 0.11. `setdefault(name, default=None)` Get the value of an attribute if it is present, otherwise set and return a default value. Like [`dict.setdefault()`](https://docs.python.org/3/library/stdtypes.html#dict.setdefault "(in Python v3.10)"). Parameters * **name** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – Name of attribute to get. * **default** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]*) – Value to set and return if the attribute is not present. Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") Changelog New in version 0.11. Useful Functions and Classes ---------------------------- `flask.current_app` A proxy to the application handling the current request. This is useful to access the application without needing to import it, or if it can’t be imported, such as when using the application factory pattern or in blueprints and extensions. This is only available when an [application context](../appcontext/index) is pushed. This happens automatically during requests and CLI commands. It can be controlled manually with [`app_context()`](#flask.Flask.app_context "flask.Flask.app_context"). This is a proxy. See [Notes On Proxies](../reqcontext/index#notes-on-proxies) for more information. `flask.has_request_context()` If you have code that wants to test if a request context is there or not this function can be used. For instance, you may want to take advantage of request information if the request object is available, but fail silently if it is unavailable. ``` class User(db.Model): def __init__(self, username, remote_addr=None): self.username = username if remote_addr is None and has_request_context(): remote_addr = request.remote_addr self.remote_addr = remote_addr ``` Alternatively you can also just test any of the context bound objects (such as [`request`](#flask.request "flask.request") or [`g`](#flask.g "flask.g")) for truthness: ``` class User(db.Model): def __init__(self, username, remote_addr=None): self.username = username if remote_addr is None and request: remote_addr = request.remote_addr self.remote_addr = remote_addr ``` Changelog New in version 0.7. Return type [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)") `flask.copy_current_request_context(f)` A helper function that decorates a function to retain the current request context. This is useful when working with greenlets. The moment the function is decorated a copy of the request context is created and then pushed when the function is called. The current session is also included in the copied request context. Example: ``` import gevent from flask import copy_current_request_context @app.route('/') def index(): @copy_current_request_context def do_some_work(): # do some work here, it can access flask.request or # flask.session like you would otherwise in the view function. ... gevent.spawn(do_some_work) return 'Regular response' ``` Changelog New in version 0.10. Parameters **f** ([Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")) – Return type [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)") `flask.has_app_context()` Works like [`has_request_context()`](#flask.has_request_context "flask.has_request_context") but for the application context. You can also just do a boolean check on the [`current_app`](#flask.current_app "flask.current_app") object instead. Changelog New in version 0.9. Return type [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)") `flask.url_for(endpoint, *, _anchor=None, _method=None, _scheme=None, _external=None, **values)` Generate a URL to the given endpoint with the given values. This requires an active request or application context, and calls [`current_app.url_for()`](#flask.Flask.url_for "flask.Flask.url_for"). See that method for full documentation. Parameters * **endpoint** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – The endpoint name associated with the URL to generate. If this starts with a `.`, the current blueprint name (if any) will be used. * **\_anchor** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – If given, append this as `#anchor` to the URL. * **\_method** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – If given, generate the URL associated with this method for the endpoint. * **\_scheme** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – If given, the URL will have this scheme if it is external. * **\_external** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")*]*) – If given, prefer the URL to be internal (False) or require it to be external (True). External URLs include the scheme and domain. When not in an active request, URLs are external by default. * **values** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Values to use for the variable parts of the URL rule. Unknown keys are appended as query string arguments, like `?a=b&c=d`. Return type [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") Changed in version 2.2: Calls `current_app.url_for`, allowing an app to override the behavior. Changelog Changed in version 0.10: The `_scheme` parameter was added. Changed in version 0.9: The `_anchor` and `_method` parameters were added. Changed in version 0.9: Calls `app.handle_url_build_error` on build errors. `flask.abort(code, *args, **kwargs)` Raise an [`HTTPException`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.HTTPException "(in Werkzeug v2.2.x)") for the given status code. If [`current_app`](#flask.current_app "flask.current_app") is available, it will call its [`aborter`](#flask.Flask.aborter "flask.Flask.aborter") object, otherwise it will use [`werkzeug.exceptions.abort()`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.abort "(in Werkzeug v2.2.x)"). Parameters * **code** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*,* *BaseResponse**]*) – The status code for the exception, which must be registered in `app.aborter`. * **args** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Passed to the exception. * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Passed to the exception. Return type te.NoReturn New in version 2.2: Calls `current_app.aborter` if available instead of always using Werkzeug’s default `abort`. `flask.redirect(location, code=302, Response=None)` Create a redirect response object. If [`current_app`](#flask.current_app "flask.current_app") is available, it will use its [`redirect()`](#flask.Flask.redirect "flask.Flask.redirect") method, otherwise it will use [`werkzeug.utils.redirect()`](https://werkzeug.palletsprojects.com/en/2.2.x/utils/#werkzeug.utils.redirect "(in Werkzeug v2.2.x)"). Parameters * **location** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – The URL to redirect to. * **code** ([int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")) – The status code for the redirect. * **Response** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Type](https://docs.python.org/3/library/typing.html#typing.Type "(in Python v3.10)")*[**BaseResponse**]**]*) – The response class to use. Not used when `current_app` is active, which uses `app.response_class`. Return type BaseResponse New in version 2.2: Calls `current_app.redirect` if available instead of always using Werkzeug’s default `redirect`. `flask.make_response(*args)` Sometimes it is necessary to set additional headers in a view. Because views do not have to return response objects but can return a value that is converted into a response object by Flask itself, it becomes tricky to add headers to it. This function can be called instead of using a return and you will get a response object which you can use to attach headers. If view looked like this and you want to add a new header: ``` def index(): return render_template('index.html', foo=42) ``` You can now do something like this: ``` def index(): response = make_response(render_template('index.html', foo=42)) response.headers['X-Parachutes'] = 'parachutes are cool' return response ``` This function accepts the very same arguments you can return from a view function. This for example creates a response with a 404 error code: ``` response = make_response(render_template('not_found.html'), 404) ``` The other use case of this function is to force the return value of a view function into a response which is helpful with view decorators: ``` response = make_response(view_function()) response.headers['X-Parachutes'] = 'parachutes are cool' ``` Internally this function does the following things: * if no arguments are passed, it creates a new response argument * if one argument is passed, [`flask.Flask.make_response()`](#flask.Flask.make_response "flask.Flask.make_response") is invoked with it. * if more than one argument is passed, the arguments are passed to the [`flask.Flask.make_response()`](#flask.Flask.make_response "flask.Flask.make_response") function as tuple. Changelog New in version 0.6. Parameters **args** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Response](#flask.Response "flask.Response") `flask.after_this_request(f)` Executes a function after this request. This is useful to modify response objects. The function is passed the response object and has to return the same or a new one. Example: ``` @app.route('/') def index(): @after_this_request def add_header(response): response.headers['X-Foo'] = 'Parachute' return response return 'Hello World!' ``` This is more useful if a function other than the view function wants to modify a response. For instance think of a decorator that wants to add some headers without converting the return value into a response object. Changelog New in version 0.9. Parameters **f** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[**flask.typing.ResponseClass**]**,* *flask.typing.ResponseClass**]**,* [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[**flask.typing.ResponseClass**]**,* [Awaitable](https://docs.python.org/3/library/typing.html#typing.Awaitable "(in Python v3.10)")*[**flask.typing.ResponseClass**]**]**]*) – Return type [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.typing.ResponseClass], flask.typing.ResponseClass], [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[flask.typing.ResponseClass], [Awaitable](https://docs.python.org/3/library/typing.html#typing.Awaitable "(in Python v3.10)")[flask.typing.ResponseClass]]] `flask.send_file(path_or_file, mimetype=None, as_attachment=False, download_name=None, conditional=True, etag=True, last_modified=None, max_age=None)` Send the contents of a file to the client. The first argument can be a file path or a file-like object. Paths are preferred in most cases because Werkzeug can manage the file and get extra information from the path. Passing a file-like object requires that the file is opened in binary mode, and is mostly useful when building a file in memory with [`io.BytesIO`](https://docs.python.org/3/library/io.html#io.BytesIO "(in Python v3.10)"). Never pass file paths provided by a user. The path is assumed to be trusted, so a user could craft a path to access a file you didn’t intend. Use [`send_from_directory()`](#flask.send_from_directory "flask.send_from_directory") to safely serve user-requested paths from within a directory. If the WSGI server sets a `file_wrapper` in `environ`, it is used, otherwise Werkzeug’s built-in wrapper is used. Alternatively, if the HTTP server supports `X-Sendfile`, configuring Flask with `USE_X_SENDFILE = True` will tell the server to send the given path, which is much more efficient than reading it in Python. Parameters * **path\_or\_file** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[os.PathLike](https://docs.python.org/3/library/os.html#os.PathLike "(in Python v3.10)")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [BinaryIO](https://docs.python.org/3/library/typing.html#typing.BinaryIO "(in Python v3.10)")*]*) – The path to the file to send, relative to the current working directory if a relative path is given. Alternatively, a file-like object opened in binary mode. Make sure the file pointer is seeked to the start of the data. * **mimetype** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – The MIME type to send for the file. If not provided, it will try to detect it from the file name. * **as\_attachment** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Indicate to a browser that it should offer to save the file instead of displaying it. * **download\_name** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – The default name browsers will use when saving the file. Defaults to the passed file name. * **conditional** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Enable conditional and range responses based on request headers. Requires passing a file path and `environ`. * **etag** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – Calculate an ETag for the file, which requires passing a file path. Can also be a string to use instead. * **last\_modified** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[datetime.datetime](https://docs.python.org/3/library/datetime.html#datetime.datetime "(in Python v3.10)")*,* [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*,* [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.10)")*]**]*) – The last modified time to send for the file, in seconds. If not provided, it will try to detect it from the file path. * **max\_age** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*,* [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[*[Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**]**,* [Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*]**]**]**]*) – How long the client should cache the file, in seconds. If set, `Cache-Control` will be `public`, otherwise it will be `no-cache` to prefer conditional caching. Return type [Response](#flask.Response "flask.Response") Changelog Changed in version 2.0: `download_name` replaces the `attachment_filename` parameter. If `as_attachment=False`, it is passed with `Content-Disposition: inline` instead. Changed in version 2.0: `max_age` replaces the `cache_timeout` parameter. `conditional` is enabled and `max_age` is not set by default. Changed in version 2.0: `etag` replaces the `add_etags` parameter. It can be a string to use instead of generating one. Changed in version 2.0: Passing a file-like object that inherits from [`TextIOBase`](https://docs.python.org/3/library/io.html#io.TextIOBase "(in Python v3.10)") will raise a [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError "(in Python v3.10)") rather than sending an empty file. New in version 2.0: Moved the implementation to Werkzeug. This is now a wrapper to pass some Flask-specific arguments. Changed in version 1.1: `filename` may be a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike "(in Python v3.10)") object. Changed in version 1.1: Passing a [`BytesIO`](https://docs.python.org/3/library/io.html#io.BytesIO "(in Python v3.10)") object supports range requests. Changed in version 1.0.3: Filenames are encoded with ASCII instead of Latin-1 for broader compatibility with WSGI servers. Changed in version 1.0: UTF-8 filenames as specified in [**RFC 2231**](https://datatracker.ietf.org/doc/html/rfc2231.html) are supported. Changed in version 0.12: The filename is no longer automatically inferred from file objects. If you want to use automatic MIME and etag support, pass a filename via `filename_or_fp` or `attachment_filename`. Changed in version 0.12: `attachment_filename` is preferred over `filename` for MIME detection. Changed in version 0.9: `cache_timeout` defaults to [`Flask.get_send_file_max_age()`](#flask.Flask.get_send_file_max_age "flask.Flask.get_send_file_max_age"). Changed in version 0.7: MIME guessing and etag support for file-like objects was deprecated because it was unreliable. Pass a filename if you are able to, otherwise attach an etag yourself. Changed in version 0.5: The `add_etags`, `cache_timeout` and `conditional` parameters were added. The default behavior is to add etags. New in version 0.2. `flask.send_from_directory(directory, path, **kwargs)` Send a file from within a directory using [`send_file()`](#flask.send_file "flask.send_file"). ``` @app.route("/uploads/<path:name>") def download_file(name): return send_from_directory( app.config['UPLOAD_FOLDER'], name, as_attachment=True ) ``` This is a secure way to serve files from a folder, such as static files or uploads. Uses [`safe_join()`](https://werkzeug.palletsprojects.com/en/2.2.x/utils/#werkzeug.security.safe_join "(in Werkzeug v2.2.x)") to ensure the path coming from the client is not maliciously crafted to point outside the specified directory. If the final path does not point to an existing regular file, raises a 404 [`NotFound`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.NotFound "(in Werkzeug v2.2.x)") error. Parameters * **directory** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[os.PathLike](https://docs.python.org/3/library/os.html#os.PathLike "(in Python v3.10)")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – The directory that `path` must be located under, relative to the current application’s root path. * **path** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[os.PathLike](https://docs.python.org/3/library/os.html#os.PathLike "(in Python v3.10)")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – The path to the file to send, relative to `directory`. * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Arguments to pass to [`send_file()`](#flask.send_file "flask.send_file"). Return type [Response](#flask.Response "flask.Response") Changelog Changed in version 2.0: `path` replaces the `filename` parameter. New in version 2.0: Moved the implementation to Werkzeug. This is now a wrapper to pass some Flask-specific arguments. New in version 0.5. `flask.escape()` Replace the characters `&`, `<`, `>`, `'`, and `"` in the string with HTML-safe sequences. Use this if you need to display text that might contain such characters in HTML. If the object has an `__html__` method, it is called and the return value is assumed to already be safe for HTML. Parameters **s** – An object to be converted to a string and escaped. Returns A [`Markup`](#flask.Markup "flask.Markup") string with the escaped text. `class flask.Markup(base='', encoding=None, errors='strict')` A string that is ready to be safely inserted into an HTML or XML document, either because it was escaped or because it was marked safe. Passing an object to the constructor converts it to text and wraps it to mark it safe without escaping. To escape the text, use the [`escape()`](#flask.escape "flask.escape") class method instead. ``` >>> Markup("Hello, <em>World</em>!") Markup('Hello, <em>World</em>!') >>> Markup(42) Markup('42') >>> Markup.escape("Hello, <em>World</em>!") Markup('Hello &lt;em&gt;World&lt;/em&gt;!') ``` This implements the `__html__()` interface that some frameworks use. Passing an object that implements `__html__()` will wrap the output of that method, marking it safe. ``` >>> class Foo: ... def __html__(self): ... return '<a href="/foo">foo</a>' ... >>> Markup(Foo()) Markup('<a href="/foo">foo</a>') ``` This is a subclass of [`str`](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"). It has the same methods, but escapes their arguments and returns a `Markup` instance. ``` >>> Markup("<em>%s</em>") % ("foo & bar",) Markup('<em>foo &amp; bar</em>') >>> Markup("<em>Hello</em> ") + "<foo>" Markup('<em>Hello</em> &lt;foo&gt;') ``` Parameters * **base** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – * **encoding** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – * **errors** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – Return type [Markup](#flask.Markup "flask.Markup") `classmethod escape(s)` Escape a string. Calls [`escape()`](#flask.escape "flask.escape") and ensures that for subclasses the correct type is returned. Parameters **s** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [markupsafe.Markup](#flask.Markup "markupsafe.Markup") `striptags()` [`unescape()`](#flask.Markup.unescape "flask.Markup.unescape") the markup, remove tags, and normalize whitespace to single spaces. ``` >>> Markup("Main &raquo; <em>About</em>").striptags() 'Main » About' ``` Return type [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") `unescape()` Convert escaped markup back into a text string. This replaces HTML entities with the characters they represent. ``` >>> Markup("Main &raquo; <em>About</em>").unescape() 'Main » <em>About</em>' ``` Return type [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") Message Flashing ---------------- `flask.flash(message, category='message')` Flashes a message to the next request. In order to remove the flashed message from the session and to display it to the user, the template has to call [`get_flashed_messages()`](#flask.get_flashed_messages "flask.get_flashed_messages"). Changelog Changed in version 0.3: `category` parameter added. Parameters * **message** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – the message to be flashed. * **category** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – the category for the message. The following values are recommended: `'message'` for any kind of message, `'error'` for errors, `'info'` for information messages and `'warning'` for warnings. However any kind of string can be used as category. Return type None `flask.get_flashed_messages(with_categories=False, category_filter=())` Pulls all flashed messages from the session and returns them. Further calls in the same request to the function will return the same messages. By default just the messages are returned, but when `with_categories` is set to `True`, the return value will be a list of tuples in the form `(category, message)` instead. Filter the flashed messages to one or more categories by providing those categories in `category_filter`. This allows rendering categories in separate html blocks. The `with_categories` and `category_filter` arguments are distinct: * `with_categories` controls whether categories are returned with message text (`True` gives a tuple, where `False` gives just the message text). * `category_filter` filters the messages down to only those matching the provided categories. See [Message Flashing](../patterns/flashing/index) for examples. Changelog Changed in version 0.9: `category_filter` parameter added. Changed in version 0.3: `with_categories` parameter added. Parameters * **with\_categories** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – set to `True` to also receive categories. * **category\_filter** ([Iterable](https://docs.python.org/3/library/typing.html#typing.Iterable "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – filter of categories to limit return values. Only categories in the list will be returned. Return type [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")]]] JSON Support ------------ Flask uses Python’s built-in [`json`](https://docs.python.org/3/library/json.html#module-json "(in Python v3.10)") module for handling JSON by default. The JSON implementation can be changed by assigning a different provider to [`flask.Flask.json_provider_class`](#flask.Flask.json_provider_class "flask.Flask.json_provider_class") or [`flask.Flask.json`](#flask.Flask.json "flask.Flask.json"). The functions provided by `flask.json` will use methods on `app.json` if an app context is active. Jinja’s `|tojson` filter is configured to use the app’s JSON provider. The filter marks the output with `|safe`. Use it to render data inside HTML `<script>` tags. ``` <script> const names = {{ names|tosjon }}; renderChart(names, {{ axis_data|tojson }}); </script> ``` `flask.json.jsonify(*args, **kwargs)` Serialize the given arguments as JSON, and return a [`Response`](#flask.Response "flask.Response") object with the `application/json` mimetype. A dict or list returned from a view will be converted to a JSON response automatically without needing to call this. This requires an active request or application context, and calls [`app.json.response()`](#flask.json.provider.JSONProvider.response "flask.json.provider.JSONProvider.response"). In debug mode, the output is formatted with indentation to make it easier to read. This may also be controlled by the provider. Either positional or keyword arguments can be given, not both. If no arguments are given, `None` is serialized. Parameters * **args** (*t.Any*) – A single value to serialize, or multiple values to treat as a list to serialize. * **kwargs** (*t.Any*) – Treat as a dict to serialize. Return type [Response](#flask.Response "flask.Response") Changed in version 2.2: Calls `current_app.json.response`, allowing an app to override the behavior. Changelog Changed in version 2.0.2: [`decimal.Decimal`](https://docs.python.org/3/library/decimal.html#decimal.Decimal "(in Python v3.10)") is supported by converting to a string. Changed in version 0.11: Added support for serializing top-level arrays. This was a security risk in ancient browsers. See [JSON Security](../security/index#security-json). New in version 0.2. `flask.json.dumps(obj, *, app=None, **kwargs)` Serialize data as JSON. If [`current_app`](#flask.current_app "flask.current_app") is available, it will use its [`app.json.dumps()`](#flask.json.provider.JSONProvider.dumps "flask.json.provider.JSONProvider.dumps") method, otherwise it will use [`json.dumps()`](https://docs.python.org/3/library/json.html#json.dumps "(in Python v3.10)"). Parameters * **obj** (*t.Any*) – The data to serialize. * **kwargs** (*t.Any*) – Arguments passed to the `dumps` implementation. * **app** ([Flask](#flask.Flask "flask.Flask") *|* *None*) – Return type [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") Changed in version 2.2: Calls `current_app.json.dumps`, allowing an app to override the behavior. Changed in version 2.2: The `app` parameter will be removed in Flask 2.3. Changelog Changed in version 2.0.2: [`decimal.Decimal`](https://docs.python.org/3/library/decimal.html#decimal.Decimal "(in Python v3.10)") is supported by converting to a string. Changed in version 2.0: `encoding` will be removed in Flask 2.1. Changed in version 1.0.3: `app` can be passed directly, rather than requiring an app context for configuration. `flask.json.dump(obj, fp, *, app=None, **kwargs)` Serialize data as JSON and write to a file. If [`current_app`](#flask.current_app "flask.current_app") is available, it will use its [`app.json.dump()`](#flask.json.provider.JSONProvider.dump "flask.json.provider.JSONProvider.dump") method, otherwise it will use [`json.dump()`](https://docs.python.org/3/library/json.html#json.dump "(in Python v3.10)"). Parameters * **obj** (*t.Any*) – The data to serialize. * **fp** (*t.IO**[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – A file opened for writing text. Should use the UTF-8 encoding to be valid JSON. * **kwargs** (*t.Any*) – Arguments passed to the `dump` implementation. * **app** ([Flask](#flask.Flask "flask.Flask") *|* *None*) – Return type None Changed in version 2.2: Calls `current_app.json.dump`, allowing an app to override the behavior. Changed in version 2.2: The `app` parameter will be removed in Flask 2.3. Changelog Changed in version 2.0: Writing to a binary file, and the `encoding` argument, will be removed in Flask 2.1. `flask.json.loads(s, *, app=None, **kwargs)` Deserialize data as JSON. If [`current_app`](#flask.current_app "flask.current_app") is available, it will use its [`app.json.loads()`](#flask.json.provider.JSONProvider.loads "flask.json.provider.JSONProvider.loads") method, otherwise it will use [`json.loads()`](https://docs.python.org/3/library/json.html#json.loads "(in Python v3.10)"). Parameters * **s** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") *|* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")) – Text or UTF-8 bytes. * **kwargs** (*t.Any*) – Arguments passed to the `loads` implementation. * **app** ([Flask](#flask.Flask "flask.Flask") *|* *None*) – Return type t.Any Changed in version 2.2: Calls `current_app.json.loads`, allowing an app to override the behavior. Changed in version 2.2: The `app` parameter will be removed in Flask 2.3. Changelog Changed in version 2.0: `encoding` will be removed in Flask 2.1. The data must be a string or UTF-8 bytes. Changed in version 1.0.3: `app` can be passed directly, rather than requiring an app context for configuration. `flask.json.load(fp, *, app=None, **kwargs)` Deserialize data as JSON read from a file. If [`current_app`](#flask.current_app "flask.current_app") is available, it will use its [`app.json.load()`](#flask.json.provider.JSONProvider.load "flask.json.provider.JSONProvider.load") method, otherwise it will use [`json.load()`](https://docs.python.org/3/library/json.html#json.load "(in Python v3.10)"). Parameters * **fp** (*t.IO**[**t.AnyStr**]*) – A file opened for reading text or UTF-8 bytes. * **kwargs** (*t.Any*) – Arguments passed to the `load` implementation. * **app** ([Flask](#flask.Flask "flask.Flask") *|* *None*) – Return type t.Any Changed in version 2.2: Calls `current_app.json.load`, allowing an app to override the behavior. Changed in version 2.2: The `app` parameter will be removed in Flask 2.3. Changelog Changed in version 2.0: `encoding` will be removed in Flask 2.1. The file must be text mode, or binary mode with UTF-8 bytes. `class flask.json.provider.JSONProvider(app)` A standard set of JSON operations for an application. Subclasses of this can be used to customize JSON behavior or use different JSON libraries. To implement a provider for a specific library, subclass this base class and implement at least [`dumps()`](#flask.json.provider.JSONProvider.dumps "flask.json.provider.JSONProvider.dumps") and [`loads()`](#flask.json.provider.JSONProvider.loads "flask.json.provider.JSONProvider.loads"). All other methods have default implementations. To use a different provider, either subclass `Flask` and set [`json_provider_class`](#flask.Flask.json_provider_class "flask.Flask.json_provider_class") to a provider class, or set [`app.json`](#flask.Flask.json "flask.Flask.json") to an instance of the class. Parameters **app** ([Flask](#flask.Flask "flask.Flask")) – An application instance. This will be stored as a `weakref.proxy` on the `_app` attribute. Return type None New in version 2.2. `dumps(obj, **kwargs)` Serialize data as JSON. Parameters * **obj** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – The data to serialize. * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – May be passed to the underlying JSON library. Return type [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") `dump(obj, fp, **kwargs)` Serialize data as JSON and write to a file. Parameters * **obj** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – The data to serialize. * **fp** ([IO](https://docs.python.org/3/library/typing.html#typing.IO "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – A file opened for writing text. Should use the UTF-8 encoding to be valid JSON. * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – May be passed to the underlying JSON library. Return type None `loads(s, **kwargs)` Deserialize data as JSON. Parameters * **s** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") *|* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")) – Text or UTF-8 bytes. * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – May be passed to the underlying JSON library. Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") `load(fp, **kwargs)` Deserialize data as JSON read from a file. Parameters * **fp** ([IO](https://docs.python.org/3/library/typing.html#typing.IO "(in Python v3.10)")) – A file opened for reading text or UTF-8 bytes. * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – May be passed to the underlying JSON library. Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") `response(*args, **kwargs)` Serialize the given arguments as JSON, and return a [`Response`](#flask.Response "flask.Response") object with the `application/json` mimetype. The [`jsonify()`](#flask.json.jsonify "flask.json.jsonify") function calls this method for the current application. Either positional or keyword arguments can be given, not both. If no arguments are given, `None` is serialized. Parameters * **args** (*t.Any*) – A single value to serialize, or multiple values to treat as a list to serialize. * **kwargs** (*t.Any*) – Treat as a dict to serialize. Return type [Response](#flask.Response "flask.Response") `class flask.json.provider.DefaultJSONProvider(app)` Provide JSON operations using Python’s built-in [`json`](https://docs.python.org/3/library/json.html#module-json "(in Python v3.10)") library. Serializes the following additional data types: * [`datetime.datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime "(in Python v3.10)") and [`datetime.date`](https://docs.python.org/3/library/datetime.html#datetime.date "(in Python v3.10)") are serialized to [**RFC 822**](https://datatracker.ietf.org/doc/html/rfc822.html) strings. This is the same as the HTTP date format. * [`uuid.UUID`](https://docs.python.org/3/library/uuid.html#uuid.UUID "(in Python v3.10)") is serialized to a string. * `dataclasses.dataclass` is passed to [`dataclasses.asdict()`](https://docs.python.org/3/library/dataclasses.html#dataclasses.asdict "(in Python v3.10)"). * [`Markup`](#flask.Markup "markupsafe.Markup") (or any object with a `__html__` method) will call the `__html__` method to get a string. Parameters **app** ([Flask](#flask.Flask "flask.Flask")) – Return type None `static default(o)` Apply this function to any object that `json.dumps()` does not know how to serialize. It should return a valid JSON type or raise a `TypeError`. Parameters **o** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") `ensure_ascii = True` Replace non-ASCII characters with escape sequences. This may be more compatible with some clients, but can be disabled for better performance and size. `sort_keys = True` Sort the keys in any serialized dicts. This may be useful for some caching situations, but can be disabled for better performance. When enabled, keys must all be strings, they are not converted before sorting. `compact: bool | None = None` If `True`, or `None` out of debug mode, the [`response()`](#flask.json.provider.DefaultJSONProvider.response "flask.json.provider.DefaultJSONProvider.response") output will not add indentation, newlines, or spaces. If `False`, or `None` in debug mode, it will use a non-compact representation. `mimetype = 'application/json'` The mimetype set in [`response()`](#flask.json.provider.DefaultJSONProvider.response "flask.json.provider.DefaultJSONProvider.response"). `dumps(obj, **kwargs)` Serialize data as JSON to a string. Keyword arguments are passed to [`json.dumps()`](https://docs.python.org/3/library/json.html#json.dumps "(in Python v3.10)"). Sets some parameter defaults from the [`default`](#flask.json.provider.DefaultJSONProvider.default "flask.json.provider.DefaultJSONProvider.default"), [`ensure_ascii`](#flask.json.provider.DefaultJSONProvider.ensure_ascii "flask.json.provider.DefaultJSONProvider.ensure_ascii"), and [`sort_keys`](#flask.json.provider.DefaultJSONProvider.sort_keys "flask.json.provider.DefaultJSONProvider.sort_keys") attributes. Parameters * **obj** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – The data to serialize. * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Passed to [`json.dumps()`](https://docs.python.org/3/library/json.html#json.dumps "(in Python v3.10)"). Return type [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") `loads(s, **kwargs)` Deserialize data as JSON from a string or bytes. Parameters * **s** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") *|* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")) – Text or UTF-8 bytes. * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Passed to [`json.loads()`](https://docs.python.org/3/library/json.html#json.loads "(in Python v3.10)"). Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") `response(*args, **kwargs)` Serialize the given arguments as JSON, and return a [`Response`](#flask.Response "flask.Response") object with it. The response mimetype will be “application/json” and can be changed with [`mimetype`](#flask.json.provider.DefaultJSONProvider.mimetype "flask.json.provider.DefaultJSONProvider.mimetype"). If [`compact`](#flask.json.provider.DefaultJSONProvider.compact "flask.json.provider.DefaultJSONProvider.compact") is `False` or debug mode is enabled, the output will be formatted to be easier to read. Either positional or keyword arguments can be given, not both. If no arguments are given, `None` is serialized. Parameters * **args** (*t.Any*) – A single value to serialize, or multiple values to treat as a list to serialize. * **kwargs** (*t.Any*) – Treat as a dict to serialize. Return type [Response](#flask.Response "flask.Response") `class flask.json.JSONEncoder(**kwargs)` The default JSON encoder. Handles extra types compared to the built-in [`json.JSONEncoder`](https://docs.python.org/3/library/json.html#json.JSONEncoder "(in Python v3.10)"). * [`datetime.datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime "(in Python v3.10)") and [`datetime.date`](https://docs.python.org/3/library/datetime.html#datetime.date "(in Python v3.10)") are serialized to [**RFC 822**](https://datatracker.ietf.org/doc/html/rfc822.html) strings. This is the same as the HTTP date format. * [`decimal.Decimal`](https://docs.python.org/3/library/decimal.html#decimal.Decimal "(in Python v3.10)") is serialized to a string. * [`uuid.UUID`](https://docs.python.org/3/library/uuid.html#uuid.UUID "(in Python v3.10)") is serialized to a string. * `dataclasses.dataclass` is passed to [`dataclasses.asdict()`](https://docs.python.org/3/library/dataclasses.html#dataclasses.asdict "(in Python v3.10)"). * [`Markup`](#flask.Markup "markupsafe.Markup") (or any object with a `__html__` method) will call the `__html__` method to get a string. Assign a subclass of this to [`flask.Flask.json_encoder`](#flask.Flask.json_encoder "flask.Flask.json_encoder") or [`flask.Blueprint.json_encoder`](#flask.Blueprint.json_encoder "flask.Blueprint.json_encoder") to override the default. Deprecated since version 2.2: Will be removed in Flask 2.3. Use `app.json` instead. Return type None `default(o)` Convert `o` to a JSON serializable type. See [`json.JSONEncoder.default()`](https://docs.python.org/3/library/json.html#json.JSONEncoder.default "(in Python v3.10)"). Python does not support overriding how basic types like `str` or `list` are serialized, they are handled before this method. Parameters **o** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") `class flask.json.JSONDecoder(**kwargs)` The default JSON decoder. This does not change any behavior from the built-in [`json.JSONDecoder`](https://docs.python.org/3/library/json.html#json.JSONDecoder "(in Python v3.10)"). Assign a subclass of this to [`flask.Flask.json_decoder`](#flask.Flask.json_decoder "flask.Flask.json_decoder") or [`flask.Blueprint.json_decoder`](#flask.Blueprint.json_decoder "flask.Blueprint.json_decoder") to override the default. Deprecated since version 2.2: Will be removed in Flask 2.3. Use `app.json` instead. Return type None ### Tagged JSON A compact representation for lossless serialization of non-standard JSON types. [`SecureCookieSessionInterface`](#flask.sessions.SecureCookieSessionInterface "flask.sessions.SecureCookieSessionInterface") uses this to serialize the session data, but it may be useful in other places. It can be extended to support other types. `class flask.json.tag.TaggedJSONSerializer` Serializer that uses a tag system to compactly represent objects that are not JSON types. Passed as the intermediate serializer to `itsdangerous.Serializer`. The following extra types are supported: * [`dict`](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.10)") * [`tuple`](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.10)") * [`bytes`](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)") * [`Markup`](#flask.Markup "markupsafe.Markup") * [`UUID`](https://docs.python.org/3/library/uuid.html#uuid.UUID "(in Python v3.10)") * [`datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime "(in Python v3.10)") Return type None `default_tags = [<class 'flask.json.tag.TagDict'>, <class 'flask.json.tag.PassDict'>, <class 'flask.json.tag.TagTuple'>, <class 'flask.json.tag.PassList'>, <class 'flask.json.tag.TagBytes'>, <class 'flask.json.tag.TagMarkup'>, <class 'flask.json.tag.TagUUID'>, <class 'flask.json.tag.TagDateTime'>]` Tag classes to bind when creating the serializer. Other tags can be added later using [`register()`](#flask.json.tag.TaggedJSONSerializer.register "flask.json.tag.TaggedJSONSerializer.register"). `dumps(value)` Tag the value and dump it to a compact JSON string. Parameters **value** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") `loads(value)` Load data from a JSON string and deserialized any tagged objects. Parameters **value** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") `register(tag_class, force=False, index=None)` Register a new tag with this serializer. Parameters * **tag\_class** ([Type](https://docs.python.org/3/library/typing.html#typing.Type "(in Python v3.10)")*[*[flask.json.tag.JSONTag](#flask.json.tag.JSONTag "flask.json.tag.JSONTag")*]*) – tag class to register. Will be instantiated with this serializer instance. * **force** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – overwrite an existing tag. If false (default), a [`KeyError`](https://docs.python.org/3/library/exceptions.html#KeyError "(in Python v3.10)") is raised. * **index** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")*]*) – index to insert the new tag in the tag order. Useful when the new tag is a special case of an existing tag. If `None` (default), the tag is appended to the end of the order. Raises [**KeyError**](https://docs.python.org/3/library/exceptions.html#KeyError "(in Python v3.10)") – if the tag key is already registered and `force` is not true. Return type None `tag(value)` Convert a value to a tagged representation if necessary. Parameters **value** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Dict](https://docs.python.org/3/library/typing.html#typing.Dict "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")] `untag(value)` Convert a tagged representation back to the original type. Parameters **value** ([Dict](https://docs.python.org/3/library/typing.html#typing.Dict "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]*) – Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") `class flask.json.tag.JSONTag(serializer)` Base class for defining type tags for [`TaggedJSONSerializer`](#flask.json.tag.TaggedJSONSerializer "flask.json.tag.TaggedJSONSerializer"). Parameters **serializer** ([TaggedJSONSerializer](#flask.json.tag.TaggedJSONSerializer "flask.json.tag.TaggedJSONSerializer")) – Return type None `check(value)` Check if the given value should be tagged by this tag. Parameters **value** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)") `key: Optional[str] = None` The tag to mark the serialized object with. If `None`, this tag is only used as an intermediate step during tagging. `tag(value)` Convert the value to a valid JSON type and add the tag structure around it. Parameters **value** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") `to_json(value)` Convert the Python object to an object that is a valid JSON type. The tag will be added later. Parameters **value** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") `to_python(value)` Convert the JSON representation back to the correct type. The tag will already be removed. Parameters **value** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") Let’s see an example that adds support for [`OrderedDict`](https://docs.python.org/3/library/collections.html#collections.OrderedDict "(in Python v3.10)"). Dicts don’t have an order in JSON, so to handle this we will dump the items as a list of `[key, value]` pairs. Subclass [`JSONTag`](#flask.json.tag.JSONTag "flask.json.tag.JSONTag") and give it the new key `' od'` to identify the type. The session serializer processes dicts first, so insert the new tag at the front of the order since `OrderedDict` must be processed before `dict`. ``` from flask.json.tag import JSONTag class TagOrderedDict(JSONTag): __slots__ = ('serializer',) key = ' od' def check(self, value): return isinstance(value, OrderedDict) def to_json(self, value): return [[k, self.serializer.tag(v)] for k, v in iteritems(value)] def to_python(self, value): return OrderedDict(value) app.session_interface.serializer.register(TagOrderedDict, index=0) ``` Template Rendering ------------------ `flask.render_template(template_name_or_list, **context)` Render a template by name with the given context. Parameters * **template\_name\_or\_list** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [jinja2.environment.Template](https://jinja.palletsprojects.com/en/3.1.x/api/#jinja2.Template "(in Jinja v3.1.x)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [jinja2.environment.Template](https://jinja.palletsprojects.com/en/3.1.x/api/#jinja2.Template "(in Jinja v3.1.x)")*]**]**]*) – The name of the template to render. If a list is given, the first name to exist will be rendered. * **context** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – The variables to make available in the template. Return type [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") `flask.render_template_string(source, **context)` Render a template from the given source string with the given context. Parameters * **source** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – The source code of the template to render. * **context** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – The variables to make available in the template. Return type [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") `flask.stream_template(template_name_or_list, **context)` Render a template by name with the given context as a stream. This returns an iterator of strings, which can be used as a streaming response from a view. Parameters * **template\_name\_or\_list** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [jinja2.environment.Template](https://jinja.palletsprojects.com/en/3.1.x/api/#jinja2.Template "(in Jinja v3.1.x)")*,* [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [jinja2.environment.Template](https://jinja.palletsprojects.com/en/3.1.x/api/#jinja2.Template "(in Jinja v3.1.x)")*]**]**]*) – The name of the template to render. If a list is given, the first name to exist will be rendered. * **context** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – The variables to make available in the template. Return type [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")] New in version 2.2. `flask.stream_template_string(source, **context)` Render a template from the given source string with the given context as a stream. This returns an iterator of strings, which can be used as a streaming response from a view. Parameters * **source** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – The source code of the template to render. * **context** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – The variables to make available in the template. Return type [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")] New in version 2.2. `flask.get_template_attribute(template_name, attribute)` Loads a macro (or variable) a template exports. This can be used to invoke a macro from within Python code. If you for example have a template named `_cider.html` with the following contents: ``` {% macro hello(name) %}Hello {{ name }}!{% endmacro %} ``` You can access this from Python code like this: ``` hello = get_template_attribute('_cider.html', 'hello') return hello('World') ``` Changelog New in version 0.2. Parameters * **template\_name** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – the name of the template * **attribute** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – the name of the variable of macro to access Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") Configuration ------------- `class flask.Config(root_path, defaults=None)` Works exactly like a dict but provides ways to fill it from files or special dictionaries. There are two common patterns to populate the config. Either you can fill the config from a config file: ``` app.config.from_pyfile('yourconfig.cfg') ``` Or alternatively you can define the configuration options in the module that calls [`from_object()`](#flask.Config.from_object "flask.Config.from_object") or provide an import path to a module that should be loaded. It is also possible to tell it to use the same module and with that provide the configuration values just before the call: ``` DEBUG = True SECRET_KEY = 'development key' app.config.from_object(__name__) ``` In both cases (loading from any Python file or loading from modules), only uppercase keys are added to the config. This makes it possible to use lowercase values in the config file for temporary values that are not added to the config or to define the config keys in the same file that implements the application. Probably the most interesting way to load configurations is from an environment variable pointing to a file: ``` app.config.from_envvar('YOURAPPLICATION_SETTINGS') ``` In this case before launching the application you have to set this environment variable to the file you want to use. On Linux and OS X use the export statement: ``` export YOURAPPLICATION_SETTINGS='/path/to/config/file' ``` On windows use `set` instead. Parameters * **root\_path** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – path to which files are read relative from. When the config object is created by the application, this is the application’s [`root_path`](#flask.Flask.root_path "flask.Flask.root_path"). * **defaults** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.10)")*]*) – an optional dictionary of default values Return type None `from_envvar(variable_name, silent=False)` Loads a configuration from an environment variable pointing to a configuration file. This is basically just a shortcut with nicer error messages for this line of code: ``` app.config.from_pyfile(os.environ['YOURAPPLICATION_SETTINGS']) ``` Parameters * **variable\_name** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – name of the environment variable * **silent** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – set to `True` if you want silent failure for missing files. Returns `True` if the file was loaded successfully. Return type [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)") `from_file(filename, load, silent=False)` Update the values in the config from a file that is loaded using the `load` parameter. The loaded data is passed to the [`from_mapping()`](#flask.Config.from_mapping "flask.Config.from_mapping") method. ``` import json app.config.from_file("config.json", load=json.load) import toml app.config.from_file("config.toml", load=toml.load) ``` Parameters * **filename** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – The path to the data file. This can be an absolute path or relative to the config root path. * **load** (`Callable[[Reader], Mapping]` where `Reader` implements a `read` method.) – A callable that takes a file handle and returns a mapping of loaded data from the file. * **silent** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Ignore the file if it doesn’t exist. Returns `True` if the file was loaded successfully. Return type [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)") Changelog New in version 2.0. `from_mapping(mapping=None, **kwargs)` Updates the config like `update()` ignoring items with non-upper keys. Returns Always returns `True`. Parameters * **mapping** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]**]*) – * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)") Changelog New in version 0.11. `from_object(obj)` Updates the values from the given object. An object can be of one of the following two types: * a string: in this case the object with that name will be imported * an actual object reference: that object is used directly Objects are usually either modules or classes. [`from_object()`](#flask.Config.from_object "flask.Config.from_object") loads only the uppercase attributes of the module/class. A `dict` object will not work with [`from_object()`](#flask.Config.from_object "flask.Config.from_object") because the keys of a `dict` are not attributes of the `dict` class. Example of module-based configuration: ``` app.config.from_object('yourapplication.default_config') from yourapplication import default_config app.config.from_object(default_config) ``` Nothing is done to the object before loading. If the object is a class and has `@property` attributes, it needs to be instantiated before being passed to this method. You should not use this function to load the actual configuration but rather configuration defaults. The actual config should be loaded with [`from_pyfile()`](#flask.Config.from_pyfile "flask.Config.from_pyfile") and ideally from a location not within the package because the package might be installed system wide. See [Development / Production](../config/index#config-dev-prod) for an example of class-based configuration using [`from_object()`](#flask.Config.from_object "flask.Config.from_object"). Parameters **obj** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[object](https://docs.python.org/3/library/functions.html#object "(in Python v3.10)")*,* [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – an import name or object Return type None `from_prefixed_env(prefix='FLASK', *, loads=<function loads>)` Load any environment variables that start with `FLASK_`, dropping the prefix from the env key for the config key. Values are passed through a loading function to attempt to convert them to more specific types than strings. Keys are loaded in [`sorted()`](https://docs.python.org/3/library/functions.html#sorted "(in Python v3.10)") order. The default loading function attempts to parse values as any valid JSON type, including dicts and lists. Specific items in nested dicts can be set by separating the keys with double underscores (`__`). If an intermediate key doesn’t exist, it will be initialized to an empty dict. Parameters * **prefix** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – Load env vars that start with this prefix, separated with an underscore (`_`). * **loads** ([Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]**,* [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")*]*) – Pass each string value to this function and use the returned value as the config value. If any error is raised it is ignored and the value remains a string. The default is [`json.loads()`](#flask.json.loads "flask.json.loads"). Return type [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)") Changelog New in version 2.1. `from_pyfile(filename, silent=False)` Updates the values in the config from a Python file. This function behaves as if the file was imported as module with the [`from_object()`](#flask.Config.from_object "flask.Config.from_object") function. Parameters * **filename** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – the filename of the config. This can either be an absolute filename or a filename relative to the root path. * **silent** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – set to `True` if you want silent failure for missing files. Returns `True` if the file was loaded successfully. Return type [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)") Changelog New in version 0.7: `silent` parameter. `get_namespace(namespace, lowercase=True, trim_namespace=True)` Returns a dictionary containing a subset of configuration options that match the specified namespace/prefix. Example usage: ``` app.config['IMAGE_STORE_TYPE'] = 'fs' app.config['IMAGE_STORE_PATH'] = '/var/app/images' app.config['IMAGE_STORE_BASE_URL'] = 'http://img.website.com' image_store_config = app.config.get_namespace('IMAGE_STORE_') ``` The resulting dictionary `image_store_config` would look like: ``` { 'type': 'fs', 'path': '/var/app/images', 'base_url': 'http://img.website.com' } ``` This is often useful when configuration options map directly to keyword arguments in functions or class constructors. Parameters * **namespace** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – a configuration namespace * **lowercase** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – a flag indicating if the keys of the resulting dictionary should be lowercase * **trim\_namespace** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – a flag indicating if the keys of the resulting dictionary should not include the namespace Return type [Dict](https://docs.python.org/3/library/typing.html#typing.Dict "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")] Changelog New in version 0.11. Stream Helpers -------------- `flask.stream_with_context(generator_or_function)` Request contexts disappear when the response is started on the server. This is done for efficiency reasons and to make it less likely to encounter memory leaks with badly written WSGI middlewares. The downside is that if you are using streamed responses, the generator cannot access request bound information any more. This function however can help you keep the context around for longer: ``` from flask import stream_with_context, request, Response @app.route('/stream') def streamed_response(): @stream_with_context def generate(): yield 'Hello ' yield request.args['name'] yield '!' return Response(generate()) ``` Alternatively it can also be used around a specific generator: ``` from flask import stream_with_context, request, Response @app.route('/stream') def streamed_response(): def generate(): yield 'Hello ' yield request.args['name'] yield '!' return Response(stream_with_context(generate())) ``` Changelog New in version 0.9. Parameters **generator\_or\_function** ([Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*,* [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*[**[**...**]**,* [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")*]**]*) – Return type [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)") Useful Internals ---------------- `class flask.ctx.RequestContext(app, environ, request=None, session=None)` The request context contains per-request information. The Flask app creates and pushes it at the beginning of the request, then pops it at the end of the request. It will create the URL adapter and request object for the WSGI environment provided. Do not attempt to use this class directly, instead use [`test_request_context()`](#flask.Flask.test_request_context "flask.Flask.test_request_context") and [`request_context()`](#flask.Flask.request_context "flask.Flask.request_context") to create this object. When the request context is popped, it will evaluate all the functions registered on the application for teardown execution ([`teardown_request()`](#flask.Flask.teardown_request "flask.Flask.teardown_request")). The request context is automatically popped at the end of the request. When using the interactive debugger, the context will be restored so `request` is still accessible. Similarly, the test client can preserve the context after the request ends. However, teardown functions may already have closed some resources such as database connections. Parameters * **app** ([Flask](#flask.Flask "flask.Flask")) – * **environ** ([dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.10)")) – * **request** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Request](#flask.Request "flask.Request")*]*) – * **session** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[SessionMixin](#flask.sessions.SessionMixin "flask.sessions.SessionMixin")*]*) – Return type None `copy()` Creates a copy of this request context with the same request object. This can be used to move a request context to a different greenlet. Because the actual request object is the same this cannot be used to move a request context to a different thread unless access to the request object is locked. Changelog Changed in version 1.1: The current session object is used instead of reloading the original data. This prevents `flask.session` pointing to an out-of-date object. New in version 0.10. Return type [flask.ctx.RequestContext](#flask.ctx.RequestContext "flask.ctx.RequestContext") `match_request()` Can be overridden by a subclass to hook into the matching of the request. Return type None `pop(exc=<object object>)` Pops the request context and unbinds it by doing that. This will also trigger the execution of functions registered by the [`teardown_request()`](#flask.Flask.teardown_request "flask.Flask.teardown_request") decorator. Changelog Changed in version 0.9: Added the `exc` argument. Parameters **exc** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[BaseException](https://docs.python.org/3/library/exceptions.html#BaseException "(in Python v3.10)")*]*) – Return type None `flask.globals.request_ctx` The current [`RequestContext`](#flask.ctx.RequestContext "flask.ctx.RequestContext"). If a request context is not active, accessing attributes on this proxy will raise a `RuntimeError`. This is an internal object that is essential to how Flask handles requests. Accessing this should not be needed in most cases. Most likely you want [`request`](#flask.request "flask.request") and [`session`](#flask.session "flask.session") instead. `class flask.ctx.AppContext(app)` The app context contains application-specific information. An app context is created and pushed at the beginning of each request if one is not already active. An app context is also pushed when running CLI commands. Parameters **app** ([Flask](#flask.Flask "flask.Flask")) – Return type None `pop(exc=<object object>)` Pops the app context. Parameters **exc** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[BaseException](https://docs.python.org/3/library/exceptions.html#BaseException "(in Python v3.10)")*]*) – Return type None `push()` Binds the app context to the current context. Return type None `flask.globals.app_ctx` The current [`AppContext`](#flask.ctx.AppContext "flask.ctx.AppContext"). If an app context is not active, accessing attributes on this proxy will raise a `RuntimeError`. This is an internal object that is essential to how Flask handles requests. Accessing this should not be needed in most cases. Most likely you want [`current_app`](#flask.current_app "flask.current_app") and [`g`](#flask.g "flask.g") instead. `class flask.blueprints.BlueprintSetupState(blueprint, app, options, first_registration)` Temporary holder object for registering a blueprint with the application. An instance of this class is created by the [`make_setup_state()`](#flask.Blueprint.make_setup_state "flask.Blueprint.make_setup_state") method and later passed to all register callback functions. Parameters * **blueprint** ([Blueprint](#flask.Blueprint "flask.blueprints.Blueprint")) – * **app** ([Flask](#flask.Flask "flask.Flask")) – * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – * **first\_registration** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Return type None `add_url_rule(rule, endpoint=None, view_func=None, **options)` A helper method to register a rule (and optionally a view function) to the application. The endpoint is automatically prefixed with the blueprint’s name. Parameters * **rule** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – * **endpoint** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – * **view\_func** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")*]*) – * **options** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type None `app` a reference to the current application `blueprint` a reference to the blueprint that created this setup state. `first_registration` as blueprints can be registered multiple times with the application and not everything wants to be registered multiple times on it, this attribute can be used to figure out if the blueprint was registered in the past already. `options` a dictionary with all options that were passed to the [`register_blueprint()`](#flask.Flask.register_blueprint "flask.Flask.register_blueprint") method. `subdomain` The subdomain that the blueprint should be active for, `None` otherwise. `url_defaults` A dictionary with URL defaults that is added to each and every URL that was defined with the blueprint. `url_prefix` The prefix that should be used for all URLs defined on the blueprint. Signals ------- Changelog New in version 0.6. `signals.signals_available` `True` if the signaling system is available. This is the case when [blinker](https://pypi.org/project/blinker/) is installed. The following signals exist in Flask: `flask.template_rendered` This signal is sent when a template was successfully rendered. The signal is invoked with the instance of the template as `template` and the context as dictionary (named `context`). Example subscriber: ``` def log_template_renders(sender, template, context, **extra): sender.logger.debug('Rendering template "%s" with context %s', template.name or 'string template', context) from flask import template_rendered template_rendered.connect(log_template_renders, app) ``` flask.before\_render\_template This signal is sent before template rendering process. The signal is invoked with the instance of the template as `template` and the context as dictionary (named `context`). Example subscriber: ``` def log_template_renders(sender, template, context, **extra): sender.logger.debug('Rendering template "%s" with context %s', template.name or 'string template', context) from flask import before_render_template before_render_template.connect(log_template_renders, app) ``` `flask.request_started` This signal is sent when the request context is set up, before any request processing happens. Because the request context is already bound, the subscriber can access the request with the standard global proxies such as [`request`](#flask.request "flask.request"). Example subscriber: ``` def log_request(sender, **extra): sender.logger.debug('Request context is set up') from flask import request_started request_started.connect(log_request, app) ``` `flask.request_finished` This signal is sent right before the response is sent to the client. It is passed the response to be sent named `response`. Example subscriber: ``` def log_response(sender, response, **extra): sender.logger.debug('Request context is about to close down. ' 'Response: %s', response) from flask import request_finished request_finished.connect(log_response, app) ``` `flask.got_request_exception` This signal is sent when an unhandled exception happens during request processing, including when debugging. The exception is passed to the subscriber as `exception`. This signal is not sent for [`HTTPException`](https://werkzeug.palletsprojects.com/en/2.2.x/exceptions/#werkzeug.exceptions.HTTPException "(in Werkzeug v2.2.x)"), or other exceptions that have error handlers registered, unless the exception was raised from an error handler. This example shows how to do some extra logging if a theoretical `SecurityException` was raised: ``` from flask import got_request_exception def log_security_exception(sender, exception, **extra): if not isinstance(exception, SecurityException): return security_logger.exception( f"SecurityException at {request.url!r}", exc_info=exception, ) got_request_exception.connect(log_security_exception, app) ``` `flask.request_tearing_down` This signal is sent when the request is tearing down. This is always called, even if an exception is caused. Currently functions listening to this signal are called after the regular teardown handlers, but this is not something you can rely on. Example subscriber: ``` def close_db_connection(sender, **extra): session.close() from flask import request_tearing_down request_tearing_down.connect(close_db_connection, app) ``` As of Flask 0.9, this will also be passed an `exc` keyword argument that has a reference to the exception that caused the teardown if there was one. `flask.appcontext_tearing_down` This signal is sent when the app context is tearing down. This is always called, even if an exception is caused. Currently functions listening to this signal are called after the regular teardown handlers, but this is not something you can rely on. Example subscriber: ``` def close_db_connection(sender, **extra): session.close() from flask import appcontext_tearing_down appcontext_tearing_down.connect(close_db_connection, app) ``` This will also be passed an `exc` keyword argument that has a reference to the exception that caused the teardown if there was one. `flask.appcontext_pushed` This signal is sent when an application context is pushed. The sender is the application. This is usually useful for unittests in order to temporarily hook in information. For instance it can be used to set a resource early onto the `g` object. Example usage: ``` from contextlib import contextmanager from flask import appcontext_pushed @contextmanager def user_set(app, user): def handler(sender, **kwargs): g.user = user with appcontext_pushed.connected_to(handler, app): yield ``` And in the testcode: ``` def test_user_me(self): with user_set(app, 'john'): c = app.test_client() resp = c.get('/users/me') assert resp.data == 'username=john' ``` Changelog New in version 0.10. `flask.appcontext_popped` This signal is sent when an application context is popped. The sender is the application. This usually falls in line with the [`appcontext_tearing_down`](#flask.appcontext_tearing_down "flask.appcontext_tearing_down") signal. Changelog New in version 0.10. `flask.message_flashed` This signal is sent when the application is flashing a message. The messages is sent as `message` keyword argument and the category as `category`. Example subscriber: ``` recorded = [] def record(sender, message, category, **extra): recorded.append((message, category)) from flask import message_flashed message_flashed.connect(record, app) ``` Changelog New in version 0.10. `class signals.Namespace` An alias for [`blinker.base.Namespace`](https://blinker.readthedocs.io/en/stable/#blinker.base.Namespace "(in Blinker v1.5)") if blinker is available, otherwise a dummy class that creates fake signals. This class is available for Flask extensions that want to provide the same fallback system as Flask itself. `signal(name, doc=None)` Creates a new signal for this namespace if blinker is available, otherwise returns a fake signal that has a send method that will do nothing but will fail with a [`RuntimeError`](https://docs.python.org/3/library/exceptions.html#RuntimeError "(in Python v3.10)") for all other operations, including connecting. Class-Based Views ----------------- Changelog New in version 0.7. `class flask.views.View` Subclass this class and override [`dispatch_request()`](#flask.views.View.dispatch_request "flask.views.View.dispatch_request") to create a generic class-based view. Call [`as_view()`](#flask.views.View.as_view "flask.views.View.as_view") to create a view function that creates an instance of the class with the given arguments and calls its `dispatch_request` method with any URL variables. See [Class-based Views](../views/index) for a detailed guide. ``` class Hello(View): init_every_request = False def dispatch_request(self, name): return f"Hello, {name}!" app.add_url_rule( "/hello/<name>", view_func=Hello.as_view("hello") ) ``` Set [`methods`](#flask.views.View.methods "flask.views.View.methods") on the class to change what methods the view accepts. Set [`decorators`](#flask.views.View.decorators "flask.views.View.decorators") on the class to apply a list of decorators to the generated view function. Decorators applied to the class itself will not be applied to the generated view function! Set [`init_every_request`](#flask.views.View.init_every_request "flask.views.View.init_every_request") to `False` for efficiency, unless you need to store request-global data on `self`. `classmethod as_view(name, *class_args, **class_kwargs)` Convert the class into a view function that can be registered for a route. By default, the generated view will create a new instance of the view class for every request and call its [`dispatch_request()`](#flask.views.View.dispatch_request "flask.views.View.dispatch_request") method. If the view class sets [`init_every_request`](#flask.views.View.init_every_request "flask.views.View.init_every_request") to `False`, the same instance will be used for every request. The arguments passed to this method are forwarded to the view class `__init__` method. Changed in version 2.2: Added the `init_every_request` class attribute. Parameters * **name** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")) – * **class\_args** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – * **class\_kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[…], [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[Headers, [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]], [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]]]]], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[Headers, [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]], [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]]]]], WSGIApplication]], [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.10)")[[…], [Awaitable](https://docs.python.org/3/library/typing.html#typing.Awaitable "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[Headers, [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]], [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]]]]], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[Headers, [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]], [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]]]]], WSGIApplication]]]] `decorators: ClassVar[List[Callable]] = []` A list of decorators to apply, in order, to the generated view function. Remember that `@decorator` syntax is applied bottom to top, so the first decorator in the list would be the bottom decorator. Changelog New in version 0.8. `dispatch_request()` The actual view function behavior. Subclasses must override this and return a valid response. Any variables from the URL rule are passed as keyword arguments. Return type [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[Headers, [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]], [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]]]]], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[Headers, [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]], [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]]]]], WSGIApplication] `init_every_request: ClassVar[bool] = True` Create a new instance of this view class for every request by default. If a view subclass sets this to `False`, the same instance is used for every request. A single instance is more efficient, especially if complex setup is done during init. However, storing data on `self` is no longer safe across requests, and [`g`](#flask.g "flask.g") should be used instead. New in version 2.2. `methods: ClassVar[Optional[Collection[str]]] = None` The methods this view is registered for. Uses the same default (`["GET", "HEAD", "OPTIONS"]`) as `route` and `add_url_rule` by default. `provide_automatic_options: ClassVar[Optional[bool]] = None` Control whether the `OPTIONS` method is handled automatically. Uses the same default (`True`) as `route` and `add_url_rule` by default. `class flask.views.MethodView` Dispatches request methods to the corresponding instance methods. For example, if you implement a `get` method, it will be used to handle `GET` requests. This can be useful for defining a REST API. `methods` is automatically set based on the methods defined on the class. See [Class-based Views](../views/index) for a detailed guide. ``` class CounterAPI(MethodView): def get(self): return str(session.get("counter", 0)) def post(self): session["counter"] = session.get("counter", 0) + 1 return redirect(url_for("counter")) app.add_url_rule( "/counter", view_func=CounterAPI.as_view("counter") ) ``` `dispatch_request(**kwargs)` The actual view function behavior. Subclasses must override this and return a valid response. Any variables from the URL rule are passed as keyword arguments. Parameters **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[Headers, [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]], [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]]]]], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[Response](#flask.Response "flask.Response"), [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator "(in Python v3.10)")[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)")]], [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[Headers, [Mapping](https://docs.python.org/3/library/typing.html#typing.Mapping "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]], [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")[[Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), [List](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")], [Tuple](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)"), …]]]]]], WSGIApplication] URL Route Registrations ----------------------- Generally there are three ways to define rules for the routing system: 1. You can use the [`flask.Flask.route()`](#flask.Flask.route "flask.Flask.route") decorator. 2. You can use the [`flask.Flask.add_url_rule()`](#flask.Flask.add_url_rule "flask.Flask.add_url_rule") function. 3. You can directly access the underlying Werkzeug routing system which is exposed as [`flask.Flask.url_map`](#flask.Flask.url_map "flask.Flask.url_map"). Variable parts in the route can be specified with angular brackets (`/user/<username>`). By default a variable part in the URL accepts any string without a slash however a different converter can be specified as well by using `<converter:name>`. Variable parts are passed to the view function as keyword arguments. The following converters are available: | | | | --- | --- | | `string` | accepts any text without a slash (the default) | | `int` | accepts integers | | `float` | like `int` but for floating point values | | `path` | like the default but also accepts slashes | | `any` | matches one of the items provided | | `uuid` | accepts UUID strings | Custom converters can be defined using [`flask.Flask.url_map`](#flask.Flask.url_map "flask.Flask.url_map"). Here are some examples: ``` @app.route('/') def index(): pass @app.route('/<username>') def show_user(username): pass @app.route('/post/<int:post_id>') def show_post(post_id): pass ``` An important detail to keep in mind is how Flask deals with trailing slashes. The idea is to keep each URL unique so the following rules apply: 1. If a rule ends with a slash and is requested without a slash by the user, the user is automatically redirected to the same page with a trailing slash attached. 2. If a rule does not end with a trailing slash and the user requests the page with a trailing slash, a 404 not found is raised. This is consistent with how web servers deal with static files. This also makes it possible to use relative link targets safely. You can also define multiple rules for the same function. They have to be unique however. Defaults can also be specified. Here for example is a definition for a URL that accepts an optional page: ``` @app.route('/users/', defaults={'page': 1}) @app.route('/users/page/<int:page>') def show_users(page): pass ``` This specifies that `/users/` will be the URL for page one and `/users/page/N` will be the URL for page `N`. If a URL contains a default value, it will be redirected to its simpler form with a 301 redirect. In the above example, `/users/page/1` will be redirected to `/users/`. If your route handles `GET` and `POST` requests, make sure the default route only handles `GET`, as redirects can’t preserve form data. ``` @app.route('/region/', defaults={'id': 1}) @app.route('/region/<int:id>', methods=['GET', 'POST']) def region(id): pass ``` Here are the parameters that [`route()`](#flask.Flask.route "flask.Flask.route") and [`add_url_rule()`](#flask.Flask.add_url_rule "flask.Flask.add_url_rule") accept. The only difference is that with the route parameter the view function is defined with the decorator instead of the `view_func` parameter. | | | | --- | --- | | `rule` | the URL rule as string | | `endpoint` | the endpoint for the registered URL rule. Flask itself assumes that the name of the view function is the name of the endpoint if not explicitly stated. | | `view_func` | the function to call when serving a request to the provided endpoint. If this is not provided one can specify the function later by storing it in the [`view_functions`](#flask.Flask.view_functions "flask.Flask.view_functions") dictionary with the endpoint as key. | | `defaults` | A dictionary with defaults for this rule. See the example above for how defaults work. | | `subdomain` | specifies the rule for the subdomain in case subdomain matching is in use. If not specified the default subdomain is assumed. | | `**options` | the options to be forwarded to the underlying [`Rule`](https://werkzeug.palletsprojects.com/en/2.2.x/routing/#werkzeug.routing.Rule "(in Werkzeug v2.2.x)") object. A change to Werkzeug is handling of method options. methods is a list of methods this rule should be limited to (`GET`, `POST` etc.). By default a rule just listens for `GET` (and implicitly `HEAD`). Starting with Flask 0.6, `OPTIONS` is implicitly added and handled by the standard request handling. They have to be specified as keyword arguments. | View Function Options --------------------- For internal usage the view functions can have some attributes attached to customize behavior the view function would normally not have control over. The following attributes can be provided optionally to either override some defaults to [`add_url_rule()`](#flask.Flask.add_url_rule "flask.Flask.add_url_rule") or general behavior: * `__name__`: The name of a function is by default used as endpoint. If endpoint is provided explicitly this value is used. Additionally this will be prefixed with the name of the blueprint by default which cannot be customized from the function itself. * `methods`: If methods are not provided when the URL rule is added, Flask will look on the view function object itself if a `methods` attribute exists. If it does, it will pull the information for the methods from there. * `provide_automatic_options`: if this attribute is set Flask will either force enable or disable the automatic implementation of the HTTP `OPTIONS` response. This can be useful when working with decorators that want to customize the `OPTIONS` response on a per-view basis. * `required_methods`: if this attribute is set, Flask will always add these methods when registering a URL rule even if the methods were explicitly overridden in the `route()` call. Full example: ``` def index(): if request.method == 'OPTIONS': # custom options handling here ... return 'Hello World!' index.provide_automatic_options = False index.methods = ['GET', 'OPTIONS'] app.add_url_rule('/', index) ``` Changelog New in version 0.8: The `provide_automatic_options` functionality was added. Command Line Interface ---------------------- `class flask.cli.FlaskGroup(add_default_commands=True, create_app=None, add_version_option=True, load_dotenv=True, set_debug_flag=True, **extra)` Special subclass of the [`AppGroup`](#flask.cli.AppGroup "flask.cli.AppGroup") group that supports loading more commands from the configured Flask app. Normally a developer does not have to interface with this class but there are some very advanced use cases for which it makes sense to create an instance of this. see [Custom Scripts](../cli/index#custom-scripts). Parameters * **add\_default\_commands** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – if this is True then the default run and shell commands will be added. * **add\_version\_option** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – adds the `--version` option. * **create\_app** (*t.Callable**[**...**,* [Flask](#flask.Flask "flask.Flask")*]* *|* *None*) – an optional callback that is passed the script info and returns the loaded app. * **load\_dotenv** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Load the nearest `.env` and `.flaskenv` files to set environment variables. Will also change the working directory to the directory containing the first file found. * **set\_debug\_flag** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Set the app’s debug flag. * **extra** (*t.Any*) – Return type None Changed in version 2.2: Added the `-A/--app`, `--debug/--no-debug`, `-e/--env-file` options. Changed in version 2.2: An app context is pushed when running `app.cli` commands, so `@with_appcontext` is no longer required for those commands. Changelog Changed in version 1.0: If installed, python-dotenv will be used to load environment variables from `.env` and `.flaskenv` files. `get_command(ctx, name)` Given a context and a command name, this returns a `Command` object if it exists or returns `None`. `list_commands(ctx)` Returns a list of subcommand names in the order they should appear. `make_context(info_name, args, parent=None, **extra)` This function when given an info name and arguments will kick off the parsing and create a new `Context`. It does not invoke the actual command callback though. To quickly customize the context class used without overriding this method, set the `context_class` attribute. Parameters * **info\_name** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") *|* *None*) – the info name for this invocation. Generally this is the most descriptive name for the script or command. For the toplevel script it’s usually the name of the script, for commands below it it’s the name of the command. * **args** ([list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – the arguments to parse as list of strings. * **parent** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[click.core.Context](https://click.palletsprojects.com/en/8.1.x/api/#click.Context "(in Click v8.1.x)")*]*) – the parent context if available. * **extra** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – extra keyword arguments forwarded to the context constructor. Return type [click.core.Context](https://click.palletsprojects.com/en/8.1.x/api/#click.Context "(in Click v8.1.x)") Changed in version 8.0: Added the `context_class` attribute. `parse_args(ctx, args)` Given a context and a list of arguments this creates the parser and parses the arguments, then modifies the context as necessary. This is automatically invoked by [`make_context()`](#flask.cli.FlaskGroup.make_context "flask.cli.FlaskGroup.make_context"). Parameters * **ctx** ([click.core.Context](https://click.palletsprojects.com/en/8.1.x/api/#click.Context "(in Click v8.1.x)")) – * **args** ([list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – Return type [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.10)")[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")] `class flask.cli.AppGroup(name=None, commands=None, **attrs)` This works similar to a regular click [`Group`](https://click.palletsprojects.com/en/8.1.x/api/#click.Group "(in Click v8.1.x)") but it changes the behavior of the [`command()`](#flask.cli.AppGroup.command "flask.cli.AppGroup.command") decorator so that it automatically wraps the functions in [`with_appcontext()`](#flask.cli.with_appcontext "flask.cli.with_appcontext"). Not to be confused with [`FlaskGroup`](#flask.cli.FlaskGroup "flask.cli.FlaskGroup"). Parameters * **name** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*]*) – * **commands** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[Dict](https://docs.python.org/3/library/typing.html#typing.Dict "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [click.core.Command](https://click.palletsprojects.com/en/8.1.x/api/#click.Command "(in Click v8.1.x)")*]**,* [Sequence](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.10)")*[*[click.core.Command](https://click.palletsprojects.com/en/8.1.x/api/#click.Command "(in Click v8.1.x)")*]**]**]*) – * **attrs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type None `command(*args, **kwargs)` This works exactly like the method of the same name on a regular [`click.Group`](https://click.palletsprojects.com/en/8.1.x/api/#click.Group "(in Click v8.1.x)") but it wraps callbacks in [`with_appcontext()`](#flask.cli.with_appcontext "flask.cli.with_appcontext") unless it’s disabled by passing `with_appcontext=False`. `group(*args, **kwargs)` This works exactly like the method of the same name on a regular [`click.Group`](https://click.palletsprojects.com/en/8.1.x/api/#click.Group "(in Click v8.1.x)") but it defaults the group class to [`AppGroup`](#flask.cli.AppGroup "flask.cli.AppGroup"). `class flask.cli.ScriptInfo(app_import_path=None, create_app=None, set_debug_flag=True)` Helper object to deal with Flask applications. This is usually not necessary to interface with as it’s used internally in the dispatching to click. In future versions of Flask this object will most likely play a bigger role. Typically it’s created automatically by the [`FlaskGroup`](#flask.cli.FlaskGroup "flask.cli.FlaskGroup") but you can also manually create it and pass it onwards as click object. Parameters * **app\_import\_path** ([str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") *|* *None*) – * **create\_app** (*t.Callable**[**...**,* [Flask](#flask.Flask "flask.Flask")*]* *|* *None*) – * **set\_debug\_flag** ([bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)")) – Return type None `app_import_path` Optionally the import path for the Flask application. `create_app` Optionally a function that is passed the script info to create the instance of the application. `data: t.Dict[t.Any, t.Any]` A dictionary with arbitrary data that can be associated with this script info. `load_app()` Loads the Flask app (if not yet loaded) and returns it. Calling this multiple times will just result in the already loaded app to be returned. Return type [Flask](#flask.Flask "flask.Flask") `flask.cli.load_dotenv(path=None)` Load “dotenv” files in order of precedence to set environment variables. If an env var is already set it is not overwritten, so earlier files in the list are preferred over later files. This is a no-op if [python-dotenv](https://github.com/theskumar/python-dotenv#readme) is not installed. Parameters **path** ([Optional](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.10)")*[*[Union](https://docs.python.org/3/library/typing.html#typing.Union "(in Python v3.10)")*[*[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)")*,* [os.PathLike](https://docs.python.org/3/library/os.html#os.PathLike "(in Python v3.10)")*]**]*) – Load the file at this location instead of searching. Returns `True` if a file was loaded. Return type [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)") Changelog Changed in version 2.0: The current directory is not changed to the location of the loaded file. Changed in version 2.0: When loading the env files, set the default encoding to UTF-8. Changed in version 1.1.0: Returns `False` when python-dotenv is not installed, or when the given path isn’t a file. New in version 1.0. `flask.cli.with_appcontext(f)` Wraps a callback so that it’s guaranteed to be executed with the script’s application context. Custom commands (and their options) registered under `app.cli` or `blueprint.cli` will always have an app context available, this decorator is not required in that case. Changed in version 2.2: The app context is active for subcommands as well as the decorated callback. The app context is always available to `app.cli` command and parameter callbacks. `flask.cli.pass_script_info(f)` Marks a function so that an instance of [`ScriptInfo`](#flask.cli.ScriptInfo "flask.cli.ScriptInfo") is passed as first argument to the click callback. Parameters **f** (*click.decorators.F*) – Return type click.decorators.F `flask.cli.run_command = <Command run>` Run a local development server. This server is for development purposes only. It does not provide the stability, security, or performance of production WSGI servers. The reloader and debugger are enabled by default with the ‘–debug’ option. Parameters * **args** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)") `flask.cli.shell_command = <Command shell>` Run an interactive Python shell in the context of a given Flask application. The application will populate the default namespace of this shell according to its configuration. This is useful for executing small snippets of management code without having to manually configure the application. Parameters * **args** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – * **kwargs** ([Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")) – Return type [Any](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.10)")
programming_docs
flask Deploying to Production Deploying to Production ======================= After developing your application, you’ll want to make it available publicly to other users. When you’re developing locally, you’re probably using the built-in development server, debugger, and reloader. These should not be used in production. Instead, you should use a dedicated WSGI server or hosting platform, some of which will be described here. “Production” means “not development”, which applies whether you’re serving your application publicly to millions of users or privately / locally to a single user. **Do not use the development server when deploying to production. It is intended for use only during local development. It is not designed to be particularly secure, stable, or efficient.** Self-Hosted Options ------------------- Flask is a WSGI *application*. A WSGI *server* is used to run the application, converting incoming HTTP requests to the standard WSGI environ, and converting outgoing WSGI responses to HTTP responses. The primary goal of these docs is to familiarize you with the concepts involved in running a WSGI application using a production WSGI server and HTTP server. There are many WSGI servers and HTTP servers, with many configuration possibilities. The pages below discuss the most common servers, and show the basics of running each one. The next section discusses platforms that can manage this for you. * [Gunicorn](gunicorn/index) * [Waitress](waitress/index) * [mod\_wsgi](mod_wsgi/index) * [uWSGI](uwsgi/index) * [gevent](gevent/index) * [eventlet](eventlet/index) * [ASGI](asgi/index) WSGI servers have HTTP servers built-in. However, a dedicated HTTP server may be safer, more efficient, or more capable. Putting an HTTP server in front of the WSGI server is called a “reverse proxy.” * [Tell Flask it is Behind a Proxy](proxy_fix/index) * [nginx](nginx/index) * [Apache httpd](apache-httpd/index) This list is not exhaustive, and you should evaluate these and other servers based on your application’s needs. Different servers will have different capabilities, configuration, and support. Hosting Platforms ----------------- There are many services available for hosting web applications without needing to maintain your own server, networking, domain, etc. Some services may have a free tier up to a certain time or bandwidth. Many of these services use one of the WSGI servers described above, or a similar interface. The links below are for some of the most common platforms, which have instructions for Flask, WSGI, or Python. * [PythonAnywhere](https://help.pythonanywhere.com/pages/Flask/) * [Google App Engine](https://cloud.google.com/appengine/docs/standard/python3/building-app) * [Google Cloud Run](https://cloud.google.com/run/docs/quickstarts/build-and-deploy/deploy-python-service) * [AWS Elastic Beanstalk](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-flask.html) * [Microsoft Azure](https://docs.microsoft.com/en-us/azure/app-service/quickstart-python) This list is not exhaustive, and you should evaluate these and other services based on your application’s needs. Different services will have different capabilities, configuration, pricing, and support. You’ll probably need to [Tell Flask it is Behind a Proxy](proxy_fix/index) when using most hosting platforms. flask ASGI ASGI ==== If you’d like to use an ASGI server you will need to utilise WSGI to ASGI middleware. The asgiref [WsgiToAsgi](https://github.com/django/asgiref#wsgi-to-asgi-adapter) adapter is recommended as it integrates with the event loop used for Flask’s [Using async and await](../../async-await/index#async-await) support. You can use the adapter by wrapping the Flask app, ``` from asgiref.wsgi import WsgiToAsgi from flask import Flask app = Flask(__name__) ... asgi_app = WsgiToAsgi(app) ``` and then serving the `asgi_app` with the ASGI server, e.g. using [Hypercorn](https://gitlab.com/pgjones/hypercorn), ``` $ hypercorn module:asgi_app ``` flask Apache httpd Apache httpd ============ [Apache httpd](https://httpd.apache.org/) is a fast, production level HTTP server. When serving your application with one of the WSGI servers listed in [Deploying to Production](../index), it is often good or necessary to put a dedicated HTTP server in front of it. This “reverse proxy” can handle incoming requests, TLS, and other security and performance concerns better than the WSGI server. httpd can be installed using your system package manager, or a pre-built executable for Windows. Installing and running httpd itself is outside the scope of this doc. This page outlines the basics of configuring httpd to proxy your application. Be sure to read its documentation to understand what features are available. Domain Name ----------- Acquiring and configuring a domain name is outside the scope of this doc. In general, you will buy a domain name from a registrar, pay for server space with a hosting provider, and then point your registrar at the hosting provider’s name servers. To simulate this, you can also edit your `hosts` file, located at `/etc/hosts` on Linux. Add a line that associates a name with the local IP. Modern Linux systems may be configured to treat any domain name that ends with `.localhost` like this without adding it to the `hosts` file. `/etc/hosts` ``` 127.0.0.1 hello.localhost ``` Configuration ------------- The httpd configuration is located at `/etc/httpd/conf/httpd.conf` on Linux. It may be different depending on your operating system. Check the docs and look for `httpd.conf`. Remove or comment out any existing `DocumentRoot` directive. Add the config lines below. We’ll assume the WSGI server is listening locally at `http://127.0.0.1:8000`. `/etc/httpd/conf/httpd.conf` ``` LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so ProxyPass / http://127.0.0.1:8000/ RequestHeader set X-Forwarded-Proto http RequestHeader set X-Forwarded-Prefix / ``` The `LoadModule` lines might already exist. If so, make sure they are uncommented instead of adding them manually. Then [Tell Flask it is Behind a Proxy](../proxy_fix/index) so that your application uses the `X-Forwarded` headers. `X-Forwarded-For` and `X-Forwarded-Host` are automatically set by `ProxyPass`. flask gevent gevent ====== Prefer using [Gunicorn](../gunicorn/index) or [uWSGI](../uwsgi/index) with gevent workers rather than using [gevent](https://www.gevent.org/) directly. Gunicorn and uWSGI provide much more configurable and production-tested servers. [gevent](https://www.gevent.org/) allows writing asynchronous, coroutine-based code that looks like standard synchronous Python. It uses [greenlet](https://greenlet.readthedocs.io/en/latest/) to enable task switching without writing `async/await` or using `asyncio`. [eventlet](../eventlet/index) is another library that does the same thing. Certain dependencies you have, or other considerations, may affect which of the two you choose to use. gevent provides a WSGI server that can handle many connections at once instead of one per worker process. You must actually use gevent in your own code to see any benefit to using the server. Installing ---------- When using gevent, greenlet>=1.0 is required, otherwise context locals such as `request` will not work as expected. When using PyPy, PyPy>=7.3.7 is required. Create a virtualenv, install your application, then install `gevent`. ``` $ cd hello-app $ python -m venv venv $ . venv/bin/activate $ pip install . # install your application $ pip install gevent ``` Running ------- To use gevent to serve your application, write a script that imports its `WSGIServer`, as well as your app or app factory. `wsgi.py` ``` from gevent.pywsgi import WSGIServer from hello import create_app app = create_app() http_server = WSGIServer(("127.0.0.1", 8000), app) http_server.serve_forever() ``` ``` $ python wsgi.py ``` No output is shown when the server starts. Binding Externally ------------------ gevent should not be run as root because it would cause your application code to run as root, which is not secure. However, this means it will not be possible to bind to port 80 or 443. Instead, a reverse proxy such as [nginx](../nginx/index) or [Apache httpd](../apache-httpd/index) should be used in front of gevent. You can bind to all external IPs on a non-privileged port by using `0.0.0.0` in the server arguments shown in the previous section. Don’t do this when using a reverse proxy setup, otherwise it will be possible to bypass the proxy. `0.0.0.0` is not a valid address to navigate to, you’d use a specific IP address in your browser. flask Waitress Waitress ======== [Waitress](https://docs.pylonsproject.org/projects/waitress/) is a pure Python WSGI server. * It is easy to configure. * It supports Windows directly. * It is easy to install as it does not require additional dependencies or compilation. * It does not support streaming requests, full request data is always buffered. * It uses a single process with multiple thread workers. This page outlines the basics of running Waitress. Be sure to read its documentation and `waitress-serve --help` to understand what features are available. Installing ---------- Create a virtualenv, install your application, then install `waitress`. ``` $ cd hello-app $ python -m venv venv $ . venv/bin/activate $ pip install . # install your application $ pip install waitress ``` Running ------- The only required argument to `waitress-serve` tells it how to load your Flask application. The syntax is `{module}:{app}`. `module` is the dotted import name to the module with your application. `app` is the variable with the application. If you’re using the app factory pattern, use `--call {module}:{factory}` instead. ``` # equivalent to 'from hello import app' $ waitress-serve --host 127.0.0.1 hello:app # equivalent to 'from hello import create_app; create_app()' $ waitress-serve --host 127.0.0.1 --call hello:create_app Serving on http://127.0.0.1:8080 ``` The `--host` option binds the server to local `127.0.0.1` only. Logs for each request aren’t shown, only errors are shown. Logging can be configured through the Python interface instead of the command line. Binding Externally ------------------ Waitress should not be run as root because it would cause your application code to run as root, which is not secure. However, this means it will not be possible to bind to port 80 or 443. Instead, a reverse proxy such as [nginx](../nginx/index) or [Apache httpd](../apache-httpd/index) should be used in front of Waitress. You can bind to all external IPs on a non-privileged port by not specifying the `--host` option. Don’t do this when using a revers proxy setup, otherwise it will be possible to bypass the proxy. `0.0.0.0` is not a valid address to navigate to, you’d use a specific IP address in your browser. flask Gunicorn Gunicorn ======== [Gunicorn](https://gunicorn.org/) is a pure Python WSGI server with simple configuration and multiple worker implementations for performance tuning. * It tends to integrate easily with hosting platforms. * It does not support Windows (but does run on WSL). * It is easy to install as it does not require additional dependencies or compilation. * It has built-in async worker support using gevent or eventlet. This page outlines the basics of running Gunicorn. Be sure to read its [documentation](https://docs.gunicorn.org/) and use `gunicorn --help` to understand what features are available. Installing ---------- Gunicorn is easy to install, as it does not require external dependencies or compilation. It runs on Windows only under WSL. Create a virtualenv, install your application, then install `gunicorn`. ``` $ cd hello-app $ python -m venv venv $ . venv/bin/activate $ pip install . # install your application $ pip install gunicorn ``` Running ------- The only required argument to Gunicorn tells it how to load your Flask application. The syntax is `{module_import}:{app_variable}`. `module_import` is the dotted import name to the module with your application. `app_variable` is the variable with the application. It can also be a function call (with any arguments) if you’re using the app factory pattern. ``` # equivalent to 'from hello import app' $ gunicorn -w 4 'hello:app' # equivalent to 'from hello import create_app; create_app()' $ gunicorn -w 4 'hello:create_app()' Starting gunicorn 20.1.0 Listening at: http://127.0.0.1:8000 (x) Using worker: sync Booting worker with pid: x Booting worker with pid: x Booting worker with pid: x Booting worker with pid: x ``` The `-w` option specifies the number of processes to run; a starting value could be `CPU * 2`. The default is only 1 worker, which is probably not what you want for the default worker type. Logs for each request aren’t shown by default, only worker info and errors are shown. To show access logs on stdout, use the `--access-logfile=-` option. Binding Externally ------------------ Gunicorn should not be run as root because it would cause your application code to run as root, which is not secure. However, this means it will not be possible to bind to port 80 or 443. Instead, a reverse proxy such as [nginx](../nginx/index) or [Apache httpd](../apache-httpd/index) should be used in front of Gunicorn. You can bind to all external IPs on a non-privileged port using the `-b 0.0.0.0` option. Don’t do this when using a reverse proxy setup, otherwise it will be possible to bypass the proxy. ``` $ gunicorn -w 4 -b 0.0.0.0 'hello:create_app()' Listening at: http://0.0.0.0:8000 (x) ``` `0.0.0.0` is not a valid address to navigate to, you’d use a specific IP address in your browser. Async with gevent or eventlet ----------------------------- The default sync worker is appropriate for many use cases. If you need asynchronous support, Gunicorn provides workers using either [gevent](https://www.gevent.org/) or [eventlet](https://eventlet.net/). This is not the same as Python’s `async/await`, or the ASGI server spec. You must actually use gevent/eventlet in your own code to see any benefit to using the workers. When using either gevent or eventlet, greenlet>=1.0 is required, otherwise context locals such as `request` will not work as expected. When using PyPy, PyPy>=7.3.7 is required. To use gevent: ``` $ gunicorn -k gevent 'hello:create_app()' Starting gunicorn 20.1.0 Listening at: http://127.0.0.1:8000 (x) Using worker: gevent Booting worker with pid: x ``` To use eventlet: ``` $ gunicorn -k eventlet 'hello:create_app()' Starting gunicorn 20.1.0 Listening at: http://127.0.0.1:8000 (x) Using worker: eventlet Booting worker with pid: x ``` flask mod_wsgi mod\_wsgi ========= [mod\_wsgi](https://modwsgi.readthedocs.io/) is a WSGI server integrated with the [Apache httpd](https://httpd.apache.org/) server. The modern [mod\_wsgi-express](https://pypi.org/project/mod-wsgi/) command makes it easy to configure and start the server without needing to write Apache httpd configuration. * Tightly integrated with Apache httpd. * Supports Windows directly. * Requires a compiler and the Apache development headers to install. * Does not require a reverse proxy setup. This page outlines the basics of running mod\_wsgi-express, not the more complex installation and configuration with httpd. Be sure to read the [mod\_wsgi-express](https://pypi.org/project/mod-wsgi/), [mod\_wsgi](https://modwsgi.readthedocs.io/), and [Apache httpd](https://httpd.apache.org/) documentation to understand what features are available. Installing ---------- Installing mod\_wsgi requires a compiler and the Apache server and development headers installed. You will get an error if they are not. How to install them depends on the OS and package manager that you use. Create a virtualenv, install your application, then install `mod_wsgi`. ``` $ cd hello-app $ python -m venv venv $ . venv/bin/activate $ pip install . # install your application $ pip install mod_wsgi ``` Running ------- The only argument to `mod_wsgi-express` specifies a script containing your Flask application, which must be called `application`. You can write a small script to import your app with this name, or to create it if using the app factory pattern. `wsgi.py` ``` from hello import app application = app ``` `wsgi.py` ``` from hello import create_app application = create_app() ``` Now run the `mod_wsgi-express start-server` command. ``` $ mod_wsgi-express start-server wsgi.py --processes 4 ``` The `--processes` option specifies the number of worker processes to run; a starting value could be `CPU * 2`. Logs for each request aren’t show in the terminal. If an error occurs, its information is written to the error log file shown when starting the server. Binding Externally ------------------ Unlike the other WSGI servers in these docs, mod\_wsgi can be run as root to bind to privileged ports like 80 and 443. However, it must be configured to drop permissions to a different user and group for the worker processes. For example, if you created a `hello` user and group, you should install your virtualenv and application as that user, then tell mod\_wsgi to drop to that user after starting. ``` $ sudo /home/hello/venv/bin/mod_wsgi-express start-server \ /home/hello/wsgi.py \ --user hello --group hello --port 80 --processes 4 ``` flask Tell Flask it is Behind a Proxy Tell Flask it is Behind a Proxy =============================== When using a reverse proxy, or many Python hosting platforms, the proxy will intercept and forward all external requests to the local WSGI server. From the WSGI server and Flask application’s perspectives, requests are now coming from the HTTP server to the local address, rather than from the remote address to the external server address. HTTP servers should set `X-Forwarded-` headers to pass on the real values to the application. The application can then be told to trust and use those values by wrapping it with the [X-Forwarded-For Proxy Fix](https://werkzeug.palletsprojects.com/en/2.2.x/middleware/proxy_fix/ "(in Werkzeug v2.2.x)") middleware provided by Werkzeug. This middleware should only be used if the application is actually behind a proxy, and should be configured with the number of proxies that are chained in front of it. Not all proxies set all the headers. Since incoming headers can be faked, you must set how many proxies are setting each header so the middleware knows what to trust. ``` from werkzeug.middleware.proxy_fix import ProxyFix app.wsgi_app = ProxyFix( app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1 ) ``` Remember, only apply this middleware if you are behind a proxy, and set the correct number of proxies that set each header. It can be a security issue if you get this configuration wrong. flask nginx nginx ===== [nginx](https://nginx.org/) is a fast, production level HTTP server. When serving your application with one of the WSGI servers listed in [Deploying to Production](../index), it is often good or necessary to put a dedicated HTTP server in front of it. This “reverse proxy” can handle incoming requests, TLS, and other security and performance concerns better than the WSGI server. Nginx can be installed using your system package manager, or a pre-built executable for Windows. Installing and running Nginx itself is outside the scope of this doc. This page outlines the basics of configuring Nginx to proxy your application. Be sure to read its documentation to understand what features are available. Domain Name ----------- Acquiring and configuring a domain name is outside the scope of this doc. In general, you will buy a domain name from a registrar, pay for server space with a hosting provider, and then point your registrar at the hosting provider’s name servers. To simulate this, you can also edit your `hosts` file, located at `/etc/hosts` on Linux. Add a line that associates a name with the local IP. Modern Linux systems may be configured to treat any domain name that ends with `.localhost` like this without adding it to the `hosts` file. `/etc/hosts` ``` 127.0.0.1 hello.localhost ``` Configuration ------------- The nginx configuration is located at `/etc/nginx/nginx.conf` on Linux. It may be different depending on your operating system. Check the docs and look for `nginx.conf`. Remove or comment out any existing `server` section. Add a `server` section and use the `proxy_pass` directive to point to the address the WSGI server is listening on. We’ll assume the WSGI server is listening locally at `http://127.0.0.1:8000`. `/etc/nginx.conf` ``` server { listen 80; server_name _; location / { proxy_pass http://127.0.0.1:8000/; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Prefix /; } } ``` Then [Tell Flask it is Behind a Proxy](../proxy_fix/index) so that your application uses these headers.
programming_docs
flask uWSGI uWSGI ===== [uWSGI](https://uwsgi-docs.readthedocs.io/en/latest/) is a fast, compiled server suite with extensive configuration and capabilities beyond a basic server. * It can be very performant due to being a compiled program. * It is complex to configure beyond the basic application, and has so many options that it can be difficult for beginners to understand. * It does not support Windows (but does run on WSL). * It requires a compiler to install in some cases. This page outlines the basics of running uWSGI. Be sure to read its documentation to understand what features are available. Installing ---------- uWSGI has multiple ways to install it. The most straightforward is to install the `pyuwsgi` package, which provides precompiled wheels for common platforms. However, it does not provide SSL support, which can be provided with a reverse proxy instead. Create a virtualenv, install your application, then install `pyuwsgi`. ``` $ cd hello-app $ python -m venv venv $ . venv/bin/activate $ pip install . # install your application $ pip install pyuwsgi ``` If you have a compiler available, you can install the `uwsgi` package instead. Or install the `pyuwsgi` package from sdist instead of wheel. Either method will include SSL support. ``` $ pip install uwsgi # or $ pip install --no-binary pyuwsgi pyuwsgi ``` Running ------- The most basic way to run uWSGI is to tell it to start an HTTP server and import your application. ``` $ uwsgi --http 127.0.0.1:8000 --master -p 4 -w hello:app *** Starting uWSGI 2.0.20 (64bit) on [x] *** *** Operational MODE: preforking *** mounting hello:app on / spawned uWSGI master process (pid: x) spawned uWSGI worker 1 (pid: x, cores: 1) spawned uWSGI worker 2 (pid: x, cores: 1) spawned uWSGI worker 3 (pid: x, cores: 1) spawned uWSGI worker 4 (pid: x, cores: 1) spawned uWSGI http 1 (pid: x) ``` If you’re using the app factory pattern, you’ll need to create a small Python file to create the app, then point uWSGI at that. `wsgi.py` ``` from hello import create_app app = create_app() ``` ``` $ uwsgi --http 127.0.0.1:8000 --master -p 4 -w wsgi:app ``` The `--http` option starts an HTTP server at 127.0.0.1 port 8000. The `--master` option specifies the standard worker manager. The `-p` option starts 4 worker processes; a starting value could be `CPU * 2`. The `-w` option tells uWSGI how to import your application Binding Externally ------------------ uWSGI should not be run as root with the configuration shown in this doc because it would cause your application code to run as root, which is not secure. However, this means it will not be possible to bind to port 80 or 443. Instead, a reverse proxy such as [nginx](../nginx/index) or [Apache httpd](../apache-httpd/index) should be used in front of uWSGI. It is possible to run uWSGI as root securely, but that is beyond the scope of this doc. uWSGI has optimized integration with [Nginx uWSGI](https://uwsgi-docs.readthedocs.io/en/latest/Nginx.html) and [Apache mod\_proxy\_uwsgi](https://uwsgi-docs.readthedocs.io/en/latest/Apache.html#mod-proxy-uwsgi), and possibly other servers, instead of using a standard HTTP proxy. That configuration is beyond the scope of this doc, see the links for more information. You can bind to all external IPs on a non-privileged port using the `--http 0.0.0.0:8000` option. Don’t do this when using a reverse proxy setup, otherwise it will be possible to bypass the proxy. ``` $ uwsgi --http 0.0.0.0:8000 --master -p 4 -w wsgi:app ``` `0.0.0.0` is not a valid address to navigate to, you’d use a specific IP address in your browser. Async with gevent ----------------- The default sync worker is appropriate for many use cases. If you need asynchronous support, uWSGI provides a [gevent](https://www.gevent.org/) worker. This is not the same as Python’s `async/await`, or the ASGI server spec. You must actually use gevent in your own code to see any benefit to using the worker. When using gevent, greenlet>=1.0 is required, otherwise context locals such as `request` will not work as expected. When using PyPy, PyPy>=7.3.7 is required. ``` $ uwsgi --http 127.0.0.1:8000 --master --gevent 100 -w wsgi:app *** Starting uWSGI 2.0.20 (64bit) on [x] *** *** Operational MODE: async *** mounting hello:app on / spawned uWSGI master process (pid: x) spawned uWSGI worker 1 (pid: x, cores: 100) spawned uWSGI http 1 (pid: x) *** running gevent loop engine [addr:x] *** ``` flask eventlet eventlet ======== Prefer using [Gunicorn](../gunicorn/index) with eventlet workers rather than using [eventlet](https://eventlet.net/) directly. Gunicorn provides a much more configurable and production-tested server. [eventlet](https://eventlet.net/) allows writing asynchronous, coroutine-based code that looks like standard synchronous Python. It uses [greenlet](https://greenlet.readthedocs.io/en/latest/) to enable task switching without writing `async/await` or using `asyncio`. [gevent](../gevent/index) is another library that does the same thing. Certain dependencies you have, or other considerations, may affect which of the two you choose to use. eventlet provides a WSGI server that can handle many connections at once instead of one per worker process. You must actually use eventlet in your own code to see any benefit to using the server. Installing ---------- When using eventlet, greenlet>=1.0 is required, otherwise context locals such as `request` will not work as expected. When using PyPy, PyPy>=7.3.7 is required. Create a virtualenv, install your application, then install `eventlet`. ``` $ cd hello-app $ python -m venv venv $ . venv/bin/activate $ pip install . # install your application $ pip install eventlet ``` Running ------- To use eventlet to serve your application, write a script that imports its `wsgi.server`, as well as your app or app factory. `wsgi.py` ``` import eventlet from eventlet import wsgi from hello import create_app app = create_app() wsgi.server(eventlet.listen(("127.0.0.1", 8000), app) ``` ``` $ python wsgi.py (x) wsgi starting up on http://127.0.0.1:8000 ``` Binding Externally ------------------ eventlet should not be run as root because it would cause your application code to run as root, which is not secure. However, this means it will not be possible to bind to port 80 or 443. Instead, a reverse proxy such as [nginx](../nginx/index) or [Apache httpd](../apache-httpd/index) should be used in front of eventlet. You can bind to all external IPs on a non-privileged port by using `0.0.0.0` in the server arguments shown in the previous section. Don’t do this when using a reverse proxy setup, otherwise it will be possible to bypass the proxy. `0.0.0.0` is not a valid address to navigate to, you’d use a specific IP address in your browser. flask Class-based Views Class-based Views ================= This page introduces using the [`View`](../api/index#flask.views.View "flask.views.View") and [`MethodView`](../api/index#flask.views.MethodView "flask.views.MethodView") classes to write class-based views. A class-based view is a class that acts as a view function. Because it is a class, different instances of the class can be created with different arguments, to change the behavior of the view. This is also known as generic, reusable, or pluggable views. An example of where this is useful is defining a class that creates an API based on the database model it is initialized with. For more complex API behavior and customization, look into the various API extensions for Flask. Basic Reusable View ------------------- Let’s walk through an example converting a view function to a view class. We start with a view function that queries a list of users then renders a template to show the list. ``` @app.route("/users/") def user_list(): users = User.query.all() return render_template("users.html", users=users) ``` This works for the user model, but let’s say you also had more models that needed list pages. You’d need to write another view function for each model, even though the only thing that would change is the model and template name. Instead, you can write a [`View`](../api/index#flask.views.View "flask.views.View") subclass that will query a model and render a template. As the first step, we’ll convert the view to a class without any customization. ``` from flask.views import View class UserList(View): def dispatch_request(self): users = User.query.all() return render_template("users.html", objects=users) app.add_url_rule("/users/", view_func=UserList.as_view("user_list")) ``` The [`View.dispatch_request()`](../api/index#flask.views.View.dispatch_request "flask.views.View.dispatch_request") method is the equivalent of the view function. Calling [`View.as_view()`](../api/index#flask.views.View.as_view "flask.views.View.as_view") method will create a view function that can be registered on the app with its [`add_url_rule()`](../api/index#flask.Flask.add_url_rule "flask.Flask.add_url_rule") method. The first argument to `as_view` is the name to use to refer to the view with [`url_for()`](../api/index#flask.url_for "flask.url_for"). Note You can’t decorate the class with `@app.route()` the way you’d do with a basic view function. Next, we need to be able to register the same view class for different models and templates, to make it more useful than the original function. The class will take two arguments, the model and template, and store them on `self`. Then `dispatch_request` can reference these instead of hard-coded values. ``` class ListView(View): def __init__(self, model, template): self.model = model self.template = template def dispatch_request(self): items = self.model.query.all() return render_template(self.template, items=items) ``` Remember, we create the view function with `View.as_view()` instead of creating the class directly. Any extra arguments passed to `as_view` are then passed when creating the class. Now we can register the same view to handle multiple models. ``` app.add_url_rule( "/users/", view_func=ListView.as_view("user_list", User, "users.html"), ) app.add_url_rule( "/stories/", view_func=ListView.as_view("story_list", Story, "stories.html"), ) ``` URL Variables ------------- Any variables captured by the URL are passed as keyword arguments to the `dispatch_request` method, as they would be for a regular view function. ``` class DetailView(View): def __init__(self, model): self.model = model self.template = f"{model.__name__.lower()}/detail.html" def dispatch_request(self, id) item = self.model.query.get_or_404(id) return render_template(self.template, item=item) app.add_url_rule( "/users/<int:id>", view_func=DetailView.as_view("user_detail", User) ) ``` View Lifetime and `self` ------------------------ By default, a new instance of the view class is created every time a request is handled. This means that it is safe to write other data to `self` during the request, since the next request will not see it, unlike other forms of global state. However, if your view class needs to do a lot of complex initialization, doing it for every request is unnecessary and can be inefficient. To avoid this, set [`View.init_every_request`](../api/index#flask.views.View.init_every_request "flask.views.View.init_every_request") to `False`, which will only create one instance of the class and use it for every request. In this case, writing to `self` is not safe. If you need to store data during the request, use [`g`](../api/index#flask.g "flask.g") instead. In the `ListView` example, nothing writes to `self` during the request, so it is more efficient to create a single instance. ``` class ListView(View): init_every_request = False def __init__(self, model, template): self.model = model self.template = template def dispatch_request(self): items = self.model.query.all() return render_template(self.template, items=items) ``` Different instances will still be created each for each `as_view` call, but not for each request to those views. View Decorators --------------- The view class itself is not the view function. View decorators need to be applied to the view function returned by `as_view`, not the class itself. Set [`View.decorators`](../api/index#flask.views.View.decorators "flask.views.View.decorators") to a list of decorators to apply. ``` class UserList(View): decorators = [cache(minutes=2), login_required] app.add_url_rule('/users/', view_func=UserList.as_view()) ``` If you didn’t set `decorators`, you could apply them manually instead. This is equivalent to: ``` view = UserList.as_view("users_list") view = cache(minutes=2)(view) view = login_required(view) app.add_url_rule('/users/', view_func=view) ``` Keep in mind that order matters. If you’re used to `@decorator` style, this is equivalent to: ``` @app.route("/users/") @login_required @cache(minutes=2) def user_list(): ... ``` Method Hints ------------ A common pattern is to register a view with `methods=["GET", "POST"]`, then check `request.method == "POST"` to decide what to do. Setting [`View.methods`](../api/index#flask.views.View.methods "flask.views.View.methods") is equivalent to passing the list of methods to `add_url_rule` or `route`. ``` class MyView(View): methods = ["GET", "POST"] def dispatch_request(self): if request.method == "POST": ... ... app.add_url_rule('/my-view', view_func=MyView.as_view('my-view')) ``` This is equivalent to the following, except further subclasses can inherit or change the methods. ``` app.add_url_rule( "/my-view", view_func=MyView.as_view("my-view"), methods=["GET", "POST"], ) ``` Method Dispatching and APIs --------------------------- For APIs it can be helpful to use a different function for each HTTP method. [`MethodView`](../api/index#flask.views.MethodView "flask.views.MethodView") extends the basic [`View`](../api/index#flask.views.View "flask.views.View") to dispatch to different methods of the class based on the request method. Each HTTP method maps to a method of the class with the same (lowercase) name. [`MethodView`](../api/index#flask.views.MethodView "flask.views.MethodView") automatically sets [`View.methods`](../api/index#flask.views.View.methods "flask.views.View.methods") based on the methods defined by the class. It even knows how to handle subclasses that override or define other methods. We can make a generic `ItemAPI` class that provides get (detail), patch (edit), and delete methods for a given model. A `GroupAPI` can provide get (list) and post (create) methods. ``` from flask.views import MethodView class ItemAPI(MethodView): init_every_request = False def __init__(self, model): self.model self.validator = generate_validator(model) def _get_item(self, id): return self.model.query.get_or_404(id) def get(self, id): user = self._get_item(id) return jsonify(item.to_json()) def patch(self, id): item = self._get_item(id) errors = self.validator.validate(item, request.json) if errors: return jsonify(errors), 400 item.update_from_json(request.json) db.session.commit() return jsonify(item.to_json()) def delete(self, id): item = self._get_item(id) db.session.delete(item) db.session.commit() return "", 204 class GroupAPI(MethodView): init_every_request = False def __init__(self, model): self.model = model self.validator = generate_validator(model, create=True) def get(self): items = self.model.query.all() return jsonify([item.to_json() for item in items]) def post(self): errors = self.validator.validate(request.json) if errors: return jsonify(errors), 400 db.session.add(self.model.from_json(request.json)) db.session.commit() return jsonify(item.to_json()) def register_api(app, model, url): item = ItemAPI.as_view(f"{name}-item", model) group = GroupAPI.as_view(f"{name}-group", model) app.add_url_rule(f"/{name}/<int:id>", view_func=item) app.add_url_rule(f"/{name}/", view_func=group) register_api(app, User, "users") register_api(app, Story, "stories") ``` This produces the following views, a standard REST API! | | | | | --- | --- | --- | | URL | Method | Description | | `/users/` | `GET` | List all users | | `/users/` | `POST` | Create a new user | | `/users/<id>` | `GET` | Show a single user | | `/users/<id>` | `PATCH` | Update a user | | `/users/<id>` | `DELETE` | Delete a user | | `/stories/` | `GET` | List all stories | | `/stories/` | `POST` | Create a new story | | `/stories/<id>` | `GET` | Show a single story | | `/stories/<id>` | `PATCH` | Update a story | | `/stories/<id>` | `DELETE` | Delete a story | flask Logging Logging ======= Flask uses standard Python [`logging`](https://docs.python.org/3/library/logging.html#module-logging "(in Python v3.10)"). Messages about your Flask application are logged with [`app.logger`](../api/index#flask.Flask.logger "flask.Flask.logger"), which takes the same name as [`app.name`](../api/index#flask.Flask.name "flask.Flask.name"). This logger can also be used to log your own messages. ``` @app.route('/login', methods=['POST']) def login(): user = get_user(request.form['username']) if user.check_password(request.form['password']): login_user(user) app.logger.info('%s logged in successfully', user.username) return redirect(url_for('index')) else: app.logger.info('%s failed to log in', user.username) abort(401) ``` If you don’t configure logging, Python’s default log level is usually ‘warning’. Nothing below the configured level will be visible. Basic Configuration ------------------- When you want to configure logging for your project, you should do it as soon as possible when the program starts. If [`app.logger`](../api/index#flask.Flask.logger "flask.Flask.logger") is accessed before logging is configured, it will add a default handler. If possible, configure logging before creating the application object. This example uses [`dictConfig()`](https://docs.python.org/3/library/logging.config.html#logging.config.dictConfig "(in Python v3.10)") to create a logging configuration similar to Flask’s default, except for all logs: ``` from logging.config import dictConfig dictConfig({ 'version': 1, 'formatters': {'default': { 'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s', }}, 'handlers': {'wsgi': { 'class': 'logging.StreamHandler', 'stream': 'ext://flask.logging.wsgi_errors_stream', 'formatter': 'default' }}, 'root': { 'level': 'INFO', 'handlers': ['wsgi'] } }) app = Flask(__name__) ``` ### Default Configuration If you do not configure logging yourself, Flask will add a [`StreamHandler`](https://docs.python.org/3/library/logging.handlers.html#logging.StreamHandler "(in Python v3.10)") to [`app.logger`](../api/index#flask.Flask.logger "flask.Flask.logger") automatically. During requests, it will write to the stream specified by the WSGI server in `environ['wsgi.errors']` (which is usually [`sys.stderr`](https://docs.python.org/3/library/sys.html#sys.stderr "(in Python v3.10)")). Outside a request, it will log to [`sys.stderr`](https://docs.python.org/3/library/sys.html#sys.stderr "(in Python v3.10)"). ### Removing the Default Handler If you configured logging after accessing [`app.logger`](../api/index#flask.Flask.logger "flask.Flask.logger"), and need to remove the default handler, you can import and remove it: ``` from flask.logging import default_handler app.logger.removeHandler(default_handler) ``` Email Errors to Admins ---------------------- When running the application on a remote server for production, you probably won’t be looking at the log messages very often. The WSGI server will probably send log messages to a file, and you’ll only check that file if a user tells you something went wrong. To be proactive about discovering and fixing bugs, you can configure a [`logging.handlers.SMTPHandler`](https://docs.python.org/3/library/logging.handlers.html#logging.handlers.SMTPHandler "(in Python v3.10)") to send an email when errors and higher are logged. ``` import logging from logging.handlers import SMTPHandler mail_handler = SMTPHandler( mailhost='127.0.0.1', fromaddr='[email protected]', toaddrs=['[email protected]'], subject='Application Error' ) mail_handler.setLevel(logging.ERROR) mail_handler.setFormatter(logging.Formatter( '[%(asctime)s] %(levelname)s in %(module)s: %(message)s' )) if not app.debug: app.logger.addHandler(mail_handler) ``` This requires that you have an SMTP server set up on the same server. See the Python docs for more information about configuring the handler. Injecting Request Information ----------------------------- Seeing more information about the request, such as the IP address, may help debugging some errors. You can subclass [`logging.Formatter`](https://docs.python.org/3/library/logging.html#logging.Formatter "(in Python v3.10)") to inject your own fields that can be used in messages. You can change the formatter for Flask’s default handler, the mail handler defined above, or any other handler. ``` from flask import has_request_context, request from flask.logging import default_handler class RequestFormatter(logging.Formatter): def format(self, record): if has_request_context(): record.url = request.url record.remote_addr = request.remote_addr else: record.url = None record.remote_addr = None return super().format(record) formatter = RequestFormatter( '[%(asctime)s] %(remote_addr)s requested %(url)s\n' '%(levelname)s in %(module)s: %(message)s' ) default_handler.setFormatter(formatter) mail_handler.setFormatter(formatter) ``` Other Libraries --------------- Other libraries may use logging extensively, and you want to see relevant messages from those logs too. The simplest way to do this is to add handlers to the root logger instead of only the app logger. ``` from flask.logging import default_handler root = logging.getLogger() root.addHandler(default_handler) root.addHandler(mail_handler) ``` Depending on your project, it may be more useful to configure each logger you care about separately, instead of configuring only the root logger. ``` for logger in ( app.logger, logging.getLogger('sqlalchemy'), logging.getLogger('other_package'), ): logger.addHandler(default_handler) logger.addHandler(mail_handler) ``` ### Werkzeug Werkzeug logs basic request/response information to the `'werkzeug'` logger. If the root logger has no handlers configured, Werkzeug adds a [`StreamHandler`](https://docs.python.org/3/library/logging.handlers.html#logging.StreamHandler "(in Python v3.10)") to its logger. ### Flask Extensions Depending on the situation, an extension may choose to log to [`app.logger`](../api/index#flask.Flask.logger "flask.Flask.logger") or its own named logger. Consult each extension’s documentation for details.
programming_docs
browser_support_tables Passive event listeners Passive event listeners ======================= Event listeners created with the `passive: true` option cannot cancel (`preventDefault()`) the events they receive. Primarily intended to be used with touch events and `wheel` events. Since they cannot prevent scrolls, passive event listeners allow the browser to perform optimizations that result in smoother scrolling. | | | | --- | --- | | Spec | <https://dom.spec.whatwg.org/#dom-addeventlisteneroptions-passive> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Improving scroll performance with passive event listeners - Google Developers Updates](https://developers.google.com/web/updates/2016/06/passive-event-listeners?hl=en) * [Polyfill from the WICG](https://github.com/WICG/EventListenerOptions/blob/gh-pages/EventListenerOptions.polyfill.js) * [Original WICG EventListenerOptions repository](https://github.com/WICG/EventListenerOptions) * [JS Bin testcase](https://jsbin.com/jaqaku/edit?html,js,output) browser_support_tables CSS3 Transitions CSS3 Transitions ================ Simple method of animating certain properties of an element, with ability to define property, duration, delay and timing function. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css3-transitions/> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 (\*) | 67 | | | 81 | 82 | 81 | 5.1 (\*) | 66 | | | 80 | 81 | 80 | 5 (1,\*) | 65 | | | 79 | 80 | 79 | 4 (1,\*) | 64 | | | 18 | 79 | 78 | 3.2 (1,\*) | 63 | | | 17 | 78 | 77 | 3.1 (1,\*) | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 (\*) | | | | 30 | 29 | | 11.6 (1,\*) | | | | 29 | 28 | | 11.5 (1,\*) | | | | 28 | 27 | | 11.1 (1,\*) | | | | 27 | 26 | | 11 (1,\*) | | | | 26 | 25 (\*) | | 10.6 (1,\*) | | | | 25 | 24 (\*) | | 10.5 (1,\*) | | | | 24 | 23 (\*) | | 10.0-10.1 | | | | 23 | 22 (\*) | | 9.5-9.6 | | | | 22 | 21 (\*) | | 9 | | | | 21 | 20 (\*) | | | | | | 20 | 19 (\*) | | | | | | 19 | 18 (\*) | | | | | | 18 | 17 (\*) | | | | | | 17 | 16 (\*) | | | | | | 16 | 15 (\*) | | | | | | 15 (\*) | 14 (\*) | | | | | | 14 (\*) | 13 (\*) | | | | | | 13 (\*) | 12 (\*) | | | | | | 12 (\*) | 11 (\*) | | | | | | 11 (\*) | 10 (\*) | | | | | | 10 (\*) | 9 (\*) | | | | | | 9 (\*) | 8 (\*) | | | | | | 8 (\*) | 7 (\*) | | | | | | 7 (\*) | 6 (\*) | | | | | | 6 (\*) | 5 (\*) | | | | | | 5 (\*) | 4 (\*) | | | | | | 4 (1,\*) | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 (\*) | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 (\*) | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 (\*) | | 11.5 (1,\*) | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 (\*) | | 11.1 (1,\*) | | | | | 15.0 | | | | | 15.4 | | 4 (\*) | | 11 (1,\*) | | | | | 14.0 | | | | | 15.2-15.3 | | 3 (\*) | | 10 (1,\*) | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 (\*) | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 (\*) | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 (\*) | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 (\*) | | | | | | | | | | | | | | 5.0-5.1 (1,\*) | | | | | | | | | | | | | | 4.2-4.3 (1,\*) | | | | | | | | | | | | | | 4.0-4.1 (1,\*) | | | | | | | | | | | | | | 3.2 (1,\*) | | | | | | | | | | | | | Notes ----- Support listed is for `transition` properties as well as the `transitionend` event. 1. Does not support the `steps()`, `step-start` & `step-end` timing functions \* Partial support with prefix. Bugs ---- * Not supported on any pseudo-elements besides ::before and ::after for Firefox, Chrome 26+, Opera 16+ and IE10+. * Transitionable properties with calc() derived values are not supported below and including IE11 (http://connect.microsoft.com/IE/feedback/details/762719/css3-calc-bug-inside-transition-or-transform) * Internet Explorer does not support transitions of the 'background-size' property. * IE11 [does not support](https://connect.microsoft.com/IE/feedbackdetail/view/920928/ie-11-css-transition-property-not-working-for-svg-elements) CSS transitions on the SVG `fill` property. * In Chrome (up to 43.0), for transition-delay property, either explicitly specified or written within transition property, the unit cannot be ommitted even if the value is 0. * IE10 & IE11 are reported to not support transitioning the `column-count` property. * Safari 11 [does not support](https://bugs.webkit.org/show_bug.cgi?id=180435) CSS transitions on the `flex-basis` property. Resources --------- * [Article on usage](https://www.webdesignerdepot.com/2010/01/css-transitions-101/) * [Examples on timing functions](https://www.the-art-of-web.com/css/timing-function/) * [WebPlatform Docs](https://webplatform.github.io/docs/css/properties/transition) browser_support_tables CSS3 Text-overflow CSS3 Text-overflow ================== Append ellipsis when text overflows its containing element | | | | --- | --- | | Spec | <https://www.w3.org/TR/css3-ui/#text-overflow> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 (\*) | | | | 25 | 24 | | 10.5 (\*) | | | | 24 | 23 | | 10.0-10.1 (\*) | | | | 23 | 22 | | 9.5-9.6 (\*) | | | | 22 | 21 | | 9 (\*) | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 (\*) | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 (\*) | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 (\*) | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 (\*) | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 (\*) | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- \* Partial support with prefix. Bugs ---- * Does not work on `select` elements in Chrome and IE, only Firefox. * Some Samsung-based browsers, have a bug with overflowing text when ellipsis is set and if `text-rendering` is not `auto`. * Does not work in IE8 and IE9 on `<input type="text">` Resources --------- * [jQuery polyfill for Firefox](https://github.com/rmorse/AutoEllipsis) * [MDN Web Docs - text-overflow](https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow) * [has.js test](https://raw.github.com/phiggins42/has.js/master/detect/css.js#css-text-overflow) * [WebPlatform Docs](https://webplatform.github.io/docs/css/properties/text-overflow)
programming_docs
browser_support_tables background-position-x & background-position-y background-position-x & background-position-y ============================================= CSS longhand properties to define x or y positions separately. | | | | --- | --- | | Spec | <https://w3c.github.io/csswg-drafts/css-backgrounds-4/#background-position-longhands> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- A workaround for the lack of support in Firefox 31 - Firefox 48 is to use [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables). See [this Stack Overflow answer](https://stackoverflow.com/a/29282573/94197) for an example. Resources --------- * [Firefox implementation bug](https://bugzilla.mozilla.org/show_bug.cgi?id=550426) * [Blog post on background-position-x & y properties](https://snook.ca/archives/html_and_css/background-position-x-y) * [MDN Web Docs - background-position-x](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position-x) * [MDN Web Docs - background-position-y](https://developer.mozilla.org/en/docs/Web/CSS/background-position-y) browser_support_tables Intl.PluralRules API Intl.PluralRules API ==================== API for plural sensitive formatting and plural language rules. | | | | --- | --- | | Spec | <https://tc39.es/ecma402/#sec-intl-pluralrules-constructor> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 (1) | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Intl.PluralRules exists, but methods are not implemented. Resources --------- * [MDN Web Docs: Intl.PluralRules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules) * [Google Developers blog: The Intl.PluralRules API](https://developers.google.com/web/updates/2017/10/intl-pluralrules) browser_support_tables CSS :any-link selector CSS :any-link selector ====================== The `:any-link` CSS pseudo-class matches all elements that match `:link` or `:visited` | | | | --- | --- | | Spec | <https://w3c.github.io/csswg-drafts/selectors-4/#the-any-link-pseudo> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 (\*) | 71 | | | 86 | 86 | 86 | 7.1 (\*) | 70 | | | 85 | 85 | 85 | 7 (\*) | 69 | | | 84 | 84 | 84 | 6.1 (\*) | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 (\*) | | | | 68 | 67 | | 50 (\*) | | | | 67 | 66 | | 49 (\*) | | | | 66 | 65 | | 48 (\*) | | | | 65 | 64 (\*) | | 47 (\*) | | | | 64 | 63 (\*) | | 46 (\*) | | | | 63 | 62 (\*) | | 45 (\*) | | | | 62 | 61 (\*) | | 44 (\*) | | | | 61 | 60 (\*) | | 43 (\*) | | | | 60 | 59 (\*) | | 42 (\*) | | | | 59 | 58 (\*) | | 41 (\*) | | | | 58 | 57 (\*) | | 40 (\*) | | | | 57 | 56 (\*) | | 39 (\*) | | | | 56 | 55 (\*) | | 38 (\*) | | | | 55 | 54 (\*) | | 37 (\*) | | | | 54 | 53 (\*) | | 36 (\*) | | | | 53 | 52 (\*) | | 35 (\*) | | | | 52 | 51 (\*) | | 34 (\*) | | | | 51 | 50 (\*) | | 33 (\*) | | | | 50 | 49 (\*) | | 32 (\*) | | | | 49 (\*) | 48 (\*) | | 31 (\*) | | | | 48 (\*) | 47 (\*) | | 30 (\*) | | | | 47 (\*) | 46 (\*) | | 29 (\*) | | | | 46 (\*) | 45 (\*) | | 28 (\*) | | | | 45 (\*) | 44 (\*) | | 27 (\*) | | | | 44 (\*) | 43 (\*) | | 26 (\*) | | | | 43 (\*) | 42 (\*) | | 25 (\*) | | | | 42 (\*) | 41 (\*) | | 24 (\*) | | | | 41 (\*) | 40 (\*) | | 23 (\*) | | | | 40 (\*) | 39 (\*) | | 22 (\*) | | | | 39 (\*) | 38 (\*) | | 21 (\*) | | | | 38 (\*) | 37 (\*) | | 20 (\*) | | | | 37 (\*) | 36 (\*) | | 19 (\*) | | | | 36 (\*) | 35 (\*) | | 18 (\*) | | | | 35 (\*) | 34 (\*) | | 17 (\*) | | | | 34 (\*) | 33 (\*) | | 16 (\*) | | | | 33 (\*) | 32 (\*) | | 15 (\*) | | | | 32 (\*) | 31 (\*) | | 12.1 | | | | 31 (\*) | 30 (\*) | | 12 | | | | 30 (\*) | 29 (\*) | | 11.6 | | | | 29 (\*) | 28 (\*) | | 11.5 | | | | 28 (\*) | 27 (\*) | | 11.1 | | | | 27 (\*) | 26 (\*) | | 11 | | | | 26 (\*) | 25 (\*) | | 10.6 | | | | 25 (\*) | 24 (\*) | | 10.5 | | | | 24 (\*) | 23 (\*) | | 10.0-10.1 | | | | 23 (\*) | 22 (\*) | | 9.5-9.6 | | | | 22 (\*) | 21 (\*) | | 9 | | | | 21 (\*) | 20 (\*) | | | | | | 20 (\*) | 19 (\*) | | | | | | 19 (\*) | 18 (\*) | | | | | | 18 (\*) | 17 (\*) | | | | | | 17 (\*) | 16 (\*) | | | | | | 16 (\*) | 15 (\*) | | | | | | 15 (\*) | 14 | | | | | | 14 (\*) | 13 | | | | | | 13 (\*) | 12 | | | | | | 12 (\*) | 11 | | | | | | 11 (\*) | 10 | | | | | | 10 (\*) | 9 | | | | | | 9 (\*) | 8 | | | | | | 8 (\*) | 7 | | | | | | 7 (\*) | 6 | | | | | | 6 (\*) | 5 | | | | | | 5 (\*) | 4 | | | | | | 4 (\*) | | | | | | | 3.6 (\*) | | | | | | | 3.5 (\*) | | | | | | | 3 (\*) | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (\*) | | 16.1 | | 4.4.3-4.4.4 (\*) | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 (\*) | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 (\*) | | | | | 13.2 | | | | | | | | | 7.2-7.4 (\*) | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 (\*) | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 (\*) | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 (\*) | | | | | | | | | | | | | | 8 (\*) | | | | | | | | | | | | | | 7.0-7.1 (\*) | | | | | | | | | | | | | | 6.0-6.1 (\*) | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- \* Partial support with prefix. Resources --------- * [MDN Web Docs - CSS :any-link](https://developer.mozilla.org/en-US/docs/Web/CSS/:any-link) browser_support_tables Scroll methods on elements (scroll, scrollTo, scrollBy) Scroll methods on elements (scroll, scrollTo, scrollBy) ======================================================= Methods to change the scroll position of an element. Similar to setting `scrollTop` & `scrollLeft` properties, but also allows options to be passed to define the scroll behavior. | | | | --- | --- | | Spec | <https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 (1) | 81 | | | 96 | 96 | 96 | 13 (1) | 80 | | | 95 | 95 | 95 | 12.1 (1) | 79 | | | 94 | 94 | 94 | 12 (1) | 78 | | | 93 | 93 | 93 | 11.1 (1) | 77 | | | 92 | 92 | 92 | 11 (1) | 76 | | | 91 | 91 | 91 | 10.1 (1) | 75 | | | 90 | 90 | 90 | 10 (1) | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (1) | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (1) | | | | | | | | | 9.2 | | | | | 13.3 (1) | | | | | | | | | 8.2 | | | | | 13.2 (1) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (1) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (1) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 (1) | | | | | | | | | 4 | | | | | 11.3-11.4 (1) | | | | | | | | | | | | | | 11.0-11.2 (1) | | | | | | | | | | | | | | 10.3 (1) | | | | | | | | | | | | | | 10.0-10.2 (1) | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- See also the support for the [`scrollIntoView` method](/#feat=scrollintoview). 1. Does not support the `smooth` behavior option. Resources --------- * [MDN article on scrollTo](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTo) * [MDN article on scrollBy](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollBy)
programming_docs
browser_support_tables EventTarget.dispatchEvent EventTarget.dispatchEvent ========================= Method to programmatically trigger a DOM event. | | | | --- | --- | | Spec | <https://dom.spec.whatwg.org/#dom-eventtarget-dispatchevent> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 (1) | 107 | 107 | 107 | 16.1 | 91 | | 9 (1) | 106 | 106 | 106 | 16.0 | 90 | | 8 (1) | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 (1) | 104 | 104 | 104 | 15.5 | 88 | | 6 (1) | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 (1) | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Supports Microsoft's proprietary [`EventTarget.fireEvent() method`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/fireEvent). Resources --------- * [MDN Web Docs - dispatchEvent](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent) * [Financial Times IE8 polyfill](https://github.com/Financial-Times/polyfill-service/blob/master/polyfills/Event/polyfill-ie8.js) * [WebReflection ie8 polyfill](https://github.com/WebReflection/ie8) browser_support_tables Decorators Decorators ========== ECMAScript Decorators are an in-progress proposal for extending JavaScript classes. Decorators use a special syntax, prefixed with an `@` symbol and placed immediately before the code being extended. | | | | --- | --- | | Spec | <https://github.com/tc39/proposal-decorators> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- While not yet supported natively in browsers, decorators are supported by a number of transpiler tools. Resources --------- * [JavaScript Decorators: What They Are and When to Use Them](https://www.sitepoint.com/javascript-decorators-what-they-are/) * [A minimal guide to JavaScript (ECMAScript) Decorators and Property Descriptor of the Object](https://medium.com/jspoint/a-minimal-guide-to-ecmascript-decorators-55b70338215e) * [Decorators in TypeScript](https://www.typescriptlang.org/docs/handbook/decorators.html) * [Babel plug-in for decorators](https://babeljs.io/docs/en/babel-plugin-proposal-decorators) browser_support_tables CSS hanging-punctuation CSS hanging-punctuation ======================= Allows some punctuation characters from start (or the end) of text elements to be placed "outside" of the box in order to preserve the reading flow. | | | | --- | --- | | Spec | <https://w3c.github.io/csswg-drafts/css-text-3/#hanging-punctuation-property> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [CSS tricks article](https://css-tricks.com/almanac/properties/h/hanging-punctuation/) * [Firefox bug #1253615](https://bugzilla.mozilla.org/show_bug.cgi?id=1253615) browser_support_tables dataset & data-* attributes dataset & data-\* attributes ============================ Method of applying and accessing custom data to elements. | | | | --- | --- | | Spec | [https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-\*-attributes](https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes) | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (1) | | | | | | 110 (1) | 110 (1) | TP (1) | | | | | 109 (1) | 109 (1) | 16.3 (1) | | | 11 | 108 (1) | 108 (1) | 108 (1) | 16.2 (1) | 92 (1) | | 10 | 107 (1) | 107 (1) | 107 (1) | 16.1 (1) | 91 (1) | | 9 | 106 (1) | 106 (1) | 106 (1) | 16.0 (1) | 90 (1) | | 8 | 105 (1) | 105 (1) | 105 (1) | 15.6 (1) | 89 (1) | | [Show all](#) | | 7 | 104 (1) | 104 (1) | 104 (1) | 15.5 (1) | 88 (1) | | 6 | 103 (1) | 103 (1) | 103 (1) | 15.4 (1) | 87 (1) | | 5.5 | 102 (1) | 102 (1) | 102 (1) | 15.2-15.3 (1) | 86 (1) | | | 101 (1) | 101 (1) | 101 (1) | 15.1 (1) | 85 (1) | | | 100 (1) | 100 (1) | 100 (1) | 15 (1) | 84 (1) | | | 99 (1) | 99 (1) | 99 (1) | 14.1 (1) | 83 (1) | | | 98 (1) | 98 (1) | 98 (1) | 14 (1) | 82 (1) | | | 97 (1) | 97 (1) | 97 (1) | 13.1 (1) | 81 (1) | | | 96 (1) | 96 (1) | 96 (1) | 13 (1) | 80 (1) | | | 95 (1) | 95 (1) | 95 (1) | 12.1 (1) | 79 (1) | | | 94 (1) | 94 (1) | 94 (1) | 12 (1) | 78 (1) | | | 93 (1) | 93 (1) | 93 (1) | 11.1 (1) | 77 (1) | | | 92 (1) | 92 (1) | 92 (1) | 11 (1) | 76 (1) | | | 91 (1) | 91 (1) | 91 (1) | 10.1 (1) | 75 (1) | | | 90 (1) | 90 (1) | 90 (1) | 10 (1) | 74 (1) | | | 89 (1) | 89 (1) | 89 (1) | 9.1 (1) | 73 (1) | | | 88 (1) | 88 (1) | 88 (1) | 9 (1) | 72 (1) | | | 87 (1) | 87 (1) | 87 (1) | 8 (1) | 71 (1) | | | 86 (1) | 86 (1) | 86 (1) | 7.1 (1) | 70 (1) | | | 85 (1) | 85 (1) | 85 (1) | 7 (1) | 69 (1) | | | 84 (1) | 84 (1) | 84 (1) | 6.1 (1) | 68 (1) | | | 83 (1) | 83 (1) | 83 (1) | 6 (1) | 67 (1) | | | 81 (1) | 82 (1) | 81 (1) | 5.1 (1) | 66 (1) | | | 80 (1) | 81 (1) | 80 (1) | 5 | 65 (1) | | | 79 (1) | 80 (1) | 79 (1) | 4 | 64 (1) | | | 18 (1) | 79 (1) | 78 (1) | 3.2 | 63 (1) | | | 17 (1) | 78 (1) | 77 (1) | 3.1 | 62 (1) | | | 16 | 77 (1) | 76 (1) | | 60 (1) | | | 15 | 76 (1) | 75 (1) | | 58 (1) | | | 14 | 75 (1) | 74 (1) | | 57 (1) | | | 13 | 74 (1) | 73 (1) | | 56 (1) | | | 12 | 73 (1) | 72 (1) | | 55 (1) | | | | 72 (1) | 71 (1) | | 54 (1) | | | | 71 (1) | 70 (1) | | 53 (1) | | | | 70 (1) | 69 (1) | | 52 (1) | | | | 69 (1) | 68 (1) | | 51 (1) | | | | 68 (1) | 67 (1) | | 50 (1) | | | | 67 (1) | 66 (1) | | 49 (1) | | | | 66 (1) | 65 (1) | | 48 (1) | | | | 65 (1) | 64 (1) | | 47 (1) | | | | 64 (1) | 63 (1) | | 46 (1) | | | | 63 (1) | 62 (1) | | 45 (1) | | | | 62 (1) | 61 (1) | | 44 (1) | | | | 61 (1) | 60 (1) | | 43 (1) | | | | 60 (1) | 59 (1) | | 42 (1) | | | | 59 (1) | 58 (1) | | 41 | | | | 58 (1) | 57 (1) | | 40 | | | | 57 (1) | 56 (1) | | 39 | | | | 56 (1) | 55 (1) | | 38 | | | | 55 (1) | 54 | | 37 | | | | 54 (1) | 53 | | 36 | | | | 53 (1) | 52 | | 35 | | | | 52 (1) | 51 | | 34 | | | | 51 (1) | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 (1) | | | | 48 | 47 | | 30 (1) | | | | 47 | 46 | | 29 (1) | | | | 46 | 45 | | 28 (1) | | | | 45 | 44 (1) | | 27 (1) | | | | 44 | 43 (1) | | 26 (1) | | | | 43 | 42 (1) | | 25 (1) | | | | 42 | 41 (1) | | 24 (1) | | | | 41 | 40 (1) | | 23 (1) | | | | 40 | 39 (1) | | 22 (1) | | | | 39 | 38 (1) | | 21 (1) | | | | 38 | 37 (1) | | 20 (1) | | | | 37 | 36 (1) | | 19 (1) | | | | 36 | 35 (1) | | 18 (1) | | | | 35 | 34 (1) | | 17 (1) | | | | 34 | 33 (1) | | 16 (1) | | | | 33 | 32 (1) | | 15 (1) | | | | 32 | 31 (1) | | 12.1 | | | | 31 | 30 (1) | | 12 | | | | 30 | 29 (1) | | 11.6 | | | | 29 | 28 (1) | | 11.5 | | | | 28 | 27 (1) | | 11.1 | | | | 27 | 26 (1) | | 11 | | | | 26 | 25 (1) | | 10.6 | | | | 25 | 24 (1) | | 10.5 | | | | 24 | 23 (1) | | 10.0-10.1 | | | | 23 | 22 (1) | | 9.5-9.6 | | | | 22 | 21 (1) | | 9 | | | | 21 | 20 (1) | | | | | | 20 | 19 (1) | | | | | | 19 | 18 (1) | | | | | | 18 | 17 (1) | | | | | | 17 | 16 (1) | | | | | | 16 | 15 (1) | | | | | | 15 | 14 (1) | | | | | | 14 | 13 (1) | | | | | | 13 | 12 (1) | | | | | | 12 | 11 (1) | | | | | | 11 | 10 (1) | | | | | | 10 | 9 (1) | | | | | | 9 | 8 (1) | | | | | | 8 | 7 (1) | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (1) | | | | | | | | | | | | | | 16.2 (1) | all | 108 (1) | 10 (1) | 72 (1) | 108 (1) | 107 (1) | 11 | 13.4 (1) | 19.0 (1) | 13.1 (1) | 13.18 (1) | 2.5 | | 16.1 (1) | | 4.4.3-4.4.4 (1) | 7 (1) | 12.1 | | | 10 | | 18.0 (1) | | | | | 16.0 (1) | | 4.4 (1) | | 12 | | | | | 17.0 (1) | | | | | 15.6 (1) | | 4.2-4.3 (1) | | 11.5 | | | | | 16.0 (1) | | | | | [Show all](#) | | 15.5 (1) | | 4.1 (1) | | 11.1 | | | | | 15.0 (1) | | | | | 15.4 (1) | | 4 (1) | | 11 | | | | | 14.0 (1) | | | | | 15.2-15.3 (1) | | 3 (1) | | 10 | | | | | 13.0 (1) | | | | | 15.0-15.1 (1) | | 2.3 | | | | | | | 12.0 (1) | | | | | 14.5-14.8 (1) | | 2.2 | | | | | | | 11.1-11.2 (1) | | | | | 14.0-14.4 (1) | | 2.1 | | | | | | | 10.1 (1) | | | | | 13.4-13.7 (1) | | | | | | | | | 9.2 (1) | | | | | 13.3 (1) | | | | | | | | | 8.2 (1) | | | | | 13.2 (1) | | | | | | | | | 7.2-7.4 (1) | | | | | 13.0-13.1 (1) | | | | | | | | | 6.2-6.4 (1) | | | | | 12.2-12.5 (1) | | | | | | | | | 5.0-5.4 (1) | | | | | 12.0-12.1 (1) | | | | | | | | | 4 (1) | | | | | 11.3-11.4 (1) | | | | | | | | | | | | | | 11.0-11.2 (1) | | | | | | | | | | | | | | 10.3 (1) | | | | | | | | | | | | | | 10.0-10.2 (1) | | | | | | | | | | | | | | 9.3 (1) | | | | | | | | | | | | | | 9.0-9.2 (1) | | | | | | | | | | | | | | 8.1-8.4 (1) | | | | | | | | | | | | | | 8 (1) | | | | | | | | | | | | | | 7.0-7.1 (1) | | | | | | | | | | | | | | 6.0-6.1 (1) | | | | | | | | | | | | | | 5.0-5.1 (1) | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Partial support refers to being able to use `data-*` attributes and access them using `getAttribute`. "Supported" refers to accessing the values using the `dataset` property. Current spec only refers to support on HTML elements, only some browsers also have support for SVG/MathML elements. 1. While the HTML spec doesn't require it, these browsers also support `dataset` and `data-*` attributes on SVG elements, in compliance with [current plans for SVG2](https://www.w3.org/2015/01/15-svg-minutes.html#item03) Bugs ---- * Android 2.3 cannot read `data-*` properties from `select` elements. * Safari 10 and below can return `undefined` on properties of `dataset` in some cases. ([See bug](https://bugs.webkit.org/show_bug.cgi?id=161454)). Resources --------- * [HTML5 Doctor article](https://html5doctor.com/html5-custom-data-attributes/) * [Demo using dataset](https://html5demos.com/dataset) * [has.js test](https://raw.github.com/phiggins42/has.js/master/detect/dom.js#dom-dataset) * [WebPlatform Docs](https://webplatform.github.io/docs/html/attributes/data-*) * [MDN Web Docs - dataset](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement.dataset) * [MDN Guide - Using data-\* attributes](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes)
programming_docs
browser_support_tables Document Policy Document Policy =============== A mechanism that allows developers to set certain rules and policies for a given site. The rules can change default browser behaviour, block certain features or set limits on resource usage. Document Policy is useful both for security and performance, and is similar to [Permissions Policy](/permissions-policy). | | | | --- | --- | | Spec | <https://wicg.github.io/document-policy/> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (1) | | | | | | 110 | 110 (1) | TP | | | | | 109 | 109 (1) | 16.3 | | | 11 | 108 (1) | 108 | 108 (1) | 16.2 | 92 (1) | | 10 | 107 (1) | 107 | 107 (1) | 16.1 | 91 (1) | | 9 | 106 (1) | 106 | 106 (1) | 16.0 | 90 (1) | | 8 | 105 (1) | 105 | 105 (1) | 15.6 | 89 (1) | | [Show all](#) | | 7 | 104 (1) | 104 | 104 (1) | 15.5 | 88 (1) | | 6 | 103 (1) | 103 | 103 (1) | 15.4 | 87 (1) | | 5.5 | 102 (1) | 102 | 102 (1) | 15.2-15.3 | 86 (1) | | | 101 (1) | 101 | 101 (1) | 15.1 | 85 (1) | | | 100 (1) | 100 | 100 (1) | 15 | 84 (1) | | | 99 (1) | 99 | 99 (1) | 14.1 | 83 (1) | | | 98 (1) | 98 | 98 (1) | 14 | 82 (1) | | | 97 (1) | 97 | 97 (1) | 13.1 | 81 (1) | | | 96 (1) | 96 | 96 (1) | 13 | 80 (1) | | | 95 (1) | 95 | 95 (1) | 12.1 | 79 (1) | | | 94 (1) | 94 | 94 (1) | 12 | 78 (1) | | | 93 (1) | 93 | 93 (1) | 11.1 | 77 (1) | | | 92 (1) | 92 | 92 (1) | 11 | 76 (1) | | | 91 (1) | 91 | 91 (1) | 10.1 | 75 (1) | | | 90 (1) | 90 | 90 (1) | 10 | 74 (1) | | | 89 (1) | 89 | 89 (1) | 9.1 | 73 (1) | | | 88 (1) | 88 | 88 (1) | 9 | 72 (1) | | | 87 (1) | 87 | 87 (1) | 8 | 71 (1) | | | 86 (1) | 86 | 86 (1) | 7.1 | 70 | | | 85 (1) | 85 | 85 (1) | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 (1) | 10 | 72 (1) | 108 (1) | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 (1) | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Standard support includes the HTTP `Document-Policy` header and `policy` attribute on iframes. 1. Chromium browsers only support the HTTP header. Resources --------- * [Firefox position: non-harmful](https://mozilla.github.io/standards-positions/#document-policy) * [Chromium tracking bug for new policies](https://bugs.chromium.org/p/chromium/issues/detail?id=993790) * [WICG - Document Policy Explainer](https://github.com/WICG/document-policy/blob/main/document-policy-explainer.md) browser_support_tables ui-serif, ui-sans-serif, ui-monospace and ui-rounded values for font-family ui-serif, ui-sans-serif, ui-monospace and ui-rounded values for font-family =========================================================================== Allows more control when choosing system interface fonts | | | | --- | --- | | Spec | <https://w3c.github.io/csswg-drafts/css-fonts-4/#ui-serif-def> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [WebKit Safari 13.1 announcement](https://webkit.org/blog/10247/new-webkit-features-in-safari-13-1/) * [ui-serif Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1598879) * [ui-sans-serif Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1598880) * [ui-monospace Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1598881) * [ui-rounded Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1598883) * [Chromium support bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1029069) browser_support_tables CSS overflow: overlay CSS overflow: overlay ===================== The `overlay` value of the `overflow` CSS property is a non-standard value to make scrollbars appear on top of content rather than take up space. This value is deprecated and related functionality being standardized as [the `scrollbar-gutter` property](mdn-css_properties_scrollbar-gutter). | | | | --- | --- | | Spec | <https://github.com/w3c/csswg-drafts/issues/92> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP (1) | | | | | 109 | 109 | 16.3 (1) | | | 11 | 108 | 108 | 108 | 16.2 (1) | 92 | | 10 | 107 | 107 | 107 | 16.1 (1) | 91 | | 9 | 106 | 106 | 106 | 16.0 (1) | 90 | | 8 | 105 | 105 | 105 | 15.6 (1) | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 (1) | 88 | | 6 | 103 | 103 | 103 | 15.4 (1) | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 (1) | 86 | | | 101 | 101 | 101 | 15.1 (1) | 85 | | | 100 | 100 | 100 | 15 (1) | 84 | | | 99 | 99 | 99 | 14.1 (1) | 83 | | | 98 | 98 | 98 | 14 (1) | 82 | | | 97 | 97 | 97 | 13.1 (1) | 81 | | | 96 | 96 | 96 | 13 (1) | 80 | | | 95 | 95 | 95 | 12.1 (1) | 79 | | | 94 | 94 | 94 | 12 (1) | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (1) | | | | | | | | | | | | | | 16.2 (1) | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 (1) | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 (1) | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 (1) | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 (1) | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 (1) | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 (1) | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 (1) | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 (1) | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (1) | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (1) | | | | | | | | | 9.2 | | | | | 13.3 (1) | | | | | | | | | 8.2 | | | | | 13.2 (1) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (1) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (1) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 (1) | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. The `overlay` value is recognized, but behaves the same as "auto". Resources --------- * [MDN article on overflow values](https://developer.mozilla.org/en-US/docs/Web/CSS/overflow#values) * [WebKit change to make "overflow: overlay" a synonym for "overflow: auto"](https://trac.webkit.org/changeset/236341/webkit) browser_support_tables OffscreenCanvas OffscreenCanvas =============== OffscreenCanvas allows canvas drawing to occur with no connection to the DOM and can be used inside workers. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/canvas.html#the-offscreencanvas-interface> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 (1) | 104 | 15.5 | 88 | | 6 | 103 | 103 (1) | 103 | 15.4 | 87 | | 5.5 | 102 | 102 (1) | 102 | 15.2-15.3 | 86 | | | 101 | 101 (1) | 101 | 15.1 | 85 | | | 100 | 100 (1) | 100 | 15 | 84 | | | 99 | 99 (1) | 99 | 14.1 | 83 | | | 98 | 98 (1) | 98 | 14 | 82 | | | 97 | 97 (1) | 97 | 13.1 | 81 | | | 96 | 96 (1) | 96 | 13 | 80 | | | 95 | 95 (1) | 95 | 12.1 | 79 | | | 94 | 94 (1) | 94 | 12 | 78 | | | 93 | 93 (1) | 93 | 11.1 | 77 | | | 92 | 92 (1) | 92 | 11 | 76 | | | 91 | 91 (1) | 91 | 10.1 | 75 | | | 90 | 90 (1) | 90 | 10 | 74 | | | 89 | 89 (1) | 89 | 9.1 | 73 | | | 88 | 88 (1) | 88 | 9 | 72 | | | 87 | 87 (1) | 87 | 8 | 71 | | | 86 | 86 (1) | 86 | 7.1 | 70 | | | 85 | 85 (1) | 85 | 7 | 69 | | | 84 | 84 (1) | 84 | 6.1 | 68 | | | 83 | 83 (1) | 83 | 6 | 67 | | | 81 | 82 (1) | 81 | 5.1 | 66 | | | 80 | 81 (1) | 80 | 5 | 65 | | | 79 | 80 (1) | 79 | 4 | 64 | | | 18 | 79 (1) | 78 | 3.2 | 63 (2) | | | 17 | 78 (1) | 77 | 3.1 | 62 (2) | | | 16 | 77 (1) | 76 | | 60 (2) | | | 15 | 76 (1) | 75 | | 58 (2) | | | 14 | 75 (1) | 74 | | 57 (2) | | | 13 | 74 (1) | 73 | | 56 (2) | | | 12 | 73 (1) | 72 | | 55 (2) | | | | 72 (1) | 71 | | 54 (2) | | | | 71 (1) | 70 | | 53 (2) | | | | 70 (1) | 69 | | 52 (2) | | | | 69 (1) | 68 (2) | | 51 (2) | | | | 68 (1) | 67 (2) | | 50 (2) | | | | 67 (1) | 66 (2) | | 49 (2) | | | | 66 (1) | 65 (2) | | 48 (2) | | | | 65 (1) | 64 (2) | | 47 (2) | | | | 64 (1) | 63 (2) | | 46 (2) | | | | 63 (1) | 62 (2) | | 45 (2) | | | | 62 (1) | 61 (2) | | 44 | | | | 61 (1) | 60 (2) | | 43 | | | | 60 (1) | 59 (2) | | 42 | | | | 59 (1) | 58 (2) | | 41 | | | | 58 (1) | 57 | | 40 | | | | 57 (1) | 56 | | 39 | | | | 56 (1) | 55 | | 38 | | | | 55 (1) | 54 | | 37 | | | | 54 (1) | 53 | | 36 | | | | 53 (1) | 52 | | 35 | | | | 52 (1) | 51 | | 34 | | | | 51 (1) | 50 | | 33 | | | | 50 (1) | 49 | | 32 | | | | 49 (1) | 48 | | 31 | | | | 48 (1) | 47 | | 30 | | | | 47 (1) | 46 | | 29 | | | | 46 (1) | 45 | | 28 | | | | 45 (1) | 44 | | 27 | | | | 44 (1) | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (1) | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled via the `gfx.offscreencanvas.enabled` flag. Currently only supports WebGL contexts, not 2D. 2. Can be enabled via the `Experimental canvas features` flag Resources --------- * [MDN article](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas) * [WebGL off the main thread - Mozilla Hacks article](https://hacks.mozilla.org/2016/01/webgl-off-the-main-thread/) * [Making the whole web better, one canvas at a time. - Article about canvas performance](https://bkardell.com/blog/OffscreenCanvas.html) * [Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1390089) * [WebKit support bug](https://bugs.webkit.org/show_bug.cgi?id=183720)
programming_docs
browser_support_tables BigInt BigInt ====== Arbitrary-precision integers in JavaScript. | | | | --- | --- | | Spec | <https://tc39.es/ecma262/#sec-bigint-objects> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 (1) | 66 | | 49 | | | | 66 (1) | 65 | | 48 | | | | 65 (1) | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled by setting `javascript.options.bigint` to "True" in `about:config` Resources --------- * [GitHub repository](https://github.com/tc39/proposal-bigint) * [Blog article from Google Developer](https://developers.google.com/web/updates/2018/05/bigint) * [Blog article from Dr. Axel Rauschmayer](https://2ality.com/2017/03/es-integer.html) * [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) * [Firefox implementation bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1366287) browser_support_tables selector list argument of :nth-child and :nth-last-child CSS pseudo-classes selector list argument of :nth-child and :nth-last-child CSS pseudo-classes =========================================================================== The newest versions of `:nth-child()` and `:nth-last-child()` accept an optional `of S` clause which filters the children to only those which match the selector list `S`. For example, `:nth-child(1 of .foo)` selects the first child among the children that have the `foo` class (ignoring any non-`foo` children which precede that child). Similar to `:nth-of-type`, but for arbitrary selectors instead of only type selectors. | | | | --- | --- | | Spec | <https://w3c.github.io/csswg-drafts/selectors/#the-nth-child-pseudo> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- For support information for just `:nth-child()` see [CSS3 selector support](#feat=css-sel3) Resources --------- * [Mozilla Bug 854148 - Support for :nth-child(An+B of sel), :nth-last-child(An+B of sel) pseudo-classes](https://bugzilla.mozilla.org/show_bug.cgi?id=854148) * [Chromium Issue 304163: Implement :nth-child(an+b of S) and :nth-last-child(an+b of S) pseudo-classes](https://bugs.chromium.org/p/chromium/issues/detail?id=304163) * [MS Edge Platform Status: Under Consideration](https://web.archive.org/web/20190401105447if_/https://developer.microsoft.com/en-us/microsoft-edge/platform/status/cssselectorslevel4/) browser_support_tables JPEG XR image format JPEG XR image format ==================== JPEG XR was built to supersede the original JPEG format by having better compression and more features. [WebP](/webp), [AVIF](/avif) and [JPEG XL](/jpegxl) are all designed to supersede JPEG XR. | | | | --- | --- | | Spec | <https://www.itu.int/rec/T-REC-T.832> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Microsoft JPEG XR Codec Overview](https://docs.microsoft.com/en-us/windows/win32/wic/jpeg-xr-codec) * [Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=500500) * [Chrome support bug (marked as WONTFIX)](https://code.google.com/p/chromium/issues/detail?id=56908) browser_support_tables MediaRecorder API MediaRecorder API ================= The MediaRecorder API (MediaStream Recording) aims to provide a really simple mechanism by which developers can record media streams from the user's input devices and instantly use them in web apps, rather than having to perform manual encoding operations on raw PCM data, etc. | | | | --- | --- | | Spec | <https://w3c.github.io/mediacapture-record/MediaRecorder.html> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 (2) | 82 | | | 97 | 97 | 97 | 13.1 (2) | 81 | | | 96 | 96 | 96 | 13 (2) | 80 | | | 95 | 95 | 95 | 12.1 (2) | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 (1) | | | | 52 | 51 | | 34 (1) | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 (1) | | 31 | | | | 48 | 47 (1) | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (3) | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (3) | | | | | | | | | 9.2 | | | | | 13.3 (3) | | | | | | | | | 8.2 | | | | | 13.2 (3) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (3) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (3) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 (3) | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled via the experimental Web Platform features flag. Does not support audio recording, only video. 2. Can be enabled using the Develop > Experimental Features menu. 3. Can be enabled using the Advanced > Experimental Features menu. Resources --------- * [MDN Web Docs - MediaRecorder](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder_API)
programming_docs
browser_support_tables Web MIDI API Web MIDI API ============ The Web MIDI API specification defines a means for web developers to enumerate, manipulate and access MIDI devices | | | | --- | --- | | Spec | <https://webaudio.github.io/web-midi-api/> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Polyfill](https://github.com/cwilso/WebMIDIAPIShim) * [Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=836897) * [Test/demo page](https://www.onlinemusictools.com/webmiditest/) * [WebKit support bug](https://bugs.webkit.org/show_bug.cgi?id=107250) browser_support_tables Declarative Shadow DOM Declarative Shadow DOM ====================== Proposal to allow rendering elements with shadow dom (aka web components) using server-side rendering. | | | | --- | --- | | Spec | <https://github.com/mfreed7/declarative-shadow-dom> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Declarative Shadow DOM - web.dev article](https://web.dev/declarative-shadow-dom/) * [A ponyfill of the Declarative Shadow DOM API](https://www.npmjs.com/package/@webcomponents/template-shadowroot) browser_support_tables WebM video format WebM video format ================= Multimedia format designed to provide a royalty-free, high-quality open video compression format for use with HTML5 video. WebM supports the video codec VP8 and VP9. | | | | --- | --- | | Spec | <https://www.webmproject.org> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (3) | 108 | 108 | 108 | 16.2 | 92 | | 10 (3) | 107 | 107 | 107 | 16.1 | 91 | | 9 (3) | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 (7) | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 (7) | 88 | | 6 | 103 | 103 | 103 | 15.4 (7) | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 (7) | 86 | | | 101 | 101 | 101 | 15.1 (7) | 85 | | | 100 | 100 | 100 | 15 (7) | 84 | | | 99 | 99 | 99 | 14.1 (7) | 83 | | | 98 | 98 | 98 | 14 (4,5,6) | 82 | | | 97 | 97 | 97 | 13.1 (4) | 81 | | | 96 | 96 | 96 | 13 (4) | 80 | | | 95 | 95 | 95 | 12.1 (4) | 79 | | | 94 | 94 | 94 | 12 (3) | 78 | | | 93 | 93 | 93 | 11.1 (3) | 77 | | | 92 | 92 | 92 | 11 (3) | 76 | | | 91 | 91 | 91 | 10.1 (3) | 75 | | | 90 | 90 | 90 | 10 (3) | 74 | | | 89 | 89 | 89 | 9.1 (3) | 73 | | | 88 | 88 | 88 | 9 (3) | 72 | | | 87 | 87 | 87 | 8 (3) | 71 | | | 86 | 86 | 86 | 7.1 (3) | 70 | | | 85 | 85 | 85 | 7 (3) | 69 | | | 84 | 84 | 84 | 6.1 (3) | 68 | | | 83 | 83 | 83 | 6 (3) | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 (1,2) | 79 | 78 | 3.2 | 63 | | | 17 (1,2) | 78 | 77 | 3.1 | 62 | | | 16 (1,2) | 77 | 76 | | 60 | | | 15 (1,2) | 76 | 75 | | 58 | | | 14 (1,2) | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 (1) | | | | 32 | 31 | | 12.1 (1) | | | | 31 | 30 | | 12 (1) | | | | 30 | 29 | | 11.6 (1) | | | | 29 | 28 | | 11.5 (1) | | | | 28 | 27 | | 11.1 (1) | | | | 27 (1) | 26 | | 11 (1) | | | | 26 (1) | 25 | | 10.6 (1) | | | | 25 (1) | 24 (1) | | 10.5 | | | | 24 (1) | 23 (1) | | 10.0-10.1 | | | | 23 (1) | 22 (1) | | 9.5-9.6 | | | | 22 (1) | 21 (1) | | 9 | | | | 21 (1) | 20 (1) | | | | | | 20 (1) | 19 (1) | | | | | | 19 (1) | 18 (1) | | | | | | 18 (1) | 17 (1) | | | | | | 17 (1) | 16 (1) | | | | | | 16 (1) | 15 (1) | | | | | | 15 (1) | 14 (1) | | | | | | 14 (1) | 13 (1) | | | | | | 13 (1) | 12 (1) | | | | | | 12 (1) | 11 (1) | | | | | | 11 (1) | 10 (1) | | | | | | 10 (1) | 9 (1) | | | | | | 9 (1) | 8 (1) | | | | | | 8 (1) | 7 (1) | | | | | | 7 (1) | 6 (1) | | | | | | 6 (1) | 5 | | | | | | 5 (1) | 4 | | | | | | 4 (1) | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (4,5) | | | | | | | | | | | | | | 16.2 (4,5) | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 (4,5) | | 4.4.3-4.4.4 (1) | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 (4,5) | | 4.4 (1) | | 12 | | | | | 17.0 | | | | | 15.6 (4,5) | | 4.2-4.3 (1) | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 (4,5) | | 4.1 (1) | | 11.1 | | | | | 15.0 | | | | | 15.4 (4,5) | | 4 (1) | | 11 | | | | | 14.0 | | | | | 15.2-15.3 (4,5) | | 3 (1) | | 10 | | | | | 13.0 | | | | | 15.0-15.1 (4,5) | | 2.3 (1) | | | | | | | 12.0 | | | | | 14.5-14.8 (4,5) | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (4,5) | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (4) | | | | | | | | | 9.2 | | | | | 13.3 (4) | | | | | | | | | 8.2 | | | | | 13.2 (4) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (4) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (4) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 (1) | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Older browser versions did not support all codecs. 2. Older Edge versions did not support progressive sources. 3. Can be enabled in Internet Explorer and Safari for MacOS by manually installing the codecs in the operating system. 4. Supports [VP8 codec used in WebRTC](https://webkit.org/blog/8672). 5. Supports [VP9 codec used in WebRTC](https://webkit.org/blog/10929) (off by default.) 6. Supports [VP9 WebM used in MediaSource](https://bugs.webkit.org/show_bug.cgi?id=216652#c1) on [macOS Big Sur or later.](https://trac.webkit.org/changeset/264747/webkit) 7. Safari 14.1 – 15.6 has full support of WebM, but requires macOS 11.3 Big Sur or later. Resources --------- * [Official website](https://www.webmproject.org) * [Wikipedia article](https://en.wikipedia.org/wiki/WebM) browser_support_tables AV1 video format AV1 video format ================ AV1 (AOMedia Video 1) is a royalty-free video format by the Alliance for Open Media, meant to succeed its predecessor VP9 and compete with the [HEVC/H.265](/hevc) format. | | | | --- | --- | | Spec | <https://github.com/AOMediaCodec/av1-spec> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 (1) | 108 | 108 | 16.2 | 92 | | 10 | 107 (1) | 107 | 107 | 16.1 | 91 | | 9 | 106 (1) | 106 | 106 | 16.0 | 90 | | 8 | 105 (1) | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 (1) | 104 | 104 | 15.5 | 88 | | 6 | 103 (1) | 103 | 103 | 15.4 | 87 | | 5.5 | 102 (1) | 102 | 102 | 15.2-15.3 | 86 | | | 101 (1) | 101 | 101 | 15.1 | 85 | | | 100 (1) | 100 | 100 | 15 | 84 | | | 99 (1) | 99 | 99 | 14.1 | 83 | | | 98 (1) | 98 | 98 | 14 | 82 | | | 97 (1) | 97 | 97 | 13.1 | 81 | | | 96 (1) | 96 | 96 | 13 | 80 | | | 95 (1) | 95 | 95 | 12.1 | 79 | | | 94 (1) | 94 | 94 | 12 | 78 | | | 93 (1) | 93 | 93 | 11.1 | 77 | | | 92 (1) | 92 | 92 | 11 | 76 | | | 91 (1) | 91 | 91 | 10.1 | 75 | | | 90 (1) | 90 | 90 | 10 | 74 | | | 89 (1) | 89 | 89 | 9.1 | 73 | | | 88 (1) | 88 | 88 | 9 | 72 | | | 87 (1) | 87 | 87 | 8 | 71 | | | 86 (1) | 86 | 86 | 7.1 | 70 | | | 85 (1) | 85 | 85 | 7 | 69 | | | 84 (1) | 84 | 84 | 6.1 | 68 | | | 83 (1) | 83 | 83 | 6 | 67 | | | 81 (1) | 82 | 81 | 5.1 | 66 | | | 80 (1) | 81 | 80 | 5 | 65 | | | 79 (1) | 80 | 79 | 4 | 64 | | | 18 (1) | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 (3) | 65 | | 48 | | | | 65 (2) | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 (4) | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled in Edge on Windows 10 or later by installing the [AV1 Video Extension from the Microsoft Store](https://www.microsoft.com/store/productId/9MVZQVXJBQ9V) 2. Firefox 65 only supported AV1 on Windows 64-bit 3. Firefox 66 only supported AV1 on Windows and macOS 4. Can be enabled in Firefox for Android via the `media.av1.enabled` flag in `about:config` Resources --------- * [Wikipedia article](https://en.wikipedia.org/wiki/AV1) * [Sample video from Bitmovin](https://bitmovin.com/demos/av1) * [Sample video from Facebook](https://www.facebook.com/330716120785217/videos/330723190784510/) * [Firefox implementation bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1452683) * [Safari implementation bug](https://bugs.webkit.org/show_bug.cgi?id=207547)
programming_docs
browser_support_tables EOT - Embedded OpenType fonts EOT - Embedded OpenType fonts ============================= Type of font that can be derived from a regular font, allowing small files and legal use of high-quality fonts. Usage is restricted by the file being tied to the website | | | | --- | --- | | Spec | <https://www.w3.org/Submission/EOT/> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Proposal by Microsoft, being considered for W3C standardization. Resources --------- * [Wikipedia](https://en.wikipedia.org/wiki/Embedded_OpenType) * [Example pages](https://www.microsoft.com/typography/web/embedding/default.aspx) browser_support_tables Web Workers Web Workers =========== Method of running scripts in the background, isolated from the web page | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/workers.html> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [MDN Web Docs - Using Web Workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) * [Web Worker demo](https://nerget.com/rayjs-mt/rayjs.html) * [Polyfill for IE (single threaded)](https://code.google.com/archive/p/ie-web-worker/) * [Tutorial](https://code.tutsplus.com/tutorials/getting-started-with-web-workers--net-27667) browser_support_tables Proximity API Proximity API ============= Defines events that provide information about the distance between a device and an object, as measured by a proximity sensor. | | | | --- | --- | | Spec | <https://www.w3.org/TR/proximity/> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Demo](https://audero.it/demo/proximity-api-demo.html) * [SitePoint article](https://www.sitepoint.com/introducing-proximity-api/) browser_support_tables CSS inline-block CSS inline-block ================ Method of displaying an element as a block while flowing it with text. | | | | --- | --- | | Spec | <https://www.w3.org/TR/CSS21/visuren.html#fixed-positioning> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 (1) | 104 | 104 | 104 | 15.5 | 88 | | 6 (1) | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 (\*) | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Only supported in IE6 and IE7 on elements with a display of "inline" by default. [Alternative properties](http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/) are available to provide complete cross-browser support. \* Partial support with prefix. Bugs ---- * IE 8 has a [resize issue with display-inline block](http://blog.caplin.com/2013/06/07/developing-for-ie8-inline-block-resize-bug/). Resources --------- * [Blog post w/info](https://robertnyman.com/2010/02/24/css-display-inline-block-why-it-rocks-and-why-it-sucks/) * [Info on cross browser support](https://blog.mozilla.org/webdev/2009/02/20/cross-browser-inline-block/) * [WebPlatform Docs](https://webplatform.github.io/docs/css/properties/display)
programming_docs
browser_support_tables Autofocus attribute Autofocus attribute =================== Allows a form field to be immediately focused on page load. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/forms.html#autofocusing-a-form-control:-the-autofocus-attribute> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- While not supported in iOS Safari, it does work in iOS WebViews. Bugs ---- * Firefox [has a bug](https://bugzilla.mozilla.org/show_bug.cgi?id=712130) where `autofocus` doesn't always scroll to the correct part of the page. Resources --------- * [Article on autofocus](https://davidwalsh.name/autofocus) * [MDN Web Docs - autofocus attribute](https://developer.mozilla.org/en/docs/Web/HTML/Element/input#attr-autofocus) browser_support_tables KeyboardEvent.charCode KeyboardEvent.charCode ====================== A legacy `KeyboardEvent` property that gives the Unicode codepoint number of a character key pressed during a `keypress` event. | | | | --- | --- | | Spec | <https://w3c.github.io/uievents/#dom-keyboardevent-charcode> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 (1) | 11 (1) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 (1) | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- This property is legacy and deprecated. ["Some key events, or their values, might be suppressed by the IME in use"](https://www.w3.org/TR/2019/WD-uievents-20190530/#keys-IME). On mobile (virtual keyboard), all keys are reported as 0. 1. Does not appear to support the `keypress` event at all Resources --------- * [MDN Web Docs - charCode](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/charCode) browser_support_tables SVG effects for HTML SVG effects for HTML ==================== Method of using SVG transforms, filters, etc on HTML elements using either CSS or the foreignObject element | | | | --- | --- | | Spec | <https://www.w3.org/TR/SVG11/extend.html#ForeignObjectElement> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (1,2) | 108 | 108 | 108 | 16.2 | 92 | | 10 (1,2) | 107 | 107 | 107 | 16.1 | 91 | | 9 (1,2) | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 (2) | 79 | 78 | 3.2 | 63 | | | 17 (2) | 78 | 77 | 3.1 | 62 | | | 16 (2) | 77 | 76 | | 60 | | | 15 (2) | 76 | 75 | | 58 | | | 14 (2) | 75 | 74 | | 57 | | | 13 (2) | 74 | 73 | | 56 | | | 12 (2) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Partial support refers to lack of filter support or buggy result from effects. A [CSS Filter Effects](https://www.w3.org/TR/filter-effects/) specification is in the works that would replace this method. 1. IE11 and below do not support `<foreignObject>`. 2. IE and Edge do not support applying SVG filter effects to HTML elements using CSS. [Bug Report](https://web.archive.org/web/20171208021756/https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/6618695/) Bugs ---- * Browsers can have differing behavior when HTML CSS properties are set on SVG elements, for example Edge & IE browsers do not respond to the `height` property while Chrome does. Resources --------- * [MDN Web Docs - Other content in SVG](https://developer.mozilla.org/en/SVG/Tutorial/Other_content_in_SVG) * [MDN Web Docs - Applying SVG effects](https://developer.mozilla.org/en-US/docs/Web/SVG/Applying_SVG_effects_to_HTML_content) * [Filter Effects draft](https://www.w3.org/TR/filter-effects/) browser_support_tables CSS Variables (Custom Properties) CSS Variables (Custom Properties) ================================= Permits the declaration and usage of cascading variables in stylesheets. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css-variables/> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 (2) | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 (2) | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 (1) | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 (1) | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 (2) | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Enabled through the "Experimental Web Platform features" flag in `chrome://flags` 2. Partial support is due to bugs present (see known issues) 3. Partial support is due to bugs present (see known issues) Bugs ---- * In Edge 15 is not possible to use css variables in pseudo elements [see bug](https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/11495448/) * In Edge 15 animations with css variables may cause the webpage to crash [see bug](https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/11676012/) * In Edge 15, nested calculations with css variables are not computed and are ignored [see bug](https://web.archive.org/web/20171216000230/https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12143022/) * In Safari 9.1 to 9.3, nested calculations using intermediate CSS Custom Properties don't work and are ignored [see bug](https://bugs.webkit.org/show_bug.cgi?id=161002) Resources --------- * [Mozilla hacks article (older syntax)](https://hacks.mozilla.org/2013/12/css-variables-in-firefox-nightly/) * [MDN Web Docs - Using CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables) * [Edge Dev Blog post](https://blogs.windows.com/msedgedev/2017/03/24/css-custom-properties/) * [Polyfill for IE11](https://github.com/nuxodin/ie11CustomProperties)
programming_docs
browser_support_tables Blob URLs Blob URLs ========= Method of creating URL handles to the specified File or Blob object. | | | | --- | --- | | Spec | <https://www.w3.org/TR/FileAPI/#url> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (1) | 108 | 108 | 108 | 16.2 | 92 | | 10 (1) | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 (\*) | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 (1) | 75 | 74 | | 57 | | | 13 (1) | 74 | 73 | | 56 | | | 12 (1) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 (\*) | | 9.5-9.6 | | | | 22 | 21 (\*) | | 9 | | | | 21 | 20 (\*) | | | | | | 20 | 19 (\*) | | | | | | 19 | 18 (\*) | | | | | | 18 | 17 (\*) | | | | | | 17 | 16 (\*) | | | | | | 16 | 15 (\*) | | | | | | 15 | 14 (\*) | | | | | | 14 | 13 (\*) | | | | | | 13 | 12 (\*) | | | | | | 12 | 11 (\*) | | | | | | 11 | 10 (\*) | | | | | | 10 | 9 (\*) | | | | | | 9 | 8 (\*) | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 (\*) | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 (\*) | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 (\*) | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 (\*) | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Created blob url can't be used as object or iframe src \* Partial support with prefix. Bugs ---- * Safari has [a serious issue](https://jsfiddle.net/24FhL/) with blobs that are of the type `application/octet-stream` * Chrome on iOS appears to have an issue when opening Blob URLs in another tab [see workaround](https://stackoverflow.com/questions/24485077/how-to-open-blob-url-on-chrome-ios). The same issue occurs for Samsung Internet. * Internet Explorer intermittently fails to load images via this method. [PDF.js has used data URLs instead](https://github.com/mozilla/pdf.js/issues/3977) Resources --------- * [MDN Web Docs - createObjectURL](https://developer.mozilla.org/en/DOM/window.URL.createObjectURL) browser_support_tables DNSSEC and DANE DNSSEC and DANE =============== Method of validating a DNS response against a trusted root server. Mitigates various attacks that could reroute a user to a fake site while showing the real URL for the original site. | | | | --- | --- | | Spec | <https://tools.ietf.org/html/rfc4033> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (1) | | | | | | 110 (1) | 110 (1) | TP (1) | | | | | 109 (1) | 109 (1) | 16.3 (1) | | | 11 (1) | 108 (1) | 108 (1) | 108 (1) | 16.2 (1) | 92 (1) | | 10 (1) | 107 (1) | 107 (1) | 107 (1) | 16.1 (1) | 91 (1) | | 9 (1) | 106 (1) | 106 (1) | 106 (1) | 16.0 (1) | 90 (1) | | 8 (1) | 105 (1) | 105 (1) | 105 (1) | 15.6 (1) | 89 (1) | | [Show all](#) | | 7 (1) | 104 (1) | 104 (1) | 104 (1) | 15.5 (1) | 88 (1) | | 6 (1) | 103 (1) | 103 (1) | 103 (1) | 15.4 (1) | 87 (1) | | 5.5 (1) | 102 (1) | 102 (1) | 102 (1) | 15.2-15.3 (1) | 86 (1) | | | 101 (1) | 101 (1) | 101 (1) | 15.1 (1) | 85 (1) | | | 100 (1) | 100 (1) | 100 (1) | 15 (1) | 84 (1) | | | 99 (1) | 99 (1) | 99 (1) | 14.1 (1) | 83 (1) | | | 98 (1) | 98 (1) | 98 (1) | 14 (1) | 82 (1) | | | 97 (1) | 97 (1) | 97 (1) | 13.1 (1) | 81 (1) | | | 96 (1) | 96 (1) | 96 (1) | 13 (1) | 80 (1) | | | 95 (1) | 95 (1) | 95 (1) | 12.1 (1) | 79 (1) | | | 94 (1) | 94 (1) | 94 (1) | 12 (1) | 78 (1) | | | 93 (1) | 93 (1) | 93 (1) | 11.1 (1) | 77 (1) | | | 92 (1) | 92 (1) | 92 (1) | 11 (1) | 76 (1) | | | 91 (1) | 91 (1) | 91 (1) | 10.1 (1) | 75 (1) | | | 90 (1) | 90 (1) | 90 (1) | 10 (1) | 74 (1) | | | 89 (1) | 89 (1) | 89 (1) | 9.1 (1) | 73 (1) | | | 88 (1) | 88 (1) | 88 (1) | 9 (1) | 72 (1) | | | 87 (1) | 87 (1) | 87 (1) | 8 (1) | 71 (1) | | | 86 (1) | 86 (1) | 86 (1) | 7.1 (1) | 70 (1) | | | 85 (1) | 85 (1) | 85 (1) | 7 (1) | 69 (1) | | | 84 (1) | 84 (1) | 84 (1) | 6.1 (1) | 68 (1) | | | 83 (1) | 83 (1) | 83 (1) | 6 (1) | 67 (1) | | | 81 (1) | 82 (1) | 81 (1) | 5.1 (1) | 66 (1) | | | 80 (1) | 81 (1) | 80 (1) | 5 (1) | 65 (1) | | | 79 (1) | 80 (1) | 79 (1) | 4 (1) | 64 (1) | | | 18 (1) | 79 (1) | 78 (1) | 3.2 (1) | 63 (1) | | | 17 (1) | 78 (1) | 77 (1) | 3.1 (1) | 62 (1) | | | 16 (1) | 77 (1) | 76 (1) | | 60 (1) | | | 15 (1) | 76 (1) | 75 (1) | | 58 (1) | | | 14 (1) | 75 (1) | 74 (1) | | 57 (1) | | | 13 (1) | 74 (1) | 73 (1) | | 56 (1) | | | 12 (1) | 73 (1) | 72 (1) | | 55 (1) | | | | 72 (1) | 71 (1) | | 54 (1) | | | | 71 (1) | 70 (1) | | 53 (1) | | | | 70 (1) | 69 (1) | | 52 (1) | | | | 69 (1) | 68 (1) | | 51 (1) | | | | 68 (1) | 67 (1) | | 50 (1) | | | | 67 (1) | 66 (1) | | 49 (1) | | | | 66 (1) | 65 (1) | | 48 (1) | | | | 65 (1) | 64 (1) | | 47 (1) | | | | 64 (1) | 63 (1) | | 46 (1) | | | | 63 (1) | 62 (1) | | 45 (1) | | | | 62 (1) | 61 (1) | | 44 (1) | | | | 61 (1) | 60 (1) | | 43 (1) | | | | 60 (1) | 59 (1) | | 42 (1) | | | | 59 (1) | 58 (1) | | 41 (1) | | | | 58 (1) | 57 (1) | | 40 (1) | | | | 57 (1) | 56 (1) | | 39 (1) | | | | 56 (1) | 55 (1) | | 38 (1) | | | | 55 (1) | 54 (1) | | 37 (1) | | | | 54 (1) | 53 (1) | | 36 (1) | | | | 53 (1) | 52 (1) | | 35 (1) | | | | 52 (1) | 51 (1) | | 34 (1) | | | | 51 (1) | 50 (1) | | 33 (1) | | | | 50 (1) | 49 (1) | | 32 (1) | | | | 49 (1) | 48 (1) | | 31 (1) | | | | 48 (1) | 47 (1) | | 30 (1) | | | | 47 (1) | 46 (1) | | 29 (1) | | | | 46 (1) | 45 (1) | | 28 (1) | | | | 45 (1) | 44 (1) | | 27 (1) | | | | 44 (1) | 43 (1) | | 26 (1) | | | | 43 (1) | 42 (1) | | 25 (1) | | | | 42 (1) | 41 (1) | | 24 (1) | | | | 41 (1) | 40 (1) | | 23 (1) | | | | 40 (1) | 39 (1) | | 22 (1) | | | | 39 (1) | 38 (1) | | 21 (1) | | | | 38 (1) | 37 (1) | | 20 (1) | | | | 37 (1) | 36 (1) | | 19 (1) | | | | 36 (1) | 35 (1) | | 18 (1) | | | | 35 (1) | 34 (1) | | 17 (1) | | | | 34 (1) | 33 (1) | | 16 (1) | | | | 33 (1) | 32 (1) | | 15 (1) | | | | 32 (1) | 31 (1) | | 12.1 (1) | | | | 31 (1) | 30 (1,2) | | 12 (1) | | | | 30 (1) | 29 (1,2) | | 11.6 (1) | | | | 29 (1) | 28 (1,2) | | 11.5 (1) | | | | 28 (1) | 27 (1,2) | | 11.1 (1) | | | | 27 (1) | 26 (1,2) | | 11 (1) | | | | 26 (1) | 25 (1,2) | | 10.6 (1) | | | | 25 (1) | 24 (1,2) | | 10.5 (1) | | | | 24 (1) | 23 (1,2) | | 10.0-10.1 (1) | | | | 23 (1) | 22 (1,2) | | 9.5-9.6 (1) | | | | 22 (1) | 21 (1,2) | | 9 (1) | | | | 21 (1) | 20 (1,2) | | | | | | 20 (1) | 19 (1,2) | | | | | | 19 (1) | 18 (1,2) | | | | | | 18 (1) | 17 (1,2) | | | | | | 17 (1) | 16 (1,2) | | | | | | 16 (1) | 15 (1,2) | | | | | | 15 (1) | 14 (1,2) | | | | | | 14 (1) | 13 (1,2) | | | | | | 13 (1) | 12 (1,2) | | | | | | 12 (1) | 11 (1,2) | | | | | | 11 (1) | 10 (1,2) | | | | | | 10 (1) | 9 (1,2) | | | | | | 9 (1) | 8 (1,2) | | | | | | 8 (1) | 7 (1,2) | | | | | | 7 (1) | 6 (1,2) | | | | | | 6 (1) | 5 (1) | | | | | | 5 (1) | 4 (1) | | | | | | 4 (1) | | | | | | | 3.6 (1) | | | | | | | 3.5 (1) | | | | | | | 3 (1) | | | | | | | 2 (1) | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (1) | | | | | | | | | | | | | | 16.2 (1) | all (1) | 108 (1) | 10 (1) | 72 (1) | 108 (1) | 107 (1) | 11 (1) | 13.4 (1) | 19.0 (1) | 13.1 (1) | 13.18 (1) | 2.5 (1) | | 16.1 (1) | | 4.4.3-4.4.4 (1) | 7 (1) | 12.1 (1) | | | 10 (1) | | 18.0 (1) | | | | | 16.0 (1) | | 4.4 (1) | | 12 (1) | | | | | 17.0 (1) | | | | | 15.6 (1) | | 4.2-4.3 (1) | | 11.5 (1) | | | | | 16.0 (1) | | | | | [Show all](#) | | 15.5 (1) | | 4.1 (1) | | 11.1 (1) | | | | | 15.0 (1) | | | | | 15.4 (1) | | 4 (1) | | 11 (1) | | | | | 14.0 (1) | | | | | 15.2-15.3 (1) | | 3 (1) | | 10 (1) | | | | | 13.0 (1) | | | | | 15.0-15.1 (1) | | 2.3 (1) | | | | | | | 12.0 (1) | | | | | 14.5-14.8 (1) | | 2.2 (1) | | | | | | | 11.1-11.2 (1) | | | | | 14.0-14.4 (1) | | 2.1 (1) | | | | | | | 10.1 (1) | | | | | 13.4-13.7 (1) | | | | | | | | | 9.2 (1) | | | | | 13.3 (1) | | | | | | | | | 8.2 (1) | | | | | 13.2 (1) | | | | | | | | | 7.2-7.4 (1) | | | | | 13.0-13.1 (1) | | | | | | | | | 6.2-6.4 (1) | | | | | 12.2-12.5 (1) | | | | | | | | | 5.0-5.4 (1) | | | | | 12.0-12.1 (1) | | | | | | | | | 4 (1) | | | | | 11.3-11.4 (1) | | | | | | | | | | | | | | 11.0-11.2 (1) | | | | | | | | | | | | | | 10.3 (1) | | | | | | | | | | | | | | 10.0-10.2 (1) | | | | | | | | | | | | | | 9.3 (1) | | | | | | | | | | | | | | 9.0-9.2 (1) | | | | | | | | | | | | | | 8.1-8.4 (1) | | | | | | | | | | | | | | 8 (1) | | | | | | | | | | | | | | 7.0-7.1 (1) | | | | | | | | | | | | | | 6.0-6.1 (1) | | | | | | | | | | | | | | 5.0-5.1 (1) | | | | | | | | | | | | | | 4.2-4.3 (1) | | | | | | | | | | | | | | 4.0-4.1 (1) | | | | | | | | | | | | | | 3.2 (1) | | | | | | | | | | | | | Notes ----- Browsers have generally decided to not implement DNSSEC validation because the added complexity outweighs the improvements to the browser. DNSSEC is still useful as it is widely used to protect delivery of records between DNS servers, only failing to protect the delivery from the last DNS server to the browser. [Certificate transparency](https://developer.mozilla.org/en-US/docs/Web/Security/Certificate_Transparency) is widely used and tries to provide the same security as DNSSEC but by very different means. 1. Does not support DNSSEC but still benefits greatly from it, as most of the security improvements are gained in the DNS-network and not in the browser. 2. Early versions of Chrome [experimented](https://www.imperialviolet.org/2011/06/16/dnssecchrome.html) with browser-level validation. Resources --------- * [Wikipedia - DNSSEC](https://en.wikipedia.org/wiki/Domain_Name_System_Security_Extensions) * [Chrome implementation bug](https://bugs.chromium.org/p/chromium/issues/detail?id=50874) * [Firefox implementation bug](https://bugzilla.mozilla.org/show_bug.cgi?id=672600) browser_support_tables Media Source Extensions Media Source Extensions ======================= API allowing media data to be accessed from HTML `video` and `audio` elements. | | | | --- | --- | | Spec | <https://www.w3.org/TR/media-source/> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (1) | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 (\*) | | 12 | | | | 30 | 29 (\*) | | 11.6 | | | | 29 | 28 (\*) | | 11.5 | | | | 28 | 27 (\*) | | 11.1 | | | | 27 | 26 (\*) | | 11 | | | | 26 | 25 (\*) | | 10.6 | | | | 25 | 24 (\*) | | 10.5 | | | | 24 | 23 (\*) | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (2) | | | | | | | | | | | | | | 16.2 (2) | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 (2) | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 (2) | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 (2) | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 (2) | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 (2) | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 (2) | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 (2) | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 (2) | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (2) | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (2) | | | | | | | | | 9.2 | | | | | 13.3 (2) | | | | | | | | | 8.2 | | | | | 13.2 (2) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (2) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Partial support in IE11 refers to only working in Windows 8+ 2. Fully supported only in iPadOS, 13 and later \* Partial support with prefix. Resources --------- * [MDN Web Docs - MediaSource](https://developer.mozilla.org/en-US/docs/Web/API/MediaSource) * [MSDN article](https://msdn.microsoft.com/en-us/library/dn594470%28v=vs.85%29.aspx) * [MediaSource demo](https://simpl.info/mse/)
programming_docs
browser_support_tables Temporal Temporal ======== A modern API for working with date and time, meant to supersede the original `Date` API. | | | | --- | --- | | Spec | <https://tc39.es/proposal-temporal/docs/> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- All browsers are working on implementing this. Resources --------- * [Fixing JavaScript Date](https://maggiepint.com/2017/04/11/fixing-javascript-date-web-compatibility-and-reality/) * [Chromium implementation bug](https://bugs.chromium.org/p/v8/issues/detail?id=11544) * [Firefox implementation bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1519167) * [WebKit implementation bug](https://bugs.webkit.org/show_bug.cgi?id=223166) * [Blog post: Temporal: getting started with JavaScript’s new date time API](https://2ality.com/2021/06/temporal-api.html) browser_support_tables CSS Containment CSS Containment =============== The CSS `contain` property lets developers limit the scope of the browser's styles, layout and paint work for faster and more efficient rendering. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css-contain-1/#contain-property> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 (1) | 67 | | 50 | | | | 67 (1) | 66 | | 49 | | | | 66 (1) | 65 | | 48 | | | | 65 (1) | 64 | | 47 | | | | 64 (1) | 63 | | 46 | | | | 63 (1) | 62 | | 45 | | | | 62 (1) | 61 | | 44 | | | | 61 (1) | 60 | | 43 | | | | 60 (1) | 59 | | 42 | | | | 59 (1) | 58 | | 41 | | | | 58 (1) | 57 | | 40 | | | | 57 (1) | 56 | | 39 | | | | 56 (1) | 55 | | 38 | | | | 55 (1) | 54 | | 37 | | | | 54 (1) | 53 | | 36 | | | | 53 (1) | 52 | | 35 | | | | 52 (1) | 51 | | 34 | | | | 51 (1) | 50 | | 33 | | | | 50 (1) | 49 | | 32 | | | | 49 (1) | 48 | | 31 | | | | 48 (1) | 47 | | 30 | | | | 47 (1) | 46 | | 29 | | | | 46 (1) | 45 | | 28 | | | | 45 (1) | 44 | | 27 | | | | 44 (1) | 43 | | 26 | | | | 43 (1) | 42 | | 25 | | | | 42 (1) | 41 | | 24 | | | | 41 (1) | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (1) | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled in older Gecko engines with the `layout.css.contain.enabled` flag in about:config 2. Partially supported in Firefox by enabling "layout.css.contain.enabled" in about:config 3. Supported in Safari TP by enabling "CSS Containment" under the "Experimental Features" menu Resources --------- * [Google Developers article](https://developers.google.com/web/updates/2016/06/css-containment) browser_support_tables Basic console logging functions Basic console logging functions =============================== Method of outputting data to the browser's console, intended for development purposes. | | | | --- | --- | | Spec | <https://console.spec.whatwg.org/> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 (1) | 106 | 106 | 106 | 16.0 | 90 | | 8 (1) | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (3) | | | | | | | | | | | | | | 16.2 (3) | all (6) | 108 (4) | 10 (2) | 72 (4) | 108 (4) | 107 (5) | 11 (2) | 13.4 (2) | 19.0 (4) | 13.1 | 13.18 (4) | 2.5 | | 16.1 (3) | | 4.4.3-4.4.4 (4) | 7 (2) | 12.1 (2) | | | 10 (2) | | 18.0 (4) | | | | | 16.0 (3) | | 4.4 (4) | | 12 (2) | | | | | 17.0 (4) | | | | | 15.6 (3) | | 4.2-4.3 (4) | | 11.5 (2) | | | | | 16.0 (4) | | | | | [Show all](#) | | 15.5 (3) | | 4.1 (4) | | 11.1 (2) | | | | | 15.0 (4) | | | | | 15.4 (3) | | 4 (4) | | 11 (2) | | | | | 14.0 (4) | | | | | 15.2-15.3 (3) | | 3 (4) | | 10 | | | | | 13.0 (4) | | | | | 15.0-15.1 (3) | | 2.3 (4) | | | | | | | 12.0 (4) | | | | | 14.5-14.8 (3) | | 2.2 (4) | | | | | | | 11.1-11.2 (4) | | | | | 14.0-14.4 (3) | | 2.1 (4) | | | | | | | 10.1 (4) | | | | | 13.4-13.7 (3) | | | | | | | | | 9.2 (4) | | | | | 13.3 (3) | | | | | | | | | 8.2 (4) | | | | | 13.2 (3) | | | | | | | | | 7.2-7.4 (4) | | | | | 13.0-13.1 (3) | | | | | | | | | 6.2-6.4 (4) | | | | | 12.2-12.5 (3) | | | | | | | | | 5.0-5.4 (4) | | | | | 12.0-12.1 (3) | | | | | | | | | 4 (4) | | | | | 11.3-11.4 (3) | | | | | | | | | | | | | | 11.0-11.2 (3) | | | | | | | | | | | | | | 10.3 (3) | | | | | | | | | | | | | | 10.0-10.2 (3) | | | | | | | | | | | | | | 9.3 (3) | | | | | | | | | | | | | | 9.0-9.2 (3) | | | | | | | | | | | | | | 8.1-8.4 (3) | | | | | | | | | | | | | | 8 (3) | | | | | | | | | | | | | | 7.0-7.1 (3) | | | | | | | | | | | | | | 6.0-6.1 (3) | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- The basic functions that this information refers to include `console.log`, `console.info`, `console.warn`, `console.error`. 1. Only supports console functions when developer tools are open, otherwise the `console` object is undefined and any calls will throw errors. 2. Allows `console` functions to be used without throwing errors, but does not appear to output the data anywhere. 3. Log output on iOS 6+ Safari can only be seen by connecting to a Mac and using the [Safari debugger](https://developer.apple.com/safari/tools/). 4. Log output on older Android browsers can be retrieved via Android's `logcat` command or using Chrome Developer Tools in Android 4.4+/Chrome for Android [see details](https://developer.android.com/guide/webapps/debugging.html) 5. Log output on Firefox for Android can be [accessed using WebIDE](https://developer.mozilla.org/en-US/docs/Tools/Remote_Debugging/Debugging_Firefox_for_Android_with_WebIDE) 6. See [this article](https://dev.opera.com/articles/opera-mini-and-javascript/) for details on how to see console logging in Opera Mini Resources --------- * [MDN Web Docs - Console](https://developer.mozilla.org/en-US/docs/Web/API/Console) * [Chrome console reference](https://developer.chrome.com/devtools/docs/console-api) * [Edge/Internet Explorer console reference](https://msdn.microsoft.com/en-us/library/hh772169)
programming_docs
browser_support_tables navigator.hardwareConcurrency navigator.hardwareConcurrency ============================= Returns the number of logical cores of the user's CPU. The value may be reduced to prevent device fingerprinting or because it exceeds the allowed number of simultaneous web workers. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/workers.html#navigator.hardwareconcurrency> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP (1) | | | | | 109 | 109 | 16.3 (1) | | | 11 | 108 | 108 | 108 | 16.2 (1) | 92 | | 10 | 107 | 107 | 107 | 16.1 (1) | 91 | | 9 | 106 | 106 | 106 | 16.0 (1) | 90 | | 8 | 105 | 105 | 105 | 15.6 (1) | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 (1) | 88 | | 6 | 103 | 103 | 103 | 15.4 (1) | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 (1) | 86 | | | 101 | 101 | 101 | 15.1 (1) | 85 | | | 100 | 100 | 100 | 15 (1) | 84 | | | 99 | 99 | 99 | 14.1 (1) | 83 | | | 98 | 98 | 98 | 14 (1) | 82 | | | 97 | 97 | 97 | 13.1 (1) | 81 | | | 96 | 96 | 96 | 13 (1) | 80 | | | 95 | 95 | 95 | 12.1 (1) | 79 | | | 94 | 94 | 94 | 12 (1) | 78 | | | 93 | 93 | 93 | 11.1 (1) | 77 | | | 92 | 92 | 92 | 11 (1) | 76 | | | 91 | 91 | 91 | 10.1 (1) | 75 | | | 90 | 90 | 90 | 10 (1) | 74 | | | 89 | 89 | 89 | 9.1 (1) | 73 | | | 88 | 88 | 88 | 9 (1) | 72 | | | 87 | 87 | 87 | 8 (1) | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (1) | | | | | | | | | | | | | | 16.2 (1) | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 (1) | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 (1) | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 (1) | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 (1) | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 (1) | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 (1) | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 (1) | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 (1) | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (1) | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (1) | | | | | | | | | 9.2 | | | | | 13.3 (1) | | | | | | | | | 8.2 | | | | | 13.2 (1) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (1) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (1) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 (1) | | | | | | | | | 4 | | | | | 11.3-11.4 (1) | | | | | | | | | | | | | | 11.0-11.2 (1) | | | | | | | | | | | | | | 10.3 (1) | | | | | | | | | | | | | | 10.0-10.2 (1) | | | | | | | | | | | | | | 9.3 (1) | | | | | | | | | | | | | | 9.0-9.2 (1) | | | | | | | | | | | | | | 8.1-8.4 (1) | | | | | | | | | | | | | | 8 (1) | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. WebKit browsers clamp the maximum value returned to 2 on iOS devices and 8 on all others. Disabled in Safari behind the ENABLE\_NAVIGATOR\_HWCONCURRENCY build option. Resources --------- * [MDN Web Docs - navigator.hardwareConcurrency](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorConcurrentHardware/hardwareConcurrency) * [Original Proposal](https://wiki.whatwg.org/wiki/Navigator_HW_Concurrency) * [WebKit implementation bug](https://bugs.webkit.org/show_bug.cgi?id=132588) browser_support_tables Font unicode-range subsetting Font unicode-range subsetting ============================= This @font-face descriptor defines the set of Unicode codepoints that may be supported by the font face for which it is declared. The descriptor value is a comma-delimited list of Unicode range (<urange>) values. The union of these ranges defines the set of codepoints that serves as a hint for user agents when deciding whether or not to download a font resource for a given text run. | | | | --- | --- | | Spec | <https://w3c.github.io/csswg-drafts/css-fonts/#unicode-range-desc> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 (1) | 42 | | 25 | | | | 42 (1) | 41 | | 24 | | | | 41 (1) | 40 | | 23 | | | | 40 (1) | 39 | | 22 | | | | 39 (1) | 38 | | 21 | | | | 38 (1) | 37 | | 20 | | | | 37 (1) | 36 | | 19 | | | | 36 (1) | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Partial support indicates that unnecessary code-ranges are downloaded by the browser - see [browser test matrix](https://docs.google.com/a/chromium.org/spreadsheets/d/18h-1gaosu4-KYxH8JUNL6ZDuOsOKmWfauoai3CS3hPY/edit?pli=1#gid=0). 1. Can be enabled in Firefox using the `layout.css.unicode-range.enabled` flag Bugs ---- * Firefox 37- [ignores the descriptor](https://developer.mozilla.org/en-US/docs/Web/CSS/unicode-range#Browser_compatibility) and the at-rule is then applied to the whole range of code points. * IE ignores the unicode-range if the U is lowercase e.g 'u+0061'. Resources --------- * [MDN Web Docs - CSS unicode-range](https://developer.mozilla.org/en-US/docs/Web/CSS/unicode-range) * [Safari CSS Reference: unicode-range](https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html#//apple_ref/css/property/unicode-range) * [Web Platform Docs: unicode-range](https://webplatform.github.io/docs/css/properties/unicode-range) * [Demo](https://jsbin.com/jeqoguzeye/1/edit?html,output) browser_support_tables Filesystem & FileWriter API Filesystem & FileWriter API =========================== Method of reading and writing files to a sandboxed file system. | | | | --- | --- | | Spec | <https://www.w3.org/TR/file-system-api/> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (\*) | | | | | | 110 | 110 (\*) | TP | | | | | 109 | 109 (\*) | 16.3 | | | 11 | 108 (\*) | 108 | 108 (\*) | 16.2 | 92 (\*) | | 10 | 107 (\*) | 107 | 107 (\*) | 16.1 | 91 (\*) | | 9 | 106 (\*) | 106 | 106 (\*) | 16.0 | 90 (\*) | | 8 | 105 (\*) | 105 | 105 (\*) | 15.6 | 89 (\*) | | [Show all](#) | | 7 | 104 (\*) | 104 | 104 (\*) | 15.5 | 88 (\*) | | 6 | 103 (\*) | 103 | 103 (\*) | 15.4 | 87 (\*) | | 5.5 | 102 (\*) | 102 | 102 (\*) | 15.2-15.3 | 86 (\*) | | | 101 (\*) | 101 | 101 (\*) | 15.1 | 85 (\*) | | | 100 (\*) | 100 | 100 (\*) | 15 | 84 (\*) | | | 99 (\*) | 99 | 99 (\*) | 14.1 | 83 (\*) | | | 98 (\*) | 98 | 98 (\*) | 14 | 82 (\*) | | | 97 (\*) | 97 | 97 (\*) | 13.1 | 81 (\*) | | | 96 (\*) | 96 | 96 (\*) | 13 | 80 (\*) | | | 95 (\*) | 95 | 95 (\*) | 12.1 | 79 (\*) | | | 94 (\*) | 94 | 94 (\*) | 12 | 78 (\*) | | | 93 (\*) | 93 | 93 (\*) | 11.1 | 77 (\*) | | | 92 (\*) | 92 | 92 (\*) | 11 | 76 (\*) | | | 91 (\*) | 91 | 91 (\*) | 10.1 | 75 (\*) | | | 90 (\*) | 90 | 90 (\*) | 10 | 74 (\*) | | | 89 (\*) | 89 | 89 (\*) | 9.1 | 73 (\*) | | | 88 (\*) | 88 | 88 (\*) | 9 | 72 (\*) | | | 87 (\*) | 87 | 87 (\*) | 8 | 71 (\*) | | | 86 (\*) | 86 | 86 (\*) | 7.1 | 70 (\*) | | | 85 (\*) | 85 | 85 (\*) | 7 | 69 (\*) | | | 84 (\*) | 84 | 84 (\*) | 6.1 | 68 (\*) | | | 83 (\*) | 83 | 83 (\*) | 6 | 67 (\*) | | | 81 (\*) | 82 | 81 (\*) | 5.1 | 66 (\*) | | | 80 (\*) | 81 | 80 (\*) | 5 | 65 (\*) | | | 79 (\*) | 80 | 79 (\*) | 4 | 64 (\*) | | | 18 | 79 | 78 (\*) | 3.2 | 63 (\*) | | | 17 | 78 | 77 (\*) | 3.1 | 62 (\*) | | | 16 | 77 | 76 (\*) | | 60 (\*) | | | 15 | 76 | 75 (\*) | | 58 (\*) | | | 14 | 75 | 74 (\*) | | 57 (\*) | | | 13 | 74 | 73 (\*) | | 56 (\*) | | | 12 | 73 | 72 (\*) | | 55 (\*) | | | | 72 | 71 (\*) | | 54 (\*) | | | | 71 | 70 (\*) | | 53 (\*) | | | | 70 | 69 (\*) | | 52 (\*) | | | | 69 | 68 (\*) | | 51 (\*) | | | | 68 | 67 (\*) | | 50 (\*) | | | | 67 | 66 (\*) | | 49 (\*) | | | | 66 | 65 (\*) | | 48 (\*) | | | | 65 | 64 (\*) | | 47 (\*) | | | | 64 | 63 (\*) | | 46 (\*) | | | | 63 | 62 (\*) | | 45 (\*) | | | | 62 | 61 (\*) | | 44 (\*) | | | | 61 | 60 (\*) | | 43 (\*) | | | | 60 | 59 (\*) | | 42 (\*) | | | | 59 | 58 (\*) | | 41 (\*) | | | | 58 | 57 (\*) | | 40 (\*) | | | | 57 | 56 (\*) | | 39 (\*) | | | | 56 | 55 (\*) | | 38 (\*) | | | | 55 | 54 (\*) | | 37 (\*) | | | | 54 | 53 (\*) | | 36 (\*) | | | | 53 | 52 (\*) | | 35 (\*) | | | | 52 | 51 (\*) | | 34 (\*) | | | | 51 | 50 (\*) | | 33 (\*) | | | | 50 | 49 (\*) | | 32 (\*) | | | | 49 | 48 (\*) | | 31 (\*) | | | | 48 | 47 (\*) | | 30 (\*) | | | | 47 | 46 (\*) | | 29 (\*) | | | | 46 | 45 (\*) | | 28 (\*) | | | | 45 | 44 (\*) | | 27 (\*) | | | | 44 | 43 (\*) | | 26 (\*) | | | | 43 | 42 (\*) | | 25 (\*) | | | | 42 | 41 (\*) | | 24 (\*) | | | | 41 | 40 (\*) | | 23 (\*) | | | | 40 | 39 (\*) | | 22 (\*) | | | | 39 | 38 (\*) | | 21 (\*) | | | | 38 | 37 (\*) | | 20 (\*) | | | | 37 | 36 (\*) | | 19 (\*) | | | | 36 | 35 (\*) | | 18 (\*) | | | | 35 | 34 (\*) | | 17 (\*) | | | | 34 | 33 (\*) | | 16 (\*) | | | | 33 | 32 (\*) | | 15 (\*) | | | | 32 | 31 (\*) | | 12.1 | | | | 31 | 30 (\*) | | 12 | | | | 30 | 29 (\*) | | 11.6 | | | | 29 | 28 (\*) | | 11.5 | | | | 28 | 27 (\*) | | 11.1 | | | | 27 | 26 (\*) | | 11 | | | | 26 | 25 (\*) | | 10.6 | | | | 25 | 24 (\*) | | 10.5 | | | | 24 | 23 (\*) | | 10.0-10.1 | | | | 23 | 22 (\*) | | 9.5-9.6 | | | | 22 | 21 (\*) | | 9 | | | | 21 | 20 (\*) | | | | | | 20 | 19 (\*) | | | | | | 19 | 18 (\*) | | | | | | 18 | 17 (\*) | | | | | | 17 | 16 (\*) | | | | | | 16 | 15 (\*) | | | | | | 15 | 14 (\*) | | | | | | 14 | 13 (\*) | | | | | | 13 | 12 (\*) | | | | | | 12 | 11 (\*) | | | | | | 11 | 10 (\*) | | | | | | 10 | 9 (\*) | | | | | | 9 | 8 (\*) | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 (\*) | 72 (\*) | 108 (\*) | 107 | 11 | 13.4 (\*) | 19.0 (\*) | 13.1 | 13.18 (\*) | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 (\*) | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 (\*) | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 (\*) | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 (\*) | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 (\*) | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 (\*) | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 (\*) | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 (\*) | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 (\*) | | | | | 13.4-13.7 | | | | | | | | | 9.2 (\*) | | | | | 13.3 | | | | | | | | | 8.2 (\*) | | | | | 13.2 | | | | | | | | | 7.2-7.4 (\*) | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 (\*) | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 (\*) | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- The File API: Directories and System specification is no longer being maintained and support may be dropped in future versions. \* Partial support with prefix. Resources --------- * [HTML5 Rocks tutorial](https://www.html5rocks.com/en/tutorials/file/filesystem/) * [WebPlatform Docs](https://webplatform.github.io/docs/apis/filesystem) * [Firefox tracking bug](https://bugzilla.mozilla.org/show_bug.cgi?id=997471)
programming_docs
browser_support_tables CSS Nesting CSS Nesting =========== CSS nesting provides the ability to nest one style rule inside another, with the selector of the child rule relative to the selector of the parent rule. Similar behavior previously required a CSS pre-processor. | | | | --- | --- | | Spec | <https://w3c.github.io/csswg-drafts/css-nesting/> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (1) | | | | | | 110 | 110 (1) | TP | | | | | 109 | 109 (1) | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Available behind the [Experimental Web Platform features](chrome://flags/#enable-experimental-web-platform-features) flag Resources --------- * [Chrome support bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1095675) * [Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1648037) * [Safari support bug](https://bugs.webkit.org/show_bug.cgi?id=223497) * [Blog post: CSS Nesting, specificity and you](https://kilianvalkhof.com/2021/css-html/css-nesting-specificity-and-you/) browser_support_tables Media Fragments Media Fragments =============== Allows only part of a resource to be shown, based on the fragment identifier in the URL. Currently support is primarily limited to video track ranges. | | | | --- | --- | | Spec | <https://www.w3.org/TR/media-frags/> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (1) | | | | | | 110 (1) | 110 (1) | TP (1) | | | | | 109 (1) | 109 (1) | 16.3 (1) | | | 11 | 108 (1) | 108 (1) | 108 (1) | 16.2 (1) | 92 (1) | | 10 | 107 (1) | 107 (1) | 107 (1) | 16.1 (1) | 91 (1) | | 9 | 106 (1) | 106 (1) | 106 (1) | 16.0 (1) | 90 (1) | | 8 | 105 (1) | 105 (1) | 105 (1) | 15.6 (1) | 89 (1) | | [Show all](#) | | 7 | 104 (1) | 104 (1) | 104 (1) | 15.5 (1) | 88 (1) | | 6 | 103 (1) | 103 (1) | 103 (1) | 15.4 (1) | 87 (1) | | 5.5 | 102 (1) | 102 (1) | 102 (1) | 15.2-15.3 (1) | 86 (1) | | | 101 (1) | 101 (1) | 101 (1) | 15.1 (1) | 85 (1) | | | 100 (1) | 100 (1) | 100 (1) | 15 (1) | 84 (1) | | | 99 (1) | 99 (1) | 99 (1) | 14.1 (1) | 83 (1) | | | 98 (1) | 98 (1) | 98 (1) | 14 (1) | 82 (1) | | | 97 (1) | 97 (1) | 97 (1) | 13.1 (1) | 81 (1) | | | 96 (1) | 96 (1) | 96 (1) | 13 (1) | 80 (1) | | | 95 (1) | 95 (1) | 95 (1) | 12.1 (1) | 79 (1) | | | 94 (1) | 94 (1) | 94 (1) | 12 (1) | 78 (1) | | | 93 (1) | 93 (1) | 93 (1) | 11.1 (1) | 77 (1) | | | 92 (1) | 92 (1) | 92 (1) | 11 (1) | 76 (1) | | | 91 (1) | 91 (1) | 91 (1) | 10.1 (1) | 75 (1) | | | 90 (1) | 90 (1) | 90 (1) | 10 (1) | 74 (1) | | | 89 (1) | 89 (1) | 89 (1) | 9.1 (1) | 73 (1) | | | 88 (1) | 88 (1) | 88 (1) | 9 (1) | 72 (1) | | | 87 (1) | 87 (1) | 87 (1) | 8 (1) | 71 (1) | | | 86 (1) | 86 (1) | 86 (1) | 7.1 (1) | 70 (1) | | | 85 (1) | 85 (1) | 85 (1) | 7 (1) | 69 (1) | | | 84 (1) | 84 (1) | 84 (1) | 6.1 (1) | 68 (1) | | | 83 (1) | 83 (1) | 83 (1) | 6 (1) | 67 (1) | | | 81 (1) | 82 (1) | 81 (1) | 5.1 | 66 (1) | | | 80 (1) | 81 (1) | 80 (1) | 5 | 65 (1) | | | 79 (1) | 80 (1) | 79 (1) | 4 | 64 (1) | | | 18 | 79 (1) | 78 (1) | 3.2 | 63 (1) | | | 17 | 78 (1) | 77 (1) | 3.1 | 62 (1) | | | 16 | 77 (1) | 76 (1) | | 60 (1) | | | 15 | 76 (1) | 75 (1) | | 58 (1) | | | 14 | 75 (1) | 74 (1) | | 57 (1) | | | 13 | 74 (1) | 73 (1) | | 56 (1) | | | 12 | 73 (1) | 72 (1) | | 55 (1) | | | | 72 (1) | 71 (1) | | 54 (1) | | | | 71 (1) | 70 (1) | | 53 (1) | | | | 70 (1) | 69 (1) | | 52 (1) | | | | 69 (1) | 68 (1) | | 51 (1) | | | | 68 (1) | 67 (1) | | 50 (1) | | | | 67 (1) | 66 (1) | | 49 (1) | | | | 66 (1) | 65 (1) | | 48 (1) | | | | 65 (1) | 64 (1) | | 47 (1) | | | | 64 (1) | 63 (1) | | 46 (1) | | | | 63 (1) | 62 (1) | | 45 (1) | | | | 62 (1) | 61 (1) | | 44 (1) | | | | 61 (1) | 60 (1) | | 43 (1) | | | | 60 (1) | 59 (1) | | 42 (1) | | | | 59 (1) | 58 (1) | | 41 (1) | | | | 58 (1) | 57 (1) | | 40 (1) | | | | 57 (1) | 56 (1) | | 39 (1) | | | | 56 (1) | 55 (1) | | 38 (1) | | | | 55 (1) | 54 (1) | | 37 (1) | | | | 54 (1) | 53 (1) | | 36 (1) | | | | 53 (1) | 52 (1) | | 35 (1) | | | | 52 (1) | 51 (1) | | 34 (1) | | | | 51 (1) | 50 (1) | | 33 (1) | | | | 50 (1) | 49 (1) | | 32 (1) | | | | 49 (1) | 48 (1) | | 31 (1) | | | | 48 (1) | 47 (1) | | 30 (1) | | | | 47 (1) | 46 (1) | | 29 (1) | | | | 46 (1) | 45 (1) | | 28 (1) | | | | 45 (1) | 44 (1) | | 27 (1) | | | | 44 (1) | 43 (1) | | 26 (1) | | | | 43 (1) | 42 (1) | | 25 (1) | | | | 42 (1) | 41 (1) | | 24 (1) | | | | 41 (1) | 40 (1) | | 23 (1) | | | | 40 (1) | 39 (1) | | 22 (1) | | | | 39 (1) | 38 (1) | | 21 (1) | | | | 38 (1) | 37 (1) | | 20 (1) | | | | 37 (1) | 36 (1) | | 19 (1) | | | | 36 (1) | 35 (1) | | 18 (1) | | | | 35 (1) | 34 (1) | | 17 (1) | | | | 34 (1) | 33 (1) | | 16 (1) | | | | 33 | 32 (1) | | 15 (1) | | | | 32 | 31 (1) | | 12.1 | | | | 31 | 30 (1) | | 12 | | | | 30 | 29 (1) | | 11.6 | | | | 29 | 28 (1) | | 11.5 | | | | 28 | 27 (1) | | 11.1 | | | | 27 | 26 (1) | | 11 | | | | 26 | 25 (1) | | 10.6 | | | | 25 | 24 (1) | | 10.5 | | | | 24 | 23 (1) | | 10.0-10.1 | | | | 23 | 22 (1) | | 9.5-9.6 | | | | 22 | 21 (1) | | 9 | | | | 21 | 20 (1) | | | | | | 20 | 19 (1) | | | | | | 19 | 18 (1) | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (1) | | | | | | | | | | | | | | 16.2 (1) | all | 108 (1) | 10 | 72 (1) | 108 (1) | 107 (1) | 11 (1) | 13.4 (1) | 19.0 (1) | 13.1 (1) | 13.18 (1) | 2.5 (1) | | 16.1 (1) | | 4.4.3-4.4.4 (1) | 7 | 12.1 | | | 10 (1) | | 18.0 (1) | | | | | 16.0 (1) | | 4.4 (1) | | 12 | | | | | 17.0 (1) | | | | | 15.6 (1) | | 4.2-4.3 | | 11.5 | | | | | 16.0 (1) | | | | | [Show all](#) | | 15.5 (1) | | 4.1 | | 11.1 | | | | | 15.0 (1) | | | | | 15.4 (1) | | 4 | | 11 | | | | | 14.0 (1) | | | | | 15.2-15.3 (1) | | 3 | | 10 | | | | | 13.0 (1) | | | | | 15.0-15.1 (1) | | 2.3 | | | | | | | 12.0 (1) | | | | | 14.5-14.8 (1) | | 2.2 | | | | | | | 11.1-11.2 (1) | | | | | 14.0-14.4 (1) | | 2.1 | | | | | | | 10.1 (1) | | | | | 13.4-13.7 (1) | | | | | | | | | 9.2 (1) | | | | | 13.3 (1) | | | | | | | | | 8.2 (1) | | | | | 13.2 (1) | | | | | | | | | 7.2-7.4 (1) | | | | | 13.0-13.1 (1) | | | | | | | | | 6.2-6.4 (1) | | | | | 12.2-12.5 (1) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 (1) | | | | | | | | | 4 | | | | | 11.3-11.4 (1) | | | | | | | | | | | | | | 11.0-11.2 (1) | | | | | | | | | | | | | | 10.3 (1) | | | | | | | | | | | | | | 10.0-10.2 (1) | | | | | | | | | | | | | | 9.3 (1) | | | | | | | | | | | | | | 9.0-9.2 (1) | | | | | | | | | | | | | | 8.1-8.4 (1) | | | | | | | | | | | | | | 8 (1) | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Only appears to support the `#t=n,n` control for selecting a range of video, and possibly `track=(name)` & `id=(name)` (not yet tested) Resources --------- * [Media fragments on MDN](https://developer.mozilla.org/de/docs/Web/HTML/Using_HTML5_audio_and_video#Specifying_playback_range) browser_support_tables Screen Orientation Screen Orientation ================== Provides the ability to read the screen orientation state, to be informed when this state changes, and to be able to lock the screen orientation to a specific state. | | | | --- | --- | | Spec | <https://www.w3.org/TR/screen-orientation/> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (1,\*) | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 (\*) | 79 | 78 | 3.2 | 63 | | | 17 (\*) | 78 | 77 | 3.1 | 62 | | | 16 (\*) | 77 | 76 | | 60 | | | 15 (\*) | 76 | 75 | | 58 | | | 14 (\*) | 75 | 74 | | 57 | | | 13 (\*) | 74 | 73 | | 56 | | | 12 (\*) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 (\*) | 42 | | 25 | | | | 42 (\*) | 41 | | 24 | | | | 41 (\*) | 40 | | 23 | | | | 40 (\*) | 39 | | 22 | | | | 39 (\*) | 38 | | 21 | | | | 38 (\*) | 37 | | 20 | | | | 37 (\*) | 36 | | 19 | | | | 36 (\*) | 35 | | 18 | | | | 35 (\*) | 34 | | 17 | | | | 34 (\*) | 33 | | 16 | | | | 33 (\*) | 32 | | 15 | | | | 32 (\*) | 31 | | 12.1 | | | | 31 (\*) | 30 | | 12 | | | | 30 (\*) | 29 | | 11.6 | | | | 29 (\*) | 28 | | 11.5 | | | | 28 (\*) | 27 | | 11.1 | | | | 27 (\*) | 26 | | 11 | | | | 26 (\*) | 25 | | 10.6 | | | | 25 (\*) | 24 | | 10.5 | | | | 24 (\*) | 23 | | 10.0-10.1 | | | | 23 (\*) | 22 | | 9.5-9.6 | | | | 22 (\*) | 21 | | 9 | | | | 21 (\*) | 20 | | | | | | 20 (\*) | 19 | | | | | | 19 (\*) | 18 | | | | | | 18 (\*) | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 (\*) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Partial support refers to an [older version](https://www.w3.org/TR/2014/WD-screen-orientation-20140220/) of the draft specification, and the spec has undergone significant changes since, for example renaming the `screen.lockOrientation` method to `screen.orientation.lock`. 1. Not supported on Windows 7. \* Partial support with prefix. Resources --------- * [Demo](https://www.audero.it/demo/screen-orientation-api-demo.html) * [MDN Web Docs - Screen Orientation](https://developer.mozilla.org/en-US/docs/Web/API/Screen.orientation) * [SitePoint article](https://www.sitepoint.com/introducing-screen-orientation-api/)
programming_docs
browser_support_tables :placeholder-shown CSS pseudo-class :placeholder-shown CSS pseudo-class =================================== Input elements can sometimes show placeholder text as a hint to the user on what to type in. See, for example, the placeholder attribute in HTML5. The :placeholder-shown pseudo-class matches an input element that is showing such placeholder text. | | | | --- | --- | | Spec | <https://www.w3.org/TR/selectors4/#placeholder> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (2,\*) | 108 | 108 | 108 | 16.2 | 92 | | 10 (2,\*) | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 (1,\*) | 49 | | 32 | | | | 49 (1,\*) | 48 | | 31 | | | | 48 (1,\*) | 47 | | 30 | | | | 47 (1,\*) | 46 | | 29 | | | | 46 (1,\*) | 45 | | 28 | | | | 45 (1,\*) | 44 | | 27 | | | | 44 (1,\*) | 43 | | 26 | | | | 43 (1,\*) | 42 | | 25 | | | | 42 (1,\*) | 41 | | 24 | | | | 41 (1,\*) | 40 | | 23 | | | | 40 (1,\*) | 39 | | 22 | | | | 39 (1,\*) | 38 | | 21 | | | | 38 (1,\*) | 37 | | 20 | | | | 37 (1,\*) | 36 | | 19 | | | | 36 (1,\*) | 35 | | 18 | | | | 35 (1,\*) | 34 | | 17 | | | | 34 (1,\*) | 33 | | 16 | | | | 33 (1,\*) | 32 | | 15 | | | | 32 (1,\*) | 31 | | 12.1 | | | | 31 (1,\*) | 30 | | 12 | | | | 30 (1,\*) | 29 | | 11.6 | | | | 29 (1,\*) | 28 | | 11.5 | | | | 28 (1,\*) | 27 | | 11.1 | | | | 27 (1,\*) | 26 | | 11 | | | | 26 (1,\*) | 25 | | 10.6 | | | | 25 (1,\*) | 24 | | 10.5 | | | | 24 (1,\*) | 23 | | 10.0-10.1 | | | | 23 (1,\*) | 22 | | 9.5-9.6 | | | | 22 (1,\*) | 21 | | 9 | | | | 21 (1,\*) | 20 | | | | | | 20 (1,\*) | 19 | | | | | | 19 (1,\*) | 18 | | | | | | 18 (1,\*) | 17 | | | | | | 17 (1,\*) | 16 | | | | | | 16 (1,\*) | 15 | | | | | | 15 (1,\*) | 14 | | | | | | 14 (1,\*) | 13 | | | | | | 13 (1,\*) | 12 | | | | | | 12 (1,\*) | 11 | | | | | | 11 (1,\*) | 10 | | | | | | 10 (1,\*) | 9 | | | | | | 9 (1,\*) | 8 | | | | | | 8 (1,\*) | 7 | | | | | | 7 (1,\*) | 6 | | | | | | 6 (1,\*) | 5 | | | | | | 5 (1,\*) | 4 | | | | | | 4 (1,\*) | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (1,\*) | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- For support of styling the actual placeholder text itself, see [CSS ::placeholder](https://caniuse.com/#feat=css-placeholder) 1. Partial support in Firefox refers to using the non-standard `:-moz-placeholder` name rather than `:placeholder-shown`. 2. Partial support in IE refers to using the non-standard `:-ms-input-placeholder` name rather than `:placeholder-shown`. \* Partial support with prefix. Resources --------- * [WebKit commit](https://trac.webkit.org/changeset/172826) * [Firefox bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1069015) browser_support_tables CSS Motion Path CSS Motion Path =============== Allows elements to be animated along SVG paths or shapes via the `offset-path` property. Originally defined as the `motion-path` property. | | | | --- | --- | | Spec | <https://www.w3.org/TR/motion-1/> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 (1) | | | | 49 | 48 | | 31 (1) | | | | 48 | 47 | | 30 (1) | | | | 47 | 46 | | 29 | | | | 46 | 45 (1) | | 28 | | | | 45 | 44 (1) | | 27 | | | | 44 | 43 (1) | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Requires the "Experimental Web Platform features" flag to be enabled Resources --------- * [Blog post](https://codepen.io/danwilson/post/css-motion-paths) * [MDN Web Docs - CSS motion-path](https://developer.mozilla.org/en-US/docs/Web/CSS/motion-path) * [Demo](https://googlechrome.github.io/samples/css-motion-path/index.html) * [Firefox tracking bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1186329) browser_support_tables Scoped CSS Scoped CSS ========== Allows CSS rules to be scoped to part of the document, based on the position of the style element. The attribute has been [removed from the current specification](https://github.com/whatwg/html/issues/552). | | | | --- | --- | | Spec | <https://www.w3.org/TR/html51/document-metadata.html#element-attrdef-style-scoped> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 (2) | 59 | | 42 | | | | 59 (2) | 58 | | 41 | | | | 58 (2) | 57 | | 40 | | | | 57 (2) | 56 | | 39 | | | | 56 (2) | 55 | | 38 | | | | 55 (2) | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 (1) | | 19 | | | | 36 | 35 (1) | | 18 | | | | 35 | 34 (1) | | 17 | | | | 34 | 33 (1) | | 16 | | | | 33 | 32 (1) | | 15 | | | | 32 | 31 (1) | | 12.1 | | | | 31 | 30 (1) | | 12 | | | | 30 | 29 (1) | | 11.6 | | | | 29 | 28 (1) | | 11.5 | | | | 28 | 27 (1) | | 11.1 | | | | 27 | 26 (1) | | 11 | | | | 26 | 25 (1) | | 10.6 | | | | 25 | 24 (1) | | 10.5 | | | | 24 | 23 (1) | | 10.0-10.1 | | | | 23 | 22 (1) | | 9.5-9.6 | | | | 22 | 21 (1) | | 9 | | | | 21 | 20 (1) | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Enabled in Chrome through the "experimental Web Platform features" flag in chrome://flags 2. Enabled in Firefox through the about:config setting "layout.css.scoped-style.enabled" Resources --------- * [Polyfill](https://github.com/PM5544/scoped-polyfill) * [HTML5 Doctor article](https://html5doctor.com/the-scoped-attribute/) * [HTML5Rocks article](https://developer.chrome.com/blog/a-new-experimental-feature-style-scoped/) * [Firefox bug #1291515: disable `](https://bugzilla.mozilla.org/show_bug.cgi?id=1291515) browser_support_tables Color input type Color input type ================ Form field allowing the user to select a color. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/forms.html#color-state-(type=color)> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (1) | | | | | | | | | | | | | | 16.2 (1) | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 (1) | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 (1) | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 (1) | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 (1) | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 (1) | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 (1) | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 (1) | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 (1) | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (1) | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (1) | | | | | | | | | 9.2 | | | | | 13.3 (1) | | | | | | | | | 8.2 | | | | | 13.2 (1) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (1) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (1) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Supported through WKWebView and Safari but not through UIWebView Resources --------- * [Polyfill](https://github.com/jonstipe/color-polyfill) * [WebPlatform Docs](https://webplatform.github.io/docs/html/elements/input/type/color) * [MDN web docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color)
programming_docs
browser_support_tables DOM manipulation convenience methods DOM manipulation convenience methods ==================================== jQuery-like methods on DOM nodes to insert nodes around or within a node, or to replace one node with another. These methods accept any number of DOM nodes or HTML strings as arguments. Includes: `ChildNode.before`, `ChildNode.after`, `ChildNode.replaceWith`, `ParentNode.prepend`, and `ParentNode.append`. | | | | --- | --- | | Spec | <https://dom.spec.whatwg.org/#interface-childnode> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 (1) | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 (1) | | 36 | | | | 53 | 52 (1) | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Enabled through the "Enable Experimental Web Platform Features" flag in chrome://flags Resources --------- * [WHATWG DOM Specification for ChildNode](https://dom.spec.whatwg.org/#interface-childnode) * [WHATWG DOM Specification for ParentNode](https://dom.spec.whatwg.org/#interface-parentnode) * [JS Bin testcase](https://jsbin.com/fiqacod/edit?html,js,output) * [DOM4 polyfill](https://github.com/WebReflection/dom4) browser_support_tables SVG filters SVG filters =========== Method of using Photoshop-like effects on SVG objects including blurring and color manipulation. | | | | --- | --- | | Spec | <https://www.w3.org/TR/SVG11/filters.html> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Bugs ---- * Older versions of Chrome and Safari do not support feConvolveMatrix and their lighting implementation is incomplete. * Chrome and Safari do not seem to [support kernelUnitLength](https://bugs.webkit.org/show_bug.cgi?id=84610) Resources --------- * [SVG filter demos](http://svg-wow.org/blog/category/filters/) * [WebPlatform Docs](https://webplatform.github.io/docs/svg/elements/filter) * [SVG Filter effects](https://jorgeatgu.github.io/svg-filters/) browser_support_tables Path2D Path2D ====== Allows path objects to be declared on 2D canvas surfaces | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/canvas.html#path2d-objects> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 (1) | 72 | | | 87 | 87 | 87 | 8 (1) | 71 | | | 86 | 86 | 86 | 7.1 (1) | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 (1) | 79 | 78 | 3.2 | 63 | | | 17 (1) | 78 | 77 | 3.1 | 62 | | | 16 (1) | 77 | 76 | | 60 | | | 15 (1) | 76 | 75 | | 58 | | | 14 (1) | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 (1) | | | | 71 | 70 | | 53 (1) | | | | 70 | 69 | | 52 (1) | | | | 69 | 68 | | 51 (1) | | | | 68 | 67 (1) | | 50 (1) | | | | 67 | 66 (1) | | 49 (1) | | | | 66 | 65 (1) | | 48 (1) | | | | 65 | 64 (1) | | 47 (1) | | | | 64 | 63 (1) | | 46 (1) | | | | 63 | 62 (1) | | 45 (1) | | | | 62 | 61 (1) | | 44 (1) | | | | 61 | 60 (1) | | 43 (1) | | | | 60 | 59 (1) | | 42 (1) | | | | 59 | 58 (1) | | 41 (1) | | | | 58 | 57 (1) | | 40 (1) | | | | 57 | 56 (1) | | 39 (1) | | | | 56 | 55 (1) | | 38 (1) | | | | 55 | 54 (1) | | 37 (1) | | | | 54 | 53 (1) | | 36 (1) | | | | 53 | 52 (1) | | 35 (1) | | | | 52 | 51 (1) | | 34 (1) | | | | 51 | 50 (1) | | 33 (1) | | | | 50 | 49 (1) | | 32 (1) | | | | 49 | 48 (1) | | 31 (1) | | | | 48 | 47 (1) | | 30 (1) | | | | 47 (1) | 46 (1) | | 29 (1) | | | | 46 (1) | 45 (1) | | 28 (1) | | | | 45 (1) | 44 (1) | | 27 (1) | | | | 44 (1) | 43 (1) | | 26 (1) | | | | 43 (1) | 42 (1) | | 25 (1) | | | | 42 (1) | 41 (1) | | 24 (1) | | | | 41 (1) | 40 (1) | | 23 (1) | | | | 40 (1) | 39 (1) | | 22 | | | | 39 (1) | 38 (1) | | 21 | | | | 38 (1) | 37 (1) | | 20 | | | | 37 (1) | 36 (1) | | 19 | | | | 36 (1) | 35 | | 18 | | | | 35 (1) | 34 | | 17 | | | | 34 (1) | 33 | | 16 | | | | 33 (1) | 32 | | 15 | | | | 32 (1) | 31 | | 12.1 | | | | 31 (1) | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 (1) | | | | | 13.3 | | | | | | | | | 8.2 (1) | | | | | 13.2 | | | | | | | | | 7.2-7.4 (1) | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 (1) | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 (1) | | | | | 12.0-12.1 | | | | | | | | | 4 (1) | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 (1) | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Does not support the `addPath()` method Resources --------- * [MDN article](https://developer.mozilla.org/en-US/docs/Web/API/Path2D) browser_support_tables CSS3 text-align-last CSS3 text-align-last ==================== CSS property to describe how the last line of a block or a line right before a forced line break when `text-align` is `justify`. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css3-text/#text-align-last-property> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (1) | 108 | 108 | 108 | 16.2 | 92 | | 10 (1) | 107 | 107 | 107 | 16.1 | 91 | | 9 (1) | 106 | 106 | 106 | 16.0 | 90 | | 8 (1) | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 (1) | 104 | 104 | 104 | 15.5 | 88 | | 6 (1) | 103 | 103 | 103 | 15.4 | 87 | | 5.5 (1) | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 (3) | | | | 50 | 49 | | 32 (3) | | | | 49 | 48 | | 31 (3) | | | | 48 (\*) | 47 | | 30 (3) | | | | 47 (\*) | 46 (2) | | 29 (3) | | | | 46 (\*) | 45 (2) | | 28 (3) | | | | 45 (\*) | 44 (2) | | 27 (3) | | | | 44 (\*) | 43 (2) | | 26 (3) | | | | 43 (\*) | 42 (2) | | 25 (3) | | | | 42 (\*) | 41 (2) | | 24 (3) | | | | 41 (\*) | 40 (2) | | 23 (3) | | | | 40 (\*) | 39 (2) | | 22 (3) | | | | 39 (\*) | 38 (2) | | 21 | | | | 38 (\*) | 37 (2) | | 20 | | | | 37 (\*) | 36 (2) | | 19 | | | | 36 (\*) | 35 (2) | | 18 | | | | 35 (\*) | 34 | | 17 | | | | 34 (\*) | 33 | | 16 | | | | 33 (\*) | 32 | | 15 | | | | 32 (\*) | 31 | | 12.1 | | | | 31 (\*) | 30 | | 12 | | | | 30 (\*) | 29 | | 11.6 | | | | 29 (\*) | 28 | | 11.5 | | | | 28 (\*) | 27 | | 11.1 | | | | 27 (\*) | 26 | | 11 | | | | 26 (\*) | 25 | | 10.6 | | | | 25 (\*) | 24 | | 10.5 | | | | 24 (\*) | 23 | | 10.0-10.1 | | | | 23 (\*) | 22 | | 9.5-9.6 | | | | 22 (\*) | 21 | | 9 | | | | 21 (\*) | 20 | | | | | | 20 (\*) | 19 | | | | | | 19 (\*) | 18 | | | | | | 18 (\*) | 17 | | | | | | 17 (\*) | 16 | | | | | | 16 (\*) | 15 | | | | | | 15 (\*) | 14 | | | | | | 14 (\*) | 13 | | | | | | 13 (\*) | 12 | | | | | | 12 (\*) | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 (1) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (\*) | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 (1) | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. In Internet Explorer, the start and end values are not supported. 2. Enabled through the "Enable Experimental Web Platform Features" flag in chrome://flags 3. Enabled through the "Enable Experimental Web Platform Features" flag in opera://flags \* Partial support with prefix. Resources --------- * [MDN Web Docs - CSS text-align-last](https://developer.mozilla.org/en-US/docs/Web/CSS/text-align-last) * [WebKit support bug](https://bugs.webkit.org/show_bug.cgi?id=146772)
programming_docs
browser_support_tables WebGL - 3D Canvas graphics WebGL - 3D Canvas graphics ========================== Method of generating dynamic 3D graphics using JavaScript, accelerated through hardware | | | | --- | --- | | Spec | <https://www.khronos.org/registry/webgl/specs/1.0/> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (1) | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 (1) | 70 | | | 85 | 85 | 85 | 7 (1) | 69 | | | 84 | 84 | 84 | 6.1 (1) | 68 | | | 83 | 83 | 83 | 6 (1) | 67 | | | 81 | 82 | 81 | 5.1 (1) | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 (1) | 79 | 78 | 3.2 | 63 | | | 17 (1) | 78 | 77 | 3.1 | 62 | | | 16 (1) | 77 | 76 | | 60 | | | 15 (1) | 76 | 75 | | 58 | | | 14 (1) | 75 | 74 | | 57 | | | 13 (1) | 74 | 73 | | 56 | | | 12 (1) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 (1) | | | | 35 | 34 | | 17 (1) | | | | 34 | 33 | | 16 (1) | | | | 33 | 32 (1) | | 15 (1) | | | | 32 | 31 (1) | | 12.1 (1) | | | | 31 | 30 (1) | | 12 (1) | | | | 30 | 29 (1) | | 11.6 | | | | 29 | 28 (1) | | 11.5 | | | | 28 | 27 (1) | | 11.1 | | | | 27 | 26 (1) | | 11 | | | | 26 | 25 (1) | | 10.6 | | | | 25 | 24 (1) | | 10.5 | | | | 24 | 23 (1) | | 10.0-10.1 | | | | 23 (1) | 22 (1) | | 9.5-9.6 | | | | 22 (1) | 21 (1) | | 9 | | | | 21 (1) | 20 (1) | | | | | | 20 (1) | 19 (1) | | | | | | 19 (1) | 18 (1) | | | | | | 18 (1) | 17 (1) | | | | | | 17 (1) | 16 (1) | | | | | | 16 (1) | 15 (1) | | | | | | 15 (1) | 14 (1) | | | | | | 14 (1) | 13 (1) | | | | | | 13 (1) | 12 (1) | | | | | | 12 (1) | 11 (1) | | | | | | 11 (1) | 10 (1) | | | | | | 10 (1) | 9 (1) | | | | | | 9 (1) | 8 (1) | | | | | | 8 (1) | 7 | | | | | | 7 (1) | 6 | | | | | | 6 (1) | 5 | | | | | | 5 (1) | 4 | | | | | | 4 (1) | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 (1) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (1) | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- WebGL support is dependent on GPU support and may not be available on older devices. This is due to the additional requirement for users to have [up to date video drivers](http://www.khronos.org/webgl/wiki/BlacklistsAndWhitelists). Note that WebGL is part of the [Khronos Group](http://www.khronos.org/webgl/), not the W3C. 1. WebGL context is accessed from "experimental-webgl" rather than "webgl" Bugs ---- * Older versions of IE11 have only [partial support of the spec](https://web.archive.org/web/20140624142800/http://connect.microsoft.com/IE/feedback/details/795172/ie11-fails-more-than-half-tests-in-official-webgl-conformance-test-suite), though it's much better with the latest update. Resources --------- * [Instructions on enabling WebGL](https://get.webgl.org/get-a-webgl-implementation/) * [Tutorial](https://www.khronos.org/webgl/wiki/Tutorial) * [Firefox blog post](https://hacks.mozilla.org/2009/12/webgl-draft-released-today/) * [Polyfill for IE](https://github.com/iewebgl/iewebgl) browser_support_tables WebVTT - Web Video Text Tracks WebVTT - Web Video Text Tracks ============================== Format for marking up text captions for multimedia resources. | | | | --- | --- | | Spec | <https://w3c.github.io/webvtt/> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 (2) | 110 | TP | | | | | 109 (2) | 109 | 16.3 | | | 11 | 108 | 108 (2) | 108 | 16.2 | 92 | | 10 | 107 | 107 (2) | 107 | 16.1 | 91 | | 9 | 106 | 106 (2) | 106 | 16.0 | 90 | | 8 | 105 | 105 (2) | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 (2) | 104 | 15.5 | 88 | | 6 | 103 | 103 (2) | 103 | 15.4 | 87 | | 5.5 | 102 | 102 (2) | 102 | 15.2-15.3 | 86 | | | 101 | 101 (2) | 101 | 15.1 | 85 | | | 100 | 100 (2) | 100 | 15 | 84 | | | 99 | 99 (2) | 99 | 14.1 | 83 | | | 98 | 98 (2) | 98 | 14 | 82 | | | 97 | 97 (2) | 97 | 13.1 | 81 | | | 96 | 96 (2) | 96 | 13 | 80 | | | 95 | 95 (2) | 95 | 12.1 | 79 | | | 94 | 94 (2) | 94 | 12 | 78 | | | 93 | 93 (2) | 93 | 11.1 | 77 | | | 92 | 92 (2) | 92 | 11 | 76 | | | 91 | 91 (2) | 91 | 10.1 | 75 | | | 90 | 90 (2) | 90 | 10 | 74 | | | 89 | 89 (2) | 89 | 9.1 | 73 | | | 88 | 88 (2) | 88 | 9 | 72 | | | 87 | 87 (2) | 87 | 8 | 71 | | | 86 | 86 (2) | 86 | 7.1 | 70 | | | 85 | 85 (2) | 85 | 7 | 69 | | | 84 | 84 (2) | 84 | 6.1 | 68 | | | 83 | 83 (2) | 83 | 6 | 67 | | | 81 | 82 (2) | 81 | 5.1 | 66 | | | 80 | 81 (2) | 80 | 5 | 65 | | | 79 | 80 (2) | 79 | 4 | 64 | | | 18 | 79 (2) | 78 | 3.2 | 63 | | | 17 | 78 (2) | 77 | 3.1 | 62 | | | 16 | 77 (2) | 76 | | 60 | | | 15 | 76 (2) | 75 | | 58 | | | 14 | 75 (2) | 74 | | 57 | | | 13 | 74 (2) | 73 | | 56 | | | 12 | 73 (2) | 72 | | 55 | | | | 72 (2) | 71 | | 54 | | | | 71 (2) | 70 | | 53 | | | | 70 (2) | 69 | | 52 | | | | 69 (2) | 68 | | 51 | | | | 68 (2) | 67 | | 50 | | | | 67 (2) | 66 | | 49 | | | | 66 (2) | 65 | | 48 | | | | 65 (2) | 64 | | 47 | | | | 64 (2) | 63 | | 46 | | | | 63 (2) | 62 | | 45 | | | | 62 (2) | 61 | | 44 | | | | 61 (2) | 60 | | 43 | | | | 60 (2) | 59 | | 42 | | | | 59 (2) | 58 | | 41 | | | | 58 (2) | 57 | | 40 | | | | 57 (2) | 56 | | 39 | | | | 56 (2) | 55 | | 38 | | | | 55 (2) | 54 | | 37 | | | | 54 (1) | 53 | | 36 | | | | 53 (1) | 52 | | 35 | | | | 52 (1) | 51 | | 34 | | | | 51 (1) | 50 | | 33 | | | | 50 (1) | 49 | | 32 | | | | 49 (1) | 48 | | 31 | | | | 48 (1) | 47 | | 30 | | | | 47 (1) | 46 | | 29 | | | | 46 (1) | 45 | | 28 | | | | 45 (1) | 44 | | 27 | | | | 44 (1) | 43 | | 26 | | | | 43 (1) | 42 | | 25 | | | | 42 (1) | 41 | | 24 | | | | 41 (1) | 40 | | 23 | | | | 40 (1) | 39 | | 22 | | | | 39 (1) | 38 | | 21 | | | | 38 (1) | 37 | | 20 | | | | 37 (1) | 36 | | 19 | | | | 36 (1) | 35 | | 18 | | | | 35 (1) | 34 | | 17 | | | | 34 (1) | 33 | | 16 | | | | 33 (1) | 32 | | 15 | | | | 32 (1) | 31 | | 12.1 | | | | 31 (1) | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (1) | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- WebVTT must be used with the [<track> element](/mdn-html_elements_track). 1. Firefox 31 - 54 lacks support for the `::cue` pseudo-element. [See bug #865395.](https://bugzilla.mozilla.org/show_bug.cgi?id=865395) 2. Firefox 55+ implements `::cue` but still lacks support for the `::cue(<selector>)` pseudo-element with selector. [See bug #1321489.](https://bugzilla.mozilla.org/show_bug.cgi?id=1321489) Bugs ---- * In Firefox 49 and below, captions are not visible for audio-only files in the `video` tag ([see bug](https://bugzilla.mozilla.org/show_bug.cgi?id=992664)). * Firefox 46 and below do not support the `textTrack.onCueChange()` event ([see details](https://stackoverflow.com/questions/28144668/html5-audio-texttrack-kind-subtitles-cuechange-event-not-working-in-firefox)). Resources --------- * [Getting Started With the Track Element](https://www.html5rocks.com/en/tutorials/track/basics/) * [An Introduction to WebVTT and track](https://dev.opera.com/articles/view/an-introduction-to-webvtt-and-track/) * [MDN Web Docs - WebVTT](https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API) browser_support_tables matchMedia matchMedia ========== API for finding out whether or not a media query applies to the document. | | | | --- | --- | | Spec | <https://www.w3.org/TR/cssom-view/#dom-window-matchmedia> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Bugs ---- * MediaQueryList.addEventListener [doesn't work in Safari and IE](https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList#Browser_compatibility) Resources --------- * [matchMedia.js polyfill](https://github.com/paulirish/matchMedia.js/) * [MDN Web Docs - matchMedia](https://developer.mozilla.org/en/DOM/window.matchMedia) * [MDN Web Docs - Using matchMedia](https://developer.mozilla.org/en/CSS/Using_media_queries_from_code) * [WebPlatform Docs](https://webplatform.github.io/docs/css/media_queries/apis/matchMedia)
programming_docs
browser_support_tables CSS Filter Effects CSS Filter Effects ================== Method of applying filter effects using the `filter` property to elements, matching filters available in SVG. Filter functions include blur, brightness, contrast, drop-shadow, grayscale, hue-rotate, invert, opacity, sepia and saturate. | | | | --- | --- | | Spec | <https://www.w3.org/TR/filter-effects-1/> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 (\*) | 72 | | | 87 | 87 | 87 | 8 (\*) | 71 | | | 86 | 86 | 86 | 7.1 (\*) | 70 | | | 85 | 85 | 85 | 7 (\*) | 69 | | | 84 | 84 | 84 | 6.1 (\*) | 68 | | | 83 | 83 | 83 | 6 (\*) | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 (4) | 79 | 78 | 3.2 | 63 | | | 17 (4) | 78 | 77 | 3.1 | 62 | | | 16 (4) | 77 | 76 | | 60 | | | 15 (4) | 76 | 75 | | 58 | | | 14 (4) | 75 | 74 | | 57 | | | 13 (4) | 74 | 73 | | 56 | | | 12 (2,4) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 (\*) | | | | 56 | 55 | | 38 (\*) | | | | 55 | 54 | | 37 (\*) | | | | 54 | 53 | | 36 (\*) | | | | 53 | 52 (\*) | | 35 (\*) | | | | 52 | 51 (\*) | | 34 (\*) | | | | 51 | 50 (\*) | | 33 (\*) | | | | 50 | 49 (\*) | | 32 (\*) | | | | 49 | 48 (\*) | | 31 (\*) | | | | 48 | 47 (\*) | | 30 (\*) | | | | 47 | 46 (\*) | | 29 (\*) | | | | 46 | 45 (\*) | | 28 (\*) | | | | 45 | 44 (\*) | | 27 (\*) | | | | 44 | 43 (\*) | | 26 (\*) | | | | 43 | 42 (\*) | | 25 (\*) | | | | 42 | 41 (\*) | | 24 (\*) | | | | 41 | 40 (\*) | | 23 (\*) | | | | 40 | 39 (\*) | | 22 (\*) | | | | 39 | 38 (\*) | | 21 (\*) | | | | 38 | 37 (\*) | | 20 (\*) | | | | 37 | 36 (\*) | | 19 (\*) | | | | 36 | 35 (\*) | | 18 (\*) | | | | 35 | 34 (\*) | | 17 (\*) | | | | 34 (1) | 33 (\*) | | 16 (\*) | | | | 33 (3) | 32 (\*) | | 15 (\*) | | | | 32 (3) | 31 (\*) | | 12.1 | | | | 31 (3) | 30 (\*) | | 12 | | | | 30 (3) | 29 (\*) | | 11.6 | | | | 29 (3) | 28 (\*) | | 11.5 | | | | 28 (3) | 27 (\*) | | 11.1 | | | | 27 (3) | 26 (\*) | | 11 | | | | 26 (3) | 25 (\*) | | 10.6 | | | | 25 (3) | 24 (\*) | | 10.5 | | | | 24 (3) | 23 (\*) | | 10.0-10.1 | | | | 23 (3) | 22 (\*) | | 9.5-9.6 | | | | 22 (3) | 21 (\*) | | 9 | | | | 21 (3) | 20 (\*) | | | | | | 20 (3) | 19 (\*) | | | | | | 19 (3) | 18 (\*) | | | | | | 18 (3) | 17 | | | | | | 17 (3) | 16 | | | | | | 16 (3) | 15 | | | | | | 15 (3) | 14 | | | | | | 14 (3) | 13 | | | | | | 13 (3) | 12 | | | | | | 12 (3) | 11 | | | | | | 11 (3) | 10 | | | | | | 10 (3) | 9 | | | | | | 9 (3) | 8 | | | | | | 8 (3) | 7 | | | | | | 7 (3) | 6 | | | | | | 6 (3) | 5 | | | | | | 5 (3) | 4 | | | | | | 4 (3) | | | | | | | 3.6 (3) | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 (\*) | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 (\*) | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 (\*) | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 (\*) | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 (\*) | | | | | 12.0-12.1 | | | | | | | | | 4 (\*) | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 (\*) | | | | | | | | | | | | | | 8.1-8.4 (\*) | | | | | | | | | | | | | | 8 (\*) | | | | | | | | | | | | | | 7.0-7.1 (\*) | | | | | | | | | | | | | | 6.0-6.1 (\*) | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Note that this property is significantly different from and incompatible with Microsoft's [older "filter" property](http://msdn.microsoft.com/en-us/library/ie/ms530752%28v=vs.85%29.aspx). 1. Supported in Firefox under the `layout.css.filters.enabled` flag. 2. Supported in MS Edge under the "Enable CSS filter property" flag. 3. Partial support in Firefox before version 34 [only implemented the url() function of the filter property](https://developer.mozilla.org/en-US/docs/Web/CSS/filter#Browser_compatibility) 4. Partial support refers to supporting filter functions, but not the `url` function. \* Partial support with prefix. Bugs ---- * In Edge filter won't apply if the element or it's parent has negative z-index. [See bug](https://web.archive.org/web/20180731165707/https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9318580/). * Currently there are no browsers with support for spread-radius in the drop-shadow filter. [See comment on MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/filter-function/drop-shadow#Parameters). * In Safari filter won't apply to child elements while they are animating. [WebKit Bug](https://bugs.webkit.org/show_bug.cgi?id=219729). Resources --------- * [Demo](https://fhtr.org/css-filters/) * [HTML5Rocks article](https://www.html5rocks.com/en/tutorials/filters/understanding-css/) * [Filter editor](https://web.archive.org/web/20160219005748/https://dl.dropboxusercontent.com/u/3260327/angular/CSS3ImageManipulation.html) * [Filter Playground](https://web.archive.org/web/20160310041612/http://bennettfeely.com/filters/) browser_support_tables CSS background-blend-mode CSS background-blend-mode ========================= Allows blending between CSS background images, gradients, and colors. | | | | --- | --- | | Spec | <https://www.w3.org/TR/compositing-1/#propdef-background-blend-mode> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 (1) | 74 | | | 89 | 89 | 89 | 9.1 (1) | 73 | | | 88 | 88 | 88 | 9 (1) | 72 | | | 87 | 87 | 87 | 8 (1) | 71 | | | 86 | 86 | 86 | 7.1 (1) | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 (2) | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 (2) | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 (1) | | | | | | | | | | | | | | 9.3 (1) | | | | | | | | | | | | | | 9.0-9.2 (1) | | | | | | | | | | | | | | 8.1-8.4 (1) | | | | | | | | | | | | | | 8 (1) | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Partial in Safari refers to not supporting the `hue`, `saturation`, `color`, and `luminosity` blend modes. 2. Chrome 46 has some [serious bugs](https://code.google.com/p/chromium/issues/detail?id=543583) with multiply, difference, and exclusion blend modes Bugs ---- * iOS Safari is reported to not support multiple background-blend-modes Resources --------- * [codepen example](https://codepen.io/bennettfeely/pen/rxoAc) * [Blog post](https://medium.com/web-design-technique/6b51bf53743a) * [Demo](https://bennettfeely.com/gradients/) browser_support_tables FIDO U2F API FIDO U2F API ============ JavaScript API to interact with Universal Second Factor (U2F) devices. This allows users to log into sites more securely using two-factor authentication with a USB dongle. | | | | --- | --- | | Spec | <https://fidoalliance.org/specs/fido-u2f-v1.0-nfc-bt-amendment-20150514/fido-u2f-javascript-api.html> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 (3) | | 10 | 107 | 107 | 107 | 16.1 | 91 (3) | | 9 | 106 | 106 | 106 | 16.0 | 90 (3) | | 8 | 105 (3) | 105 | 105 (3) | 15.6 | 89 (3) | | [Show all](#) | | 7 | 104 (3) | 104 | 104 (3) | 15.5 | 88 (3) | | 6 | 103 (3) | 103 | 103 (3) | 15.4 | 87 (3) | | 5.5 | 102 (3) | 102 | 102 (3) | 15.2-15.3 | 86 (3) | | | 101 (3) | 101 | 101 (3) | 15.1 | 85 (3) | | | 100 (3) | 100 | 100 (3) | 15 | 84 (3) | | | 99 (3) | 99 | 99 (3) | 14.1 | 83 (3) | | | 98 (3) | 98 | 98 (3) | 14 | 82 (3) | | | 97 (3) | 97 | 97 (3) | 13.1 | 81 (3) | | | 96 (3) | 96 | 96 (3) | 13 | 80 (3) | | | 95 (3) | 95 | 95 (3) | 12.1 | 79 (3) | | | 94 (3) | 94 | 94 (3) | 12 | 78 (3) | | | 93 (3) | 93 | 93 (3) | 11.1 | 77 (3) | | | 92 (3) | 92 | 92 (3) | 11 | 76 (3) | | | 91 (3) | 91 | 91 (3) | 10.1 | 75 (3) | | | 90 (3) | 90 | 90 (3) | 10 | 74 (3) | | | 89 (3) | 89 | 89 (3) | 9.1 | 73 (3) | | | 88 (3) | 88 | 88 (3) | 9 | 72 (3) | | | 87 (3) | 87 | 87 (3) | 8 | 71 (3) | | | 86 (3) | 86 | 86 (3) | 7.1 | 70 (3) | | | 85 (3) | 85 | 85 (3) | 7 | 69 (3) | | | 84 (3) | 84 | 84 (3) | 6.1 | 68 (3) | | | 83 (3) | 83 | 83 (3) | 6 | 67 (3) | | | 81 (3) | 82 | 81 (3) | 5.1 | 66 (3) | | | 80 (3) | 81 | 80 (3) | 5 | 65 (3) | | | 79 (3) | 80 | 79 (3) | 4 | 64 (3) | | | 18 | 79 | 78 (3) | 3.2 | 63 (3) | | | 17 | 78 | 77 (3) | 3.1 | 62 (3) | | | 16 | 77 | 76 (3) | | 60 (3) | | | 15 | 76 | 75 (3) | | 58 (3) | | | 14 | 75 | 74 (3) | | 57 (3) | | | 13 | 74 | 73 (3) | | 56 (3) | | | 12 | 73 | 72 (3) | | 55 (3) | | | | 72 | 71 (3) | | 54 (3) | | | | 71 | 70 (3) | | 53 (3) | | | | 70 | 69 (3) | | 52 (3) | | | | 69 | 68 (3) | | 51 (3) | | | | 68 | 67 (3) | | 50 (3) | | | | 67 | 66 (3) | | 49 (3) | | | | 66 (2) | 65 (3) | | 48 (3) | | | | 65 (2) | 64 (3) | | 47 (3) | | | | 64 (2) | 63 (3) | | 46 (3) | | | | 63 (2) | 62 (3) | | 45 (3) | | | | 62 (2) | 61 (3) | | 44 (3) | | | | 61 (2) | 60 (3) | | 43 (3) | | | | 60 (2) | 59 (3) | | 42 (3) | | | | 59 (2) | 58 (3) | | 41 | | | | 58 (2) | 57 (3) | | 40 (3) | | | | 57 (2) | 56 (3) | | 39 | | | | 56 (2) | 55 (3) | | 38 | | | | 55 (2) | 54 (3) | | 37 | | | | 54 (2) | 53 (3) | | 36 | | | | 53 (2) | 52 (3) | | 35 | | | | 52 (2) | 51 (3) | | 34 | | | | 51 (2) | 50 (3) | | 33 | | | | 50 (2) | 49 (3) | | 32 | | | | 49 (2) | 48 (3) | | 31 | | | | 48 (2) | 47 (3) | | 30 | | | | 47 (2) | 46 (3) | | 29 | | | | 46 | 45 (3) | | 28 | | | | 45 | 44 (3) | | 27 | | | | 44 | 43 (3) | | 26 | | | | 43 | 42 (3) | | 25 | | | | 42 | 41 (3) | | 24 | | | | 41 | 40 (1) | | 23 | | | | 40 | 39 (1) | | 22 | | | | 39 | 38 (1) | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (2) | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- The U2F API is [being decommissioned](https://www.yubico.com/blog/google-chrome-u2f-api-decommission-what-the-change-means-for-your-users-and-how-to-prepare/) (only the API, not the U2F protocol) and superseded by [WebAuthn](/webauthn). 1. Requires the "FIDO U2F (Universal 2nd Factor)" Chrome extension 2. Support can be enabled with the "security.webauth.u2f" flag 3. Supported [via the internal CryptoTokenExtension.](https://github.com/google/u2f-ref-code/blob/master/u2f-gae-demo/war/js/u2f-api.js) Resources --------- * [Mozilla bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1065729) * [Google Security article](https://security.googleblog.com/2014/10/strengthening-2-step-verification-with.html) * [Chrome platform status: U2F Security Key API removal (Cryptotoken Component Extension)](https://chromestatus.com/feature/5759004926017536) * [Yubico blog post about the decommission](https://www.yubico.com/blog/google-chrome-u2f-api-decommission-what-the-change-means-for-your-users-and-how-to-prepare/) * [Chromium Intent to Deprecate and Remove: U2F API (Cryptotoken)](https://groups.google.com/a/chromium.org/g/blink-dev/c/xHC3AtU_65A/m/yg20tsVFBAAJ) * [Mozilla Firefox bug to remove the U2F API](https://bugzilla.mozilla.org/show_bug.cgi?id=1737205)
programming_docs
browser_support_tables Pointer events Pointer events ============== This specification integrates various inputs from mice, touchscreens, and pens, making separate implementations no longer necessary and authoring for cross-device pointers easier. Not to be mistaken with the unrelated "pointer-events" CSS property. | | | | --- | --- | | Spec | <https://www.w3.org/TR/pointerevents/> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 (1,\*) | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 (4) | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 (3) | | | | 58 (2) | 57 | | 40 (3) | | | | 57 (2) | 56 | | 39 (3) | | | | 56 (2) | 55 | | 38 | | | | 55 (2) | 54 (3) | | 37 | | | | 54 (2) | 53 (3) | | 36 | | | | 53 (2) | 52 (3) | | 35 | | | | 52 (2) | 51 | | 34 | | | | 51 (2) | 50 | | 33 | | | | 50 (2) | 49 | | 32 | | | | 49 (2) | 48 | | 31 | | | | 48 (2) | 47 | | 30 | | | | 47 (2) | 46 | | 29 | | | | 46 (2) | 45 | | 28 | | | | 45 (2) | 44 | | 27 | | | | 44 (2) | 43 | | 26 | | | | 43 (2) | 42 | | 25 | | | | 42 (2) | 41 | | 24 | | | | 41 (2) | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (2) | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 (\*) | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (5,6) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Firefox, starting with version 28, provides the 'dom.w3c\_pointer\_events.enabled' flag to support this specification. 1. Partial support in IE10 refers the lack of pointerenter and pointerleave events. 2. Firefox support is disabled by default and [only supports mouse input](https://hacks.mozilla.org/2015/08/pointer-events-now-in-firefox-nightly/). On Windows only, touch can be enabled with the `layers.async-pan-zoom.enabled` and `dom.w3c_touch_events.enabled` flags 3. Can be enabled with the `#enable-pointer-events` flag. 4. Can be enabled under the `Experimental Features` menu. 5. element.releasePointerCapture(pointerID) is only partially implemented. Calling it after pointerdown does not result in boundary events (pointerover pointerleave) being dispatched during pointer movements. 6. Value of pointerevent.buttons is incorrect on pointermove events generated by touches. Is 0 but should be 1. \* Partial support with prefix. Resources --------- * [Abstraction library for pointer events](https://deeptissuejs.com/) * [PEP: Pointer Events Polyfill](https://github.com/jquery/PEP) * [Pointer Event API on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events) * [Bugzilla@Mozilla: Bug 822898 - Implement pointer events](https://bugzilla.mozilla.org/show_bug.cgi?id=822898) browser_support_tables DeviceOrientation & DeviceMotion events DeviceOrientation & DeviceMotion events ======================================= API for detecting orientation and motion events from the device running the browser. | | | | --- | --- | | Spec | <https://www.w3.org/TR/orientation-event/> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (1) | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Partial support refers to the lack of compassneedscalibration event. Partial support also refers to the lack of devicemotion event support for Chrome 30- and Opera. Opera Mobile 14 lost the ondevicemotion event support. Firefox 3.6, 4 and 5 support the non-standard [MozOrientation](https://developer.mozilla.org/en/DOM/MozOrientation) event. 1. `compassneedscalibration` supported in IE11 only for compatible devices with Windows 8.1+. Bugs ---- * `DeviceOrientationEvent.beta` has values between -90 and 90 on mobile Safari and between 180 and -180 on Firefox. `DeviceOrientationEvent.gamma` has values between -180 and 180 on mobile Safari and between 90 and -90 on Firefox. See [Firefox reference](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent) and [Safari reference](https://developer.apple.com/library/safari/documentation/SafariDOMAdditions/Reference/DeviceOrientationEventClassRef/DeviceOrientationEvent/DeviceOrientationEvent.html#//apple_ref/javascript/instp/DeviceOrientationEvent/beta) * Safari on iOS doesn't implement the spec correctly, because alpha is arbitrary instead of relative to true north. Safari instead offers webkitCompassHeading`, which has the opposite sign to alpha and is also relative to magnetic north instead of true north. (see [details](https://github.com/w3c/deviceorientation/issues/6)) Resources --------- * [HTML5 Rocks tutorial](https://www.html5rocks.com/en/tutorials/device/orientation/) * [has.js test](https://raw.github.com/phiggins42/has.js/master/detect/features.js#native-orientation) * [DeviceOrientation implementation prototype for IE10](http://html5labs.interoperabilitybridges.com/prototypes/device-orientation-events/device-orientation-events/info) * [Demo](https://audero.it/demo/device-orientation-api-demo.html) browser_support_tables Cookie Store API Cookie Store API ================ An API for reading and modifying cookies. Compared to the existing `document.cookie` method, the API provides a much more modern interface, which can also be used in service workers. | | | | --- | --- | | Spec | <https://wicg.github.io/cookie-store/> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 (1) | | | 88 | 88 | 88 | 9 | 72 (1) | | | 87 | 87 | 87 | 8 | 71 (1) | | | 86 (1) | 86 | 86 (1) | 7.1 | 70 (1) | | | 85 (1) | 85 | 85 (1) | 7 | 69 (1) | | | 84 (1) | 84 | 84 (1) | 6.1 | 68 (1) | | | 83 (1) | 83 | 83 (1) | 6 | 67 (1) | | | 81 (1) | 82 | 81 (1) | 5.1 | 66 (1) | | | 80 (1) | 81 | 80 (1) | 5 | 65 (1) | | | 79 (1) | 80 | 79 (1) | 4 | 64 (1) | | | 18 | 79 | 78 (1) | 3.2 | 63 (1) | | | 17 | 78 | 77 (1) | 3.1 | 62 (1) | | | 16 | 77 | 76 (1) | | 60 (1) | | | 15 | 76 | 75 (1) | | 58 (1) | | | 14 | 75 | 74 (1) | | 57 (1) | | | 13 | 74 | 73 (1) | | 56 (1) | | | 12 | 73 | 72 (1) | | 55 (1) | | | | 72 | 71 (1) | | 54 (1) | | | | 71 | 70 (1) | | 53 (1) | | | | 70 | 69 (1) | | 52 (1) | | | | 69 | 68 (1) | | 51 (1) | | | | 68 | 67 (1) | | 50 | | | | 67 | 66 (1) | | 49 | | | | 66 | 65 (1) | | 48 | | | | 65 | 64 (1) | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled with the `#enable-experimental-web-platform-features` flag. Resources --------- * [Article on using the Cookie Store API](https://developers.google.com/web/updates/2018/09/asynchronous-access-to-http-cookies) * [Specification explainer](https://wicg.github.io/cookie-store/explainer.html) * [Firefox position: defer](https://mozilla.github.io/standards-positions/#cookie-store) * [Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1475599)
programming_docs
browser_support_tables File API File API ======== Method of manipulating file objects in web applications client-side, as well as programmatically selecting them and accessing their data. | | | | --- | --- | | Spec | <https://www.w3.org/TR/FileAPI/> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (2) | 108 | 108 | 108 | 16.2 | 92 | | 10 (2) | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 (2) | 73 | | | 88 | 88 | 88 | 9 (2) | 72 | | | 87 | 87 | 87 | 8 (2) | 71 | | | 86 | 86 | 86 | 7.1 (2) | 70 | | | 85 | 85 | 85 | 7 (2) | 69 | | | 84 | 84 | 84 | 6.1 (2) | 68 | | | 83 | 83 | 83 | 6 (2) | 67 | | | 81 | 82 | 81 | 5.1 (1,2) | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 (2) | 79 | 78 | 3.2 | 63 | | | 17 (2) | 78 | 77 | 3.1 | 62 | | | 16 (2) | 77 | 76 | | 60 | | | 15 (2) | 76 | 75 | | 58 | | | 14 (2) | 75 | 74 | | 57 | | | 13 (2) | 74 | 73 | | 56 | | | 12 (2) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 (2) | | | | 41 | 40 | | 23 (2) | | | | 40 | 39 | | 22 (2) | | | | 39 | 38 | | 21 (2) | | | | 38 | 37 (2) | | 20 (2) | | | | 37 | 36 (2) | | 19 (2) | | | | 36 | 35 (2) | | 18 (2) | | | | 35 | 34 (2) | | 17 (2) | | | | 34 | 33 (2) | | 16 (2) | | | | 33 | 32 (2) | | 15 (2) | | | | 32 | 31 (2) | | 12.1 (2) | | | | 31 | 30 (2) | | 12 (2) | | | | 30 | 29 (2) | | 11.6 (2) | | | | 29 | 28 (2) | | 11.5 (2) | | | | 28 | 27 (2) | | 11.1 (2) | | | | 27 (2) | 26 (2) | | 11 | | | | 26 (2) | 25 (2) | | 10.6 | | | | 25 (2) | 24 (2) | | 10.5 | | | | 24 (2) | 23 (2) | | 10.0-10.1 | | | | 23 (2) | 22 (2) | | 9.5-9.6 | | | | 22 (2) | 21 (2) | | 9 | | | | 21 (2) | 20 (2) | | | | | | 20 (2) | 19 (2) | | | | | | 19 (2) | 18 (2) | | | | | | 18 (2) | 17 (2) | | | | | | 17 (2) | 16 (2) | | | | | | 16 (2) | 15 (2) | | | | | | 15 (2) | 14 (2) | | | | | | 14 (2) | 13 (2) | | | | | | 13 (2) | 12 (1,2) | | | | | | 12 (2) | 11 (1,2) | | | | | | 11 (2) | 10 (1,2) | | | | | | 10 (2) | 9 (1,2) | | | | | | 9 (2) | 8 (1,2) | | | | | | 8 (2) | 7 (1,2) | | | | | | 7 (2) | 6 (1,2) | | | | | | 6 (2) | 5 | | | | | | 5 (2) | 4 | | | | | | 4 (2) | | | | | | | 3.6 (2) | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 (2) | 72 | 108 | 107 | 11 (2) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 (1,2) | 12.1 (2) | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 (2) | | 12 (2) | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 (1,2) | | 11.5 (2) | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 (1,2) | | 11.1 (2) | | | | | 15.0 | | | | | 15.4 | | 4 (1,2) | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 (1,2) | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 (2) | | | | | | | | | | | | | | 9.0-9.2 (2) | | | | | | | | | | | | | | 8.1-8.4 (2) | | | | | | | | | | | | | | 8 (2) | | | | | | | | | | | | | | 7.0-7.1 (2) | | | | | | | | | | | | | | 6.0-6.1 (2) | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Does not have `FileReader` support. 2. Does not support the `File` constructor Resources --------- * [MDN Web Docs - Using Files](https://developer.mozilla.org/en/Using_files_from_web_applications) * [WebPlatform Docs](https://webplatform.github.io/docs/apis/file) * [Polyfill](https://github.com/moxiecode/moxie) browser_support_tables Array.prototype.findIndex Array.prototype.findIndex ========================= The `findIndex()` method returns the index of the first element in the array that satisfies the provided testing function. | | | | --- | --- | | Spec | <https://tc39.es/ecma262/#sec-array.prototype.findindex> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [MDN article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex) * [Polyfill for this feature is available in the core-js library](https://github.com/zloirock/core-js#ecmascript-array) browser_support_tables CSS page-break properties CSS page-break properties ========================= Properties to control the way elements are broken across (printed) pages. | | | | --- | --- | | Spec | <https://www.w3.org/TR/CSS2/page.html#page-breaks> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (1,2,3) | | | | | | 110 (2,3) | 110 (1,2,3) | TP (1,2,3) | | | | | 109 (2,3) | 109 (1,2,3) | 16.3 (1,2,3) | | | 11 (1,2) | 108 (1,2,3) | 108 (2,3) | 108 (1,2,3) | 16.2 (1,2,3) | 92 (1,2,3) | | 10 (1,2) | 107 (1,2,3) | 107 (2,3) | 107 (1,2,3) | 16.1 (1,2,3) | 91 (1,2,3) | | 9 (1,2,3) | 106 (1,2,3) | 106 (2,3) | 106 (1,2,3) | 16.0 (1,2,3) | 90 (1,2,3) | | 8 (1,2,3) | 105 (1,2,3) | 105 (2,3) | 105 (1,2,3) | 15.6 (1,2,3) | 89 (1,2,3) | | [Show all](#) | | 7 (1,2,3) | 104 (1,2,3) | 104 (2,3) | 104 (1,2,3) | 15.5 (1,2,3) | 88 (1,2,3) | | 6 (1,2,3) | 103 (1,2,3) | 103 (2,3) | 103 (1,2,3) | 15.4 (1,2,3) | 87 (1,2,3) | | 5.5 (1,2,3) | 102 (1,2,3) | 102 (2,3) | 102 (1,2,3) | 15.2-15.3 (1,2,3) | 86 (1,2,3) | | | 101 (1,2,3) | 101 (2,3) | 101 (1,2,3) | 15.1 (1,2,3) | 85 (1,2,3) | | | 100 (1,2,3) | 100 (2,3) | 100 (1,2,3) | 15 (1,2,3) | 84 (1,2,3) | | | 99 (1,2,3) | 99 (2,3) | 99 (1,2,3) | 14.1 (1,2,3) | 83 (1,2,3) | | | 98 (1,2,3) | 98 (2,3) | 98 (1,2,3) | 14 (1,2,3) | 82 (1,2,3) | | | 97 (1,2,3) | 97 (2,3) | 97 (1,2,3) | 13.1 (1,2,3) | 81 (1,2,3) | | | 96 (1,2,3) | 96 (2,3) | 96 (1,2,3) | 13 (1,2,3) | 80 (1,2,3) | | | 95 (1,2,3) | 95 (2,3) | 95 (1,2,3) | 12.1 (1,2,3) | 79 (1,2,3) | | | 94 (1,2,3) | 94 (2,3) | 94 (1,2,3) | 12 (1,2,3) | 78 (1,2,3) | | | 93 (1,2,3) | 93 (2,3) | 93 (1,2,3) | 11.1 (1,2,3) | 77 (1,2,3) | | | 92 (1,2,3) | 92 (2,3) | 92 (1,2,3) | 11 (1,2,3) | 76 (1,2,3) | | | 91 (1,2,3) | 91 (2,3) | 91 (1,2,3) | 10.1 (1,2,3) | 75 (1,2,3) | | | 90 (1,2,3) | 90 (2,3) | 90 (1,2,3) | 10 (2,3) | 74 (1,2,3) | | | 89 (1,2,3) | 89 (2,3) | 89 (1,2,3) | 9.1 (1,2,3) | 73 (1,2,3) | | | 88 (1,2,3) | 88 (2,3) | 88 (1,2,3) | 9 (1,2,3) | 72 (1,2,3) | | | 87 (1,2,3) | 87 (2,3) | 87 (1,2,3) | 8 (1,2,3) | 71 (1,2,3) | | | 86 (1,2,3) | 86 (2,3) | 86 (1,2,3) | 7.1 (1,2,3) | 70 (1,2,3) | | | 85 (1,2,3) | 85 (2,3) | 85 (1,2,3) | 7 (1,2,3) | 69 (1,2,3) | | | 84 (1,2,3) | 84 (2,3) | 84 (1,2,3) | 6.1 (1,2,3) | 68 (1,2,3) | | | 83 (1,2,3) | 83 (2,3) | 83 (1,2,3) | 6 (1,2,3) | 67 (1,2,3) | | | 81 (1,2,3) | 82 (2,3) | 81 (1,2,3) | 5.1 (1,2,3) | 66 (1,2,3) | | | 80 (1,2,3) | 81 (2,3) | 80 (1,2,3) | 5 (1,2,3) | 65 (1,2,3) | | | 79 (1,2,3) | 80 (2,3) | 79 (1,2,3) | 4 (1,2,3) | 64 (1,2,3) | | | 18 (1,2) | 79 (2,3) | 78 (1,2,3) | 3.2 (1,2,3) | 63 (1,2,3) | | | 17 (1,2) | 78 (2,3) | 77 (1,2,3) | 3.1 (1,2,3) | 62 (1,2,3) | | | 16 (1,2) | 77 (2,3) | 76 (1,2,3) | | 60 (1,2,3) | | | 15 (1,2) | 76 (2,3) | 75 (1,2,3) | | 58 (1,2,3) | | | 14 (1,2) | 75 (2,3) | 74 (1,2,3) | | 57 (1,2,3) | | | 13 (1,2) | 74 (2,3) | 73 (1,2,3) | | 56 (1,2,3) | | | 12 (1,2) | 73 (2,3) | 72 (1,2,3) | | 55 (1,2,3) | | | | 72 (2,3) | 71 (1,2,3) | | 54 (1,2,3) | | | | 71 (2,3) | 70 (1,2,3) | | 53 (1,2,3) | | | | 70 (2,3) | 69 (1,2,3) | | 52 (1,2,3) | | | | 69 (2,3) | 68 (1,2,3) | | 51 (1,2,3) | | | | 68 (2,3) | 67 (1,2,3) | | 50 (1,2,3) | | | | 67 (2,3) | 66 (1,2,3) | | 49 (1,2,3) | | | | 66 (2,3) | 65 (1,2,3) | | 48 (1,2,3) | | | | 65 (2,3) | 64 (1,2,3) | | 47 (1,2,3) | | | | 64 (1,2,3) | 63 (1,2,3) | | 46 (1,2,3) | | | | 63 (1,2,3) | 62 (1,2,3) | | 45 (1,2,3) | | | | 62 (1,2,3) | 61 (1,2,3) | | 44 (1,2,3) | | | | 61 (1,2,3) | 60 (1,2,3) | | 43 (1,2,3) | | | | 60 (1,2,3) | 59 (1,2,3) | | 42 (1,2,3) | | | | 59 (1,2,3) | 58 (1,2,3) | | 41 (1,2,3) | | | | 58 (1,2,3) | 57 (1,2,3) | | 40 (1,2,3) | | | | 57 (1,2,3) | 56 (1,2,3) | | 39 (1,2,3) | | | | 56 (1,2,3) | 55 (1,2,3) | | 38 (1,2,3) | | | | 55 (1,2,3) | 54 (1,2,3) | | 37 (1,2,3) | | | | 54 (1,2,3) | 53 (1,2,3) | | 36 (1,2,3) | | | | 53 (1,2,3) | 52 (1,2,3) | | 35 (1,2,3) | | | | 52 (1,2,3) | 51 (1,2,3) | | 34 (1,2,3) | | | | 51 (1,2,3) | 50 (1,2,3) | | 33 (1,2,3) | | | | 50 (1,2,3) | 49 (1,2,3) | | 32 (1,2,3) | | | | 49 (1,2,3) | 48 (1,2,3) | | 31 (1,2,3) | | | | 48 (1,2,3) | 47 (1,2,3) | | 30 (1,2,3) | | | | 47 (1,2,3) | 46 (1,2,3) | | 29 (1,2,3) | | | | 46 (1,2,3) | 45 (1,2,3) | | 28 (1,2,3) | | | | 45 (1,2,3) | 44 (1,2,3) | | 27 (1,2,3) | | | | 44 (1,2,3) | 43 (1,2,3) | | 26 (1,2,3) | | | | 43 (1,2,3) | 42 (1,2,3) | | 25 (1,2,3) | | | | 42 (1,2,3) | 41 (1,2,3) | | 24 (1,2,3) | | | | 41 (1,2,3) | 40 (1,2,3) | | 23 (1,2,3) | | | | 40 (1,2,3) | 39 (1,2,3) | | 22 (1,2,3) | | | | 39 (1,2,3) | 38 (1,2,3) | | 21 (1,2,3) | | | | 38 (1,2,3) | 37 (1,2,3) | | 20 (1,2,3) | | | | 37 (1,2,3) | 36 (1,2,3) | | 19 (1,2,3) | | | | 36 (1,2,3) | 35 (1,2,3) | | 18 (1,2,3) | | | | 35 (1,2,3) | 34 (1,2,3) | | 17 (1,2,3) | | | | 34 (1,2,3) | 33 (1,2,3) | | 16 (1,2,3) | | | | 33 (1,2,3) | 32 (1,2,3) | | 15 (1,2,3) | | | | 32 (1,2,3) | 31 (1,2,3) | | 12.1 (1) | | | | 31 (1,2,3) | 30 (1,2,3) | | 12 (1) | | | | 30 (1,2,3) | 29 (1,2,3) | | 11.6 (1) | | | | 29 (1,2,3) | 28 (1,2,3) | | 11.5 (1) | | | | 28 (1,2,3) | 27 (1,2,3) | | 11.1 (1) | | | | 27 (1,2,3) | 26 (1,2,3) | | 11 (1) | | | | 26 (1,2,3) | 25 (1,2,3) | | 10.6 (1) | | | | 25 (1,2,3) | 24 (1,2,3) | | 10.5 (1) | | | | 24 (1,2,3) | 23 (1,2,3) | | 10.0-10.1 (1) | | | | 23 (1,2,3) | 22 (1,2,3) | | 9.5-9.6 | | | | 22 (1,2,3) | 21 (1,2,3) | | 9 | | | | 21 (1,2,3) | 20 (1,2,3) | | | | | | 20 (1,2,3) | 19 (1,2,3) | | | | | | 19 (1,2,3) | 18 (1,2,3) | | | | | | 18 (1,2,3) | 17 (1,2,3) | | | | | | 17 (1,2,3) | 16 (1,2,3) | | | | | | 16 (1,2,3) | 15 (1,2,3) | | | | | | 15 (1,2,3) | 14 (1,2,3) | | | | | | 14 (1,2,3) | 13 (1,2,3) | | | | | | 13 (1,2,3) | 12 (1,2,3) | | | | | | 12 (1,2,3) | 11 (1,2,3) | | | | | | 11 (1,2,3) | 10 (1,2,3) | | | | | | 10 (1,2,3) | 9 (1,2,3) | | | | | | 9 (1,2,3) | 8 (1,2,3) | | | | | | 8 (1,2,3) | 7 (1,2,3) | | | | | | 7 (1,2,3) | 6 (1,2,3) | | | | | | 6 (1,2,3) | 5 (1,2,3) | | | | | | 5 (1,2,3) | 4 (1,2,3) | | | | | | 4 (1,2,3) | | | | | | | 3.6 (1,2,3) | | | | | | | 3.5 (1,2,3) | | | | | | | 3 (1,2,3) | | | | | | | 2 (1,2,3) | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (1,2,3) | | | | | | | | | | | | | | 16.2 (1,2,3) | all (1) | 108 (1,2,3) | 10 (1,2,3) | 72 (1,2,3) | 108 (1,2,3) | 107 (2,3) | 11 (1,2) | 13.4 (1,2,3) | 19.0 (1,2,3) | 13.1 (1,2,3) | 13.18 (1,2,3) | 2.5 (1,2,3) | | 16.1 (1,2,3) | | 4.4.3-4.4.4 (1,2,3) | 7 (1,2,3) | 12.1 (1) | | | 10 (1,2) | | 18.0 (1,2,3) | | | | | 16.0 (1,2,3) | | 4.4 (1,2,3) | | 12 (1) | | | | | 17.0 (1,2,3) | | | | | 15.6 (1,2,3) | | 4.2-4.3 (1,2,3) | | 11.5 (1) | | | | | 16.0 (1,2,3) | | | | | [Show all](#) | | 15.5 (1,2,3) | | 4.1 (1,2,3) | | 11.1 (1) | | | | | 15.0 (1,2,3) | | | | | 15.4 (1,2,3) | | 4 (1,2,3) | | 11 (1) | | | | | 14.0 (1,2,3) | | | | | 15.2-15.3 (1,2,3) | | 3 (1,2,3) | | 10 (1) | | | | | 13.0 (1,2,3) | | | | | 15.0-15.1 (1,2,3) | | 2.3 (1,2,3) | | | | | | | 12.0 (1,2,3) | | | | | 14.5-14.8 (1,2,3) | | 2.2 (1,2,3) | | | | | | | 11.1-11.2 (1,2,3) | | | | | 14.0-14.4 (1,2,3) | | 2.1 (1,2,3) | | | | | | | 10.1 (1,2,3) | | | | | 13.4-13.7 (1,2,3) | | | | | | | | | 9.2 (1,2,3) | | | | | 13.3 (1,2,3) | | | | | | | | | 8.2 (1,2,3) | | | | | 13.2 (1,2,3) | | | | | | | | | 7.2-7.4 (1,2,3) | | | | | 13.0-13.1 (1,2,3) | | | | | | | | | 6.2-6.4 (1,2,3) | | | | | 12.2-12.5 (1,2,3) | | | | | | | | | 5.0-5.4 (1,2,3) | | | | | 12.0-12.1 (1,2,3) | | | | | | | | | 4 (1,2,3) | | | | | 11.3-11.4 (1,2,3) | | | | | | | | | | | | | | 11.0-11.2 (1,2,3) | | | | | | | | | | | | | | 10.3 (1,2,3) | | | | | | | | | | | | | | 10.0-10.2 (1,2,3) | | | | | | | | | | | | | | 9.3 (1,2,3) | | | | | | | | | | | | | | 9.0-9.2 (1,2,3) | | | | | | | | | | | | | | 8.1-8.4 (1,2,3) | | | | | | | | | | | | | | 8 (1,2,3) | | | | | | | | | | | | | | 7.0-7.1 (1,2,3) | | | | | | | | | | | | | | 6.0-6.1 (1,2,3) | | | | | | | | | | | | | | 5.0-5.1 (1,2,3) | | | | | | | | | | | | | | 4.2-4.3 (1,2,3) | | | | | | | | | | | | | | 4.0-4.1 (1,2,3) | | | | | | | | | | | | | | 3.2 (1,2,3) | | | | | | | | | | | | | Notes ----- Not all mobile browsers offer print support; support listed for these is based on browser engine capability. 1. Supports the `page-break-*` alias from the CSS 2.1 specification, but not the `break-*` properties from the latest spec. 2. Does not support `avoid` for `page-break-before` & `page-break-after` (only `page-break-inside`). 3. Treats the `left` and `right` values like `always`. Bugs ---- * Firefox issue [#775617](https://bugzilla.mozilla.org/show_bug.cgi?id=775617) for page-break-before/page-break-after: avoid * Chromium issue [#223068](https://bugs.chromium.org/p/chromium/issues/detail?id=223068) for break-before, break-after, break-inside Resources --------- * [CSS Tricks article](https://css-tricks.com/almanac/properties/p/page-break/) * [Latest fragmentation specification (includes column & region breaks)](https://drafts.csswg.org/css-break-3/#break-between)
programming_docs
browser_support_tables Ambient Light Sensor Ambient Light Sensor ==================== Defines a concrete sensor interface to monitor the ambient light level or illuminance of the device’s environment. | | | | --- | --- | | Spec | <https://www.w3.org/TR/ambient-light/> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (2) | | | | | | 110 (1) | 110 (2) | TP | | | | | 109 (1) | 109 (2) | 16.3 | | | 11 | 108 (2) | 108 (1) | 108 (2) | 16.2 | 92 (2) | | 10 | 107 (2) | 107 (1) | 107 (2) | 16.1 | 91 (2) | | 9 | 106 (2) | 106 (1) | 106 (2) | 16.0 | 90 (2) | | 8 | 105 (2) | 105 (1) | 105 (2) | 15.6 | 89 (2) | | [Show all](#) | | 7 | 104 (2) | 104 (1) | 104 (2) | 15.5 | 88 (2) | | 6 | 103 (2) | 103 (1) | 103 (2) | 15.4 | 87 (2) | | 5.5 | 102 (2) | 102 (1) | 102 (2) | 15.2-15.3 | 86 (2) | | | 101 (2) | 101 (1) | 101 (2) | 15.1 | 85 (2) | | | 100 (2) | 100 (1) | 100 (2) | 15 | 84 (2) | | | 99 (2) | 99 (1) | 99 (2) | 14.1 | 83 (2) | | | 98 (2) | 98 (1) | 98 (2) | 14 | 82 (2) | | | 97 (2) | 97 (1) | 97 (2) | 13.1 | 81 (2) | | | 96 (2) | 96 (1) | 96 (2) | 13 | 80 (2) | | | 95 (2) | 95 (1) | 95 (2) | 12.1 | 79 (2) | | | 94 (2) | 94 (1) | 94 (2) | 12 | 78 (2) | | | 93 (2) | 93 (1) | 93 (2) | 11.1 | 77 (2) | | | 92 (2) | 92 (1) | 92 (2) | 11 | 76 (2) | | | 91 (2) | 91 (1) | 91 (2) | 10.1 | 75 (2) | | | 90 (2) | 90 (1) | 90 (2) | 10 | 74 (2) | | | 89 (2) | 89 (1) | 89 (2) | 9.1 | 73 (2) | | | 88 (2) | 88 (1) | 88 (2) | 9 | 72 | | | 87 (2) | 87 (1) | 87 (2) | 8 | 71 | | | 86 (2) | 86 (1) | 86 (2) | 7.1 | 70 | | | 85 (2) | 85 (1) | 85 (2) | 7 | 69 | | | 84 (2) | 84 (1) | 84 (2) | 6.1 | 68 | | | 83 (2) | 83 (1) | 83 (2) | 6 | 67 | | | 81 (2) | 82 (1) | 81 (2) | 5.1 | 66 | | | 80 (2) | 81 (1) | 80 (2) | 5 | 65 | | | 79 (2) | 80 (1) | 79 (2) | 4 | 64 | | | 18 (1) | 79 (1) | 78 (2) | 3.2 | 63 | | | 17 (1) | 78 (1) | 77 (2) | 3.1 | 62 | | | 16 (1) | 77 (1) | 76 (2) | | 60 | | | 15 (1) | 76 (1) | 75 (2) | | 58 | | | 14 (1) | 75 (1) | 74 (2) | | 57 | | | 13 | 74 (1) | 73 (2) | | 56 | | | 12 | 73 (1) | 72 (2) | | 55 | | | | 72 (1) | 71 (2) | | 54 | | | | 71 (1) | 70 (2) | | 53 | | | | 70 (1) | 69 (2) | | 52 | | | | 69 (1) | 68 (2) | | 51 | | | | 68 (1) | 67 (2) | | 50 | | | | 67 (1) | 66 (2) | | 49 | | | | 66 (1) | 65 (2) | | 48 | | | | 65 (1) | 64 (2) | | 47 | | | | 64 (1) | 63 (2) | | 46 | | | | 63 (1) | 62 (2) | | 45 | | | | 62 (1) | 61 (2) | | 44 | | | | 61 (1) | 60 (2) | | 43 | | | | 60 (1) | 59 (2) | | 42 | | | | 59 (1) | 58 (2) | | 41 | | | | 58 (1) | 57 | | 40 | | | | 57 (1) | 56 | | 39 | | | | 56 (1) | 55 | | 38 | | | | 55 (1) | 54 | | 37 | | | | 54 (1) | 53 | | 36 | | | | 53 (1) | 52 | | 35 | | | | 52 (1) | 51 | | 34 | | | | 51 (1) | 50 | | 33 | | | | 50 (1) | 49 | | 32 | | | | 49 (1) | 48 | | 31 | | | | 48 (1) | 47 | | 30 | | | | 47 (1) | 46 | | 29 | | | | 46 (1) | 45 | | 28 | | | | 45 (1) | 44 | | 27 | | | | 44 (1) | 43 | | 26 | | | | 43 (1) | 42 | | 25 | | | | 42 (1) | 41 | | 24 | | | | 41 (1) | 40 | | 23 | | | | 40 (1) | 39 | | 22 | | | | 39 (1) | 38 | | 21 | | | | 38 (1) | 37 | | 20 | | | | 37 (1) | 36 | | 19 | | | | 36 (1) | 35 | | 18 | | | | 35 (1) | 34 | | 17 | | | | 34 (1) | 33 | | 16 | | | | 33 (1) | 32 | | 15 | | | | 32 (1) | 31 | | 12.1 | | | | 31 (1) | 30 | | 12 | | | | 30 (1) | 29 | | 11.6 | | | | 29 (1) | 28 | | 11.5 | | | | 28 (1) | 27 | | 11.1 | | | | 27 (1) | 26 | | 11 | | | | 26 (1) | 25 | | 10.6 | | | | 25 (1) | 24 | | 10.5 | | | | 24 (1) | 23 | | 10.0-10.1 | | | | 23 (1) | 22 | | 9.5-9.6 | | | | 22 (1) | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (1) | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Implements an [outdated version of the spec](https://www.w3.org/TR/2015/WD-ambient-light-20150903/). 2. Available by enabling the "Generic Sensor Extra Classes" experimental flag in `about:flags` Resources --------- * [Demo](https://intel.github.io/generic-sensor-demos/ambient-map/build/bundled/) * [Article](https://developers.google.com/web/updates/2017/09/sensors-for-the-web) * [MDN Web Docs - Ambient Light Sensor](https://developer.mozilla.org/en-US/docs/Web/API/Ambient_Light_Sensor_API) browser_support_tables WOFF - Web Open Font Format WOFF - Web Open Font Format =========================== Compressed TrueType/OpenType font that contains information about the font's source. | | | | --- | --- | | Spec | <https://www.w3.org/TR/WOFF/> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 (1) | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Reported to be supported in some modified versions of the Android 4.0 browser. Resources --------- * [Mozilla hacks blog post](https://hacks.mozilla.org/2009/10/woff/) browser_support_tables CSS font-smooth CSS font-smooth =============== Controls the application of anti-aliasing when fonts are rendered. | | | | --- | --- | | Spec | <https://www.w3.org/TR/WD-font/#font-smooth> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (1,3,\*) | | | | | | 110 (2,3,\*) | 110 (1,3,\*) | TP (1,3,\*) | | | | | 109 (2,3,\*) | 109 (1,3,\*) | 16.3 (1,3,\*) | | | 11 | 108 (1,3,\*) | 108 (2,3,\*) | 108 (1,3,\*) | 16.2 (1,3,\*) | 92 (1,3,\*) | | 10 | 107 (1,3,\*) | 107 (2,3,\*) | 107 (1,3,\*) | 16.1 (1,3,\*) | 91 (1,3,\*) | | 9 | 106 (1,3,\*) | 106 (2,3,\*) | 106 (1,3,\*) | 16.0 (1,3,\*) | 90 (1,3,\*) | | 8 | 105 (1,3,\*) | 105 (2,3,\*) | 105 (1,3,\*) | 15.6 (1,3,\*) | 89 (1,3,\*) | | [Show all](#) | | 7 | 104 (1,3,\*) | 104 (2,3,\*) | 104 (1,3,\*) | 15.5 (1,3,\*) | 88 (1,3,\*) | | 6 | 103 (1,3,\*) | 103 (2,3,\*) | 103 (1,3,\*) | 15.4 (1,3,\*) | 87 (1,3,\*) | | 5.5 | 102 (1,3,\*) | 102 (2,3,\*) | 102 (1,3,\*) | 15.2-15.3 (1,3,\*) | 86 (1,3,\*) | | | 101 (1,3,\*) | 101 (2,3,\*) | 101 (1,3,\*) | 15.1 (1,3,\*) | 85 (1,3,\*) | | | 100 (1,3,\*) | 100 (2,3,\*) | 100 (1,3,\*) | 15 (1,3,\*) | 84 (1,3,\*) | | | 99 (1,3,\*) | 99 (2,3,\*) | 99 (1,3,\*) | 14.1 (1,3,\*) | 83 (1,3,\*) | | | 98 (1,3,\*) | 98 (2,3,\*) | 98 (1,3,\*) | 14 (1,3,\*) | 82 (1,3,\*) | | | 97 (1,3,\*) | 97 (2,3,\*) | 97 (1,3,\*) | 13.1 (1,3,\*) | 81 (1,3,\*) | | | 96 (1,3,\*) | 96 (2,3,\*) | 96 (1,3,\*) | 13 (1,3,\*) | 80 (1,3,\*) | | | 95 (1,3,\*) | 95 (2,3,\*) | 95 (1,3,\*) | 12.1 (1,3,\*) | 79 (1,3,\*) | | | 94 (1,3,\*) | 94 (2,3,\*) | 94 (1,3,\*) | 12 (1,3,\*) | 78 (1,3,\*) | | | 93 (1,3,\*) | 93 (2,3,\*) | 93 (1,3,\*) | 11.1 (1,3,\*) | 77 (1,3,\*) | | | 92 (1,3,\*) | 92 (2,3,\*) | 92 (1,3,\*) | 11 (1,3,\*) | 76 (1,3,\*) | | | 91 (1,3,\*) | 91 (2,3,\*) | 91 (1,3,\*) | 10.1 (1,3,\*) | 75 (1,3,\*) | | | 90 (1,3,\*) | 90 (2,3,\*) | 90 (1,3,\*) | 10 (1,3,\*) | 74 (1,3,\*) | | | 89 (1,3,\*) | 89 (2,3,\*) | 89 (1,3,\*) | 9.1 (1,3,\*) | 73 (1,3,\*) | | | 88 (1,3,\*) | 88 (2,3,\*) | 88 (1,3,\*) | 9 (1,3,\*) | 72 (1,3,\*) | | | 87 (1,3,\*) | 87 (2,3,\*) | 87 (1,3,\*) | 8 (1,3,\*) | 71 (1,3,\*) | | | 86 (1,3,\*) | 86 (2,3,\*) | 86 (1,3,\*) | 7.1 (1,3,\*) | 70 (1,3,\*) | | | 85 (1,3,\*) | 85 (2,3,\*) | 85 (1,3,\*) | 7 (1,3,\*) | 69 (1,3,\*) | | | 84 (1,3,\*) | 84 (2,3,\*) | 84 (1,3,\*) | 6.1 (1,3,\*) | 68 (1,3,\*) | | | 83 (1,3,\*) | 83 (2,3,\*) | 83 (1,3,\*) | 6 (1,3,\*) | 67 (1,3,\*) | | | 81 (1,3,\*) | 82 (2,3,\*) | 81 (1,3,\*) | 5.1 (1,3,\*) | 66 (1,3,\*) | | | 80 (1,3,\*) | 81 (2,3,\*) | 80 (1,3,\*) | 5 (1,3,\*) | 65 (1,3,\*) | | | 79 (1,3,\*) | 80 (2,3,\*) | 79 (1,3,\*) | 4 (1,3,\*) | 64 (1,3,\*) | | | 18 | 79 (2,3,\*) | 78 (1,3,\*) | 3.2 | 63 (1,3,\*) | | | 17 | 78 (2,3,\*) | 77 (1,3,\*) | 3.1 | 62 (1,3,\*) | | | 16 | 77 (2,3,\*) | 76 (1,3,\*) | | 60 (1,3,\*) | | | 15 | 76 (2,3,\*) | 75 (1,3,\*) | | 58 (1,3,\*) | | | 14 | 75 (2,3,\*) | 74 (1,3,\*) | | 57 (1,3,\*) | | | 13 | 74 (2,3,\*) | 73 (1,3,\*) | | 56 (1,3,\*) | | | 12 | 73 (2,3,\*) | 72 (1,3,\*) | | 55 (1,3,\*) | | | | 72 (2,3,\*) | 71 (1,3,\*) | | 54 (1,3,\*) | | | | 71 (2,3,\*) | 70 (1,3,\*) | | 53 (1,3,\*) | | | | 70 (2,3,\*) | 69 (1,3,\*) | | 52 (1,3,\*) | | | | 69 (2,3,\*) | 68 (1,3,\*) | | 51 (1,3,\*) | | | | 68 (2,3,\*) | 67 (1,3,\*) | | 50 (1,3,\*) | | | | 67 (2,3,\*) | 66 (1,3,\*) | | 49 (1,3,\*) | | | | 66 (2,3,\*) | 65 (1,3,\*) | | 48 (1,3,\*) | | | | 65 (2,3,\*) | 64 (1,3,\*) | | 47 (1,3,\*) | | | | 64 (2,3,\*) | 63 (1,3,\*) | | 46 (1,3,\*) | | | | 63 (2,3,\*) | 62 (1,3,\*) | | 45 (1,3,\*) | | | | 62 (2,3,\*) | 61 (1,3,\*) | | 44 (1,3,\*) | | | | 61 (2,3,\*) | 60 (1,3,\*) | | 43 (1,3,\*) | | | | 60 (2,3,\*) | 59 (1,3,\*) | | 42 (1,3,\*) | | | | 59 (2,3,\*) | 58 (1,3,\*) | | 41 (1,3,\*) | | | | 58 (2,3,\*) | 57 (1,3,\*) | | 40 (1,3,\*) | | | | 57 (2,3,\*) | 56 (1,3,\*) | | 39 (1,3,\*) | | | | 56 (2,3,\*) | 55 (1,3,\*) | | 38 (1,3,\*) | | | | 55 (2,3,\*) | 54 (1,3,\*) | | 37 (1,3,\*) | | | | 54 (2,3,\*) | 53 (1,3,\*) | | 36 (1,3,\*) | | | | 53 (2,3,\*) | 52 (1,3,\*) | | 35 (1,3,\*) | | | | 52 (2,3,\*) | 51 (1,3,\*) | | 34 (1,3,\*) | | | | 51 (2,3,\*) | 50 (1,3,\*) | | 33 (1,3,\*) | | | | 50 (2,3,\*) | 49 (1,3,\*) | | 32 (1,3,\*) | | | | 49 (2,3,\*) | 48 (1,3,\*) | | 31 (1,3,\*) | | | | 48 (2,3,\*) | 47 (1,3,\*) | | 30 (1,3,\*) | | | | 47 (2,3,\*) | 46 (1,3,\*) | | 29 (1,3,\*) | | | | 46 (2,3,\*) | 45 (1,3,\*) | | 28 (1,3,\*) | | | | 45 (2,3,\*) | 44 (1,3,\*) | | 27 (1,3,\*) | | | | 44 (2,3,\*) | 43 (1,3,\*) | | 26 (1,3,\*) | | | | 43 (2,3,\*) | 42 (1,3,\*) | | 25 (1,3,\*) | | | | 42 (2,3,\*) | 41 (1,3,\*) | | 24 (1,3,\*) | | | | 41 (2,3,\*) | 40 (1,3,\*) | | 23 (1,3,\*) | | | | 40 (2,3,\*) | 39 (1,3,\*) | | 22 (1,3,\*) | | | | 39 (2,3,\*) | 38 (1,3,\*) | | 21 (1,3,\*) | | | | 38 (2,3,\*) | 37 (1,3,\*) | | 20 (1,3,\*) | | | | 37 (2,3,\*) | 36 (1,3,\*) | | 19 (1,3,\*) | | | | 36 (2,3,\*) | 35 (1,3,\*) | | 18 (1,3,\*) | | | | 35 (2,3,\*) | 34 (1,3,\*) | | 17 (1,3,\*) | | | | 34 (2,3,\*) | 33 (1,3,\*) | | 16 (1,3,\*) | | | | 33 (2,3,\*) | 32 (1,3,\*) | | 15 (1,3,\*) | | | | 32 (2,3,\*) | 31 (1,3,\*) | | 12.1 | | | | 31 (2,3,\*) | 30 (1,3,\*) | | 12 | | | | 30 (2,3,\*) | 29 (1,3,\*) | | 11.6 | | | | 29 (2,3,\*) | 28 (1,3,\*) | | 11.5 | | | | 28 (2,3,\*) | 27 (1,3,\*) | | 11.1 | | | | 27 (2,3,\*) | 26 (1,3,\*) | | 11 | | | | 26 (2,3,\*) | 25 (1,3,\*) | | 10.6 | | | | 25 (2,3,\*) | 24 (1,3,\*) | | 10.5 | | | | 24 | 23 (1,3,\*) | | 10.0-10.1 | | | | 23 | 22 (1,3,\*) | | 9.5-9.6 | | | | 22 | 21 (1,3,\*) | | 9 | | | | 21 | 20 (1,3,\*) | | | | | | 20 | 19 (1,3,\*) | | | | | | 19 | 18 (1,3,\*) | | | | | | 18 | 17 (1,3,\*) | | | | | | 17 | 16 (1,3,\*) | | | | | | 16 | 15 (1,3,\*) | | | | | | 15 | 14 (1,3,\*) | | | | | | 14 | 13 (1,3,\*) | | | | | | 13 | 12 (1,3,\*) | | | | | | 12 | 11 (1,3,\*) | | | | | | 11 | 10 (1,3,\*) | | | | | | 10 | 9 (1,3,\*) | | | | | | 9 | 8 (1,3,\*) | | | | | | 8 | 7 (1,3,\*) | | | | | | 7 | 6 (1,3,\*) | | | | | | 6 | 5 (1,3,\*) | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (2,3,\*) | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Though present in early (2002) drafts of CSS3 Fonts, `font-smooth` has been removed from this specification and is currently not on the standard track. 1. WebKit implements something similar with a different name `-webkit-font-smoothing` and different values: `none`, `antialiased` and `subpixel-antialiased`. 2. Firefox implements something similar with a different name `-moz-osx-font-smoothing` and different values: `auto`, `inherit`, `unset`, `grayscale`. 3. Works only on Mac OS X platform. \* Partial support with prefix. Bugs ---- * Chrome briefly removed and then re-instated support for -webkit-font-smoothing in 2012. Resources --------- * [MDN Web Docs - font-smooth](https://developer.mozilla.org/en-US/docs/Web/CSS/font-smooth) * [Old version of W3C recommendation containing font-smooth](https://www.w3.org/TR/WD-font/#font-smooth)
programming_docs
browser_support_tables Ping attribute Ping attribute ============== When used on an anchor, this attribute signifies that the browser should send a ping request the resource the attribute points to. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/semantics.html#ping> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 (1) | 110 | TP | | | | | 109 (1) | 109 | 16.3 | | | 11 | 108 | 108 (1) | 108 | 16.2 | 92 | | 10 | 107 | 107 (1) | 107 | 16.1 | 91 | | 9 | 106 | 106 (1) | 106 | 16.0 | 90 | | 8 | 105 | 105 (1) | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 (1) | 104 | 15.5 | 88 | | 6 | 103 | 103 (1) | 103 | 15.4 | 87 | | 5.5 | 102 | 102 (1) | 102 | 15.2-15.3 | 86 | | | 101 | 101 (1) | 101 | 15.1 | 85 | | | 100 | 100 (1) | 100 | 15 | 84 | | | 99 | 99 (1) | 99 | 14.1 | 83 | | | 98 | 98 (1) | 98 | 14 | 82 | | | 97 | 97 (1) | 97 | 13.1 | 81 | | | 96 | 96 (1) | 96 | 13 | 80 | | | 95 | 95 (1) | 95 | 12.1 | 79 | | | 94 | 94 (1) | 94 | 12 | 78 | | | 93 | 93 (1) | 93 | 11.1 | 77 | | | 92 | 92 (1) | 92 | 11 | 76 | | | 91 | 91 (1) | 91 | 10.1 | 75 | | | 90 | 90 (1) | 90 | 10 | 74 | | | 89 | 89 (1) | 89 | 9.1 | 73 | | | 88 | 88 (1) | 88 | 9 | 72 | | | 87 | 87 (1) | 87 | 8 | 71 | | | 86 | 86 (1) | 86 | 7.1 | 70 | | | 85 | 85 (1) | 85 | 7 | 69 | | | 84 | 84 (1) | 84 | 6.1 | 68 | | | 83 | 83 (1) | 83 | 6 | 67 | | | 81 | 82 (1) | 81 | 5.1 | 66 | | | 80 | 81 (1) | 80 | 5 | 65 | | | 79 | 80 (1) | 79 | 4 | 64 | | | 18 | 79 (1) | 78 | 3.2 | 63 | | | 17 | 78 (1) | 77 | 3.1 | 62 | | | 16 | 77 (1) | 76 | | 60 | | | 15 | 76 (1) | 75 | | 58 | | | 14 | 75 (1) | 74 | | 57 | | | 13 | 74 (1) | 73 | | 56 | | | 12 | 73 (1) | 72 | | 55 | | | | 72 (1) | 71 | | 54 | | | | 71 (1) | 70 | | 53 | | | | 70 (1) | 69 | | 52 | | | | 69 (1) | 68 | | 51 | | | | 68 (1) | 67 | | 50 | | | | 67 (1) | 66 | | 49 | | | | 66 (1) | 65 | | 48 | | | | 65 (1) | 64 | | 47 | | | | 64 (1) | 63 | | 46 | | | | 63 (1) | 62 | | 45 | | | | 62 (1) | 61 | | 44 | | | | 61 (1) | 60 | | 43 | | | | 60 (1) | 59 | | 42 | | | | 59 (1) | 58 | | 41 | | | | 58 (1) | 57 | | 40 | | | | 57 (1) | 56 | | 39 | | | | 56 (1) | 55 | | 38 | | | | 55 (1) | 54 | | 37 | | | | 54 (1) | 53 | | 36 | | | | 53 (1) | 52 | | 35 | | | | 52 (1) | 51 | | 34 | | | | 51 (1) | 50 | | 33 | | | | 50 (1) | 49 | | 32 | | | | 49 (1) | 48 | | 31 | | | | 48 (1) | 47 | | 30 | | | | 47 (1) | 46 | | 29 | | | | 46 (1) | 45 | | 28 | | | | 45 (1) | 44 | | 27 | | | | 44 (1) | 43 | | 26 | | | | 43 (1) | 42 | | 25 | | | | 42 (1) | 41 | | 24 | | | | 41 (1) | 40 | | 23 | | | | 40 (1) | 39 | | 22 | | | | 39 (1) | 38 | | 21 | | | | 38 (1) | 37 | | 20 | | | | 37 (1) | 36 | | 19 | | | | 36 (1) | 35 | | 18 | | | | 35 (1) | 34 | | 17 | | | | 34 (1) | 33 | | 16 | | | | 33 (1) | 32 | | 15 | | | | 32 (1) | 31 | | 12.1 | | | | 31 (1) | 30 | | 12 | | | | 30 (1) | 29 | | 11.6 | | | | 29 (1) | 28 | | 11.5 | | | | 28 (1) | 27 | | 11.1 | | | | 27 (1) | 26 | | 11 | | | | 26 (1) | 25 | | 10.6 | | | | 25 (1) | 24 | | 10.5 | | | | 24 (1) | 23 | | 10.0-10.1 | | | | 23 (1) | 22 | | 9.5-9.6 | | | | 22 (1) | 21 | | 9 | | | | 21 (1) | 20 | | | | | | 20 (1) | 19 | | | | | | 19 (1) | 18 | | | | | | 18 (1) | 17 | | | | | | 17 (1) | 16 | | | | | | 16 (1) | 15 | | | | | | 15 (1) | 14 | | | | | | 14 (1) | 13 | | | | | | 13 (1) | 12 | | | | | | 12 (1) | 11 | | | | | | 11 (1) | 10 | | | | | | 10 (1) | 9 | | | | | | 9 (1) | 8 | | | | | | 8 (1) | 7 | | | | | | 7 (1) | 6 | | | | | | 6 (1) | 5 | | | | | | 5 (1) | 4 | | | | | | 4 (1) | | | | | | | 3.6 (1) | | | | | | | 3.5 (1) | | | | | | | 3 (1) | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 (1) | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (1) | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- While still in the WHATWG specification, this feature was removed from the W3C HTML5 specification in 2010. 1. Disabled by default for [privacy reasons](http://kb.mozillazine.org/Browser.send_pings). Can be enabled via the `browser.send_pings` flag. Resources --------- * [MDN Web Docs - Element ping attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-ping) browser_support_tables Small, Large, and Dynamic viewport units Small, Large, and Dynamic viewport units ======================================== Viewport units similar to `vw` and `vh` that are based on shown or hidden browser UI states to address shortcomings of the original units. Currently defined as the `sv*` units (`svb`, `svh`, `svi`, `svmax`, `svmin`, `svw`), `lv*` units (`lvb`, `lvh`, `lvi`, `lvmax`, `lvmin`, `lvw`), `dv*` units (`dvb`, `dvh`, `dvi`, `dvmax`, `dvmin`, `dvw`) and the logical `vi`/`vb` units. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css-values-4/#viewport-variants> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 (1) | | 10 | 107 (1) | 107 | 107 (1) | 16.1 | 91 (1) | | 9 | 106 (1) | 106 | 106 (1) | 16.0 | 90 | | 8 | 105 (1) | 105 | 105 (1) | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 (1) | 15.5 | 88 | | 6 | 103 | 103 | 103 (1) | 15.4 | 87 | | 5.5 | 102 | 102 | 102 (1) | 15.2-15.3 | 86 | | | 101 | 101 | 101 (1) | 15.1 | 85 | | | 100 | 100 | 100 (1) | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled via the [Experimental Web Platform features](chrome://flags/#enable-experimental-web-platform-features) flag Bugs ---- * Safari 15.6 on macOS has an issue where `dvh` is larger than expected ([242758](https://bugs.webkit.org/show_bug.cgi?id=242758)). Resources --------- * [Blog post explaining the new units](https://www.bram.us/2021/07/08/the-large-small-and-dynamic-viewports/) * [Chromium support bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1093055) * [Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1610815) * [WebKit support bug](https://bugs.webkit.org/show_bug.cgi?id=219287) * [MDN Web Docs - Relative length units based on viewport](https://developer.mozilla.org/en-US/docs/Web/CSS/length#relative_length_units_based_on_viewport) browser_support_tables Payment Request API Payment Request API =================== Payment Request is a new API for the open web that makes checkout flows easier, faster and consistent on shopping sites. | | | | --- | --- | | Spec | <https://www.w3.org/TR/payment-request/> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 (8) | 110 | TP | | | | | 109 (8) | 109 | 16.3 | | | 11 | 108 | 108 (8) | 108 | 16.2 | 92 | | 10 | 107 | 107 (8) | 107 | 16.1 | 91 | | 9 | 106 | 106 (8) | 106 | 16.0 | 90 | | 8 | 105 | 105 (8) | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 (8) | 104 | 15.5 | 88 | | 6 | 103 | 103 (8) | 103 | 15.4 | 87 | | 5.5 | 102 | 102 (8) | 102 | 15.2-15.3 | 86 | | | 101 | 101 (8) | 101 | 15.1 | 85 | | | 100 | 100 (8) | 100 | 15 | 84 | | | 99 | 99 (8) | 99 | 14.1 | 83 | | | 98 | 98 (8) | 98 | 14 | 82 | | | 97 | 97 (8) | 97 | 13.1 | 81 | | | 96 | 96 (8) | 96 | 13 | 80 | | | 95 | 95 (8) | 95 | 12.1 | 79 | | | 94 | 94 (8) | 94 | 12 (7) | 78 | | | 93 | 93 (8) | 93 | 11.1 (7) | 77 | | | 92 | 92 (8) | 92 | 11 (3) | 76 | | | 91 | 91 (8) | 91 | 10.1 (3) | 75 | | | 90 | 90 (8) | 90 | 10 (3) | 74 | | | 89 | 89 (8) | 89 | 9.1 | 73 | | | 88 | 88 (8) | 88 | 9 | 72 | | | 87 | 87 (8) | 87 | 8 | 71 | | | 86 | 86 (8) | 86 | 7.1 | 70 | | | 85 | 85 (8) | 85 | 7 | 69 | | | 84 | 84 (8) | 84 | 6.1 | 68 | | | 83 | 83 (8) | 83 | 6 | 67 | | | 81 | 82 (8) | 81 | 5.1 | 66 | | | 80 | 81 (8) | 80 | 5 | 65 (7) | | | 79 | 80 (8) | 79 | 4 | 64 (7) | | | 18 (7) | 79 (8) | 78 | 3.2 | 63 (7) | | | 17 (7) | 78 (8) | 77 (7) | 3.1 | 62 (7) | | | 16 (7) | 77 (8) | 76 (7) | | 60 (7) | | | 15 (7) | 76 (8) | 75 (7) | | 58 (7) | | | 14 (2) | 75 (8) | 74 (7) | | 57 (7) | | | 13 | 74 (8) | 73 (7) | | 56 (7) | | | 12 | 73 (8) | 72 (7) | | 55 (7) | | | | 72 (8) | 71 (7) | | 54 (7) | | | | 71 (8) | 70 (7) | | 53 (7) | | | | 70 (8) | 69 (7) | | 52 (7) | | | | 69 (8) | 68 (7) | | 51 (7) | | | | 68 (8) | 67 (7) | | 50 (7) | | | | 67 (8) | 66 (7) | | 49 (7) | | | | 66 (8) | 65 (7) | | 48 (7) | | | | 65 (6) | 64 (7) | | 47 (1) | | | | 64 (6) | 63 (7) | | 46 (1) | | | | 63 (6) | 62 (7) | | 45 (1) | | | | 62 (6) | 61 (7) | | 44 (1) | | | | 61 (6) | 60 (4) | | 43 (1) | | | | 60 (6) | 59 (4) | | 42 (1) | | | | 59 (6) | 58 (1) | | 41 (1) | | | | 58 (6) | 57 (1) | | 40 (1) | | | | 57 (6) | 56 (1) | | 39 | | | | 56 (6) | 55 (1) | | 38 | | | | 55 (6) | 54 (1) | | 37 | | | | 54 | 53 (1) | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 (5) | 107 | 11 | 13.4 | 19.0 | 13.1 (7) | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 (7) | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 (7) | | | | | 13.4-13.7 | | | | | | | | | 9.2 (7) | | | | | 13.3 | | | | | | | | | 8.2 (7) | | | | | 13.2 | | | | | | | | | 7.2-7.4 (7) | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 (7) | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 (7) | | | | | 12.0-12.1 (7) | | | | | | | | | 4 | | | | | 11.3-11.4 (7) | | | | | | | | | | | | | | 11.0-11.2 (3) | | | | | | | | | | | | | | 10.3 (3) | | | | | | | | | | | | | | 10.0-10.2 (3) | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Apple provides an equivalent proprietary API called [Apple Pay JS](https://developer.apple.com/reference/applepayjs/). Google provides a [PaymentRequest wrapper for Apple Pay JS](https://github.com/GoogleChrome/appr-wrapper). 1. Can be enabled via the "Experimental Web Platform features" flag 2. Can be enabled via the "Experimental Web Payments API" flag 3. Apple's proprietary implementation (see above) 4. Can be enabled via the "[Web Payments API](chrome://flags/#web-payments)" flag 5. Unlike Desktop Chrome, support has been in Chrome for Android since version 53. 6. Can be enabled via the `dom.payments.request.enabled` flag in "about:config" flag since 55. 7. Missing support for PaymentResponse.prototype.retry() method 8. Disabled by default in Nightly. To enable, go to "about:config" and set "dom.payments.request.enabled" to true, and "dom.payments.request.supportedRegions" to "US,CA". Resources --------- * [Spec discussion](https://github.com/w3c/browser-payment-api/) * [Bringing easy and fast checkout with Payment Request API](https://developers.google.com/web/updates/2016/07/payment-request) * [Payment Request API Integration Guide](https://developers.google.com/web/fundamentals/discovery-and-monetization/payment-request/) * [MDN Web Docs - Payment Request API](https://developer.mozilla.org/en-US/docs/Web/API/Payment_Request_API) * [Demo](https://paymentrequest.show/demo) * [Simpler Demos and Codes](https://googlechrome.github.io/samples/paymentrequest/)
programming_docs
browser_support_tables KeyboardEvent.location KeyboardEvent.location ====================== A `KeyboardEvent` property that indicates the location of the key on the input device. Useful when there are more than one physical key for the same logical key (e.g. left or right "Control" key; main or numpad "1" key). | | | | --- | --- | | Spec | <https://www.w3.org/TR/uievents/#dom-keyboardevent-location> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 (1) | 66 | | | 80 | 81 | 80 | 5 (1) | 65 | | | 79 | 80 | 79 | 4 (1) | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 (1) | | | | 33 | 32 | | 15 (1) | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 (1) | | 11.6 | | | | 29 | 28 (1) | | 11.5 | | | | 28 | 27 (1) | | 11.1 | | | | 27 | 26 (1) | | 11 | | | | 26 | 25 (1) | | 10.6 | | | | 25 | 24 (1) | | 10.5 | | | | 24 | 23 (1) | | 10.0-10.1 | | | | 23 | 22 (1) | | 9.5-9.6 | | | | 22 | 21 (1) | | 9 | | | | 21 | 20 (1) | | | | | | 20 | 19 (1) | | | | | | 19 | 18 (1) | | | | | | 18 | 17 (1) | | | | | | 17 | 16 (1) | | | | | | 16 | 15 (1) | | | | | | 15 | 14 (1) | | | | | | 14 | 13 (1) | | | | | | 13 | 12 (1) | | | | | | 12 | 11 (1) | | | | | | 11 | 10 (1) | | | | | | 10 | 9 (1) | | | | | | 9 | 8 (1) | | | | | | 8 | 7 (1) | | | | | | 7 | 6 (1) | | | | | | 6 | 5 (1) | | | | | | 5 | 4 (1) | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 (1) | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 (1) | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 (1) | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 (1) | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 (1) | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 (1) | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 (1) | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 (1) | | | | | | | | | | | | | | 6.0-6.1 (1) | | | | | | | | | | | | | | 5.0-5.1 (1) | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Only supports `KeyboardEvent.keyLocation` from an older draft of the DOM Level 3 Events spec instead. Resources --------- * [MDN Web Docs - location](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/location) browser_support_tables Permissions Policy Permissions Policy ================== A security mechanism that allows developers to explicitly enable or disable various powerful browser features for a given site. Similar to [Document Policy](/document-policy). | | | | --- | --- | | Spec | <https://w3c.github.io/webappsec-permissions-policy/> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (1,2) | | | | | | 110 (2) | 110 (1,2) | TP (2) | | | | | 109 (2) | 109 (1,2) | 16.3 (2) | | | 11 | 108 (1,2) | 108 (2) | 108 (1,2) | 16.2 (2) | 92 (2) | | 10 | 107 (1,2) | 107 (2) | 107 (1,2) | 16.1 (2) | 91 (2) | | 9 | 106 (1,2) | 106 (2) | 106 (1,2) | 16.0 (2) | 90 (2) | | 8 | 105 (1,2) | 105 (2) | 105 (1,2) | 15.6 (2) | 89 (2) | | [Show all](#) | | 7 | 104 (1,2) | 104 (2) | 104 (1,2) | 15.5 (2) | 88 (2) | | 6 | 103 (1,2) | 103 (2) | 103 (1,2) | 15.4 (2) | 87 (2) | | 5.5 | 102 (1,2) | 102 (2) | 102 (1,2) | 15.2-15.3 (2) | 86 (2) | | | 101 (1,2) | 101 (2) | 101 (1,2) | 15.1 (2) | 85 (2) | | | 100 (1,2) | 100 (2) | 100 (1,2) | 15 (2) | 84 (2) | | | 99 (1,2) | 99 (2) | 99 (1,2) | 14.1 (2) | 83 (2) | | | 98 (1,2) | 98 (2) | 98 (1,2) | 14 (2) | 82 (2) | | | 97 (1,2) | 97 (2) | 97 (1,2) | 13.1 (2) | 81 (2) | | | 96 (1,2) | 96 (2) | 96 (1,2) | 13 (2) | 80 (2) | | | 95 (1,2) | 95 (2) | 95 (1,2) | 12.1 (2) | 79 (2) | | | 94 (1,2) | 94 (2) | 94 (1,2) | 12 (2) | 78 (2) | | | 93 (1,2) | 93 (2) | 93 (1,2) | 11.1 (2) | 77 (2) | | | 92 (1,2) | 92 (2) | 92 (1,2) | 11 | 76 (2) | | | 91 (1,2) | 91 (2) | 91 (1,2) | 10.1 | 75 (2) | | | 90 (1,2) | 90 (2) | 90 (1,2) | 10 | 74 (2) | | | 89 (1,2) | 89 (2) | 89 (1,2) | 9.1 | 73 (2) | | | 88 (1,2) | 88 (2) | 88 (1,2) | 9 | 72 (2) | | | 87 (2) | 87 (2) | 87 (2) | 8 | 71 (2) | | | 86 (2) | 86 (2) | 86 (2) | 7.1 | 70 (2) | | | 85 (2) | 85 (2) | 85 (2) | 7 | 69 (2) | | | 84 (2) | 84 (2) | 84 (2) | 6.1 | 68 (2) | | | 83 (2) | 83 (2) | 83 (2) | 6 | 67 (2) | | | 81 (2) | 82 (2) | 81 (2) | 5.1 | 66 (2) | | | 80 (2) | 81 (2) | 80 (2) | 5 | 65 (2) | | | 79 (2) | 80 (2) | 79 (2) | 4 | 64 (2) | | | 18 | 79 (2) | 78 (2) | 3.2 | 63 (2) | | | 17 | 78 (2) | 77 (2) | 3.1 | 62 (2) | | | 16 | 77 (2) | 76 (2) | | 60 (2) | | | 15 | 76 (2) | 75 (2) | | 58 (2) | | | 14 | 75 (2) | 74 (2) | | 57 (2) | | | 13 | 74 (2) | 73 (2) | | 56 (2) | | | 12 | 73 | 72 (2) | | 55 (2) | | | | 72 | 71 (2) | | 54 (2) | | | | 71 | 70 (2) | | 53 (2) | | | | 70 | 69 (2) | | 52 (2) | | | | 69 | 68 (2) | | 51 (2) | | | | 68 | 67 (2) | | 50 (2) | | | | 67 | 66 (2) | | 49 (2) | | | | 66 | 65 (2) | | 48 (2) | | | | 65 | 64 (2) | | 47 (2) | | | | 64 | 63 (2) | | 46 | | | | 63 | 62 (2) | | 45 | | | | 62 | 61 (2) | | 44 | | | | 61 | 60 (2) | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (2) | | | | | | | | | | | | | | 16.2 (2) | all | 108 (2) | 10 | 72 (1,2) | 108 (1,2) | 107 | 11 | 13.4 | 19.0 (2) | 13.1 (2) | 13.18 (1,2) | 2.5 | | 16.1 (2) | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 (2) | | | | | 16.0 (2) | | 4.4 | | 12 | | | | | 17.0 (2) | | | | | 15.6 (2) | | 4.2-4.3 | | 11.5 | | | | | 16.0 (2) | | | | | [Show all](#) | | 15.5 (2) | | 4.1 | | 11.1 | | | | | 15.0 (2) | | | | | 15.4 (2) | | 4 | | 11 | | | | | 14.0 (2) | | | | | 15.2-15.3 (2) | | 3 | | 10 | | | | | 13.0 (2) | | | | | 15.0-15.1 (2) | | 2.3 | | | | | | | 12.0 (2) | | | | | 14.5-14.8 (2) | | 2.2 | | | | | | | 11.1-11.2 (2) | | | | | 14.0-14.4 (2) | | 2.1 | | | | | | | 10.1 (2) | | | | | 13.4-13.7 (2) | | | | | | | | | 9.2 (2) | | | | | 13.3 (2) | | | | | | | | | 8.2 (2) | | | | | 13.2 (2) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (2) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (2) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 (2) | | | | | | | | | 4 | | | | | 11.3-11.4 (2) | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Standard support includes the HTTP `Permissions-Policy` header, `allow` attribute on iframes and the `document.permissionsPolicy` JS API. 1. Chromium browsers only support the HTTP header. 2. At least partially supports [Feature Policy](/feature-policy), the predecessor to this spec. Resources --------- * [W3C - Permissions Policy Explainer](https://github.com/w3c/webappsec-feature-policy/blob/main/permissions-policy-explainer.md) * [Firefox implementation tracker](https://bugzilla.mozilla.org/show_bug.cgi?id=1531012) * [List of known features](https://github.com/w3c/webappsec-permissions-policy/blob/main/features.md) browser_support_tables Subresource Integrity Subresource Integrity ===================== Subresource Integrity enables browsers to verify that file is delivered without unexpected manipulation. | | | | --- | --- | | Spec | <https://www.w3.org/TR/SRI/> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 (1) | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled via the "Experimental Features" developer menu Resources --------- * [Subresource Integrity (MDN)](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) * [SRI generation and browser support test](https://www.srihash.org/) * [WebKit feature request bug](https://bugs.webkit.org/show_bug.cgi?id=148363)
programming_docs
browser_support_tables CSS3 Colors CSS3 Colors =========== Method of describing colors using Hue, Saturation and Lightness (hsl()) rather than just RGB, as well as allowing alpha-transparency with rgba() and hsla(). | | | | --- | --- | | Spec | <https://www.w3.org/TR/css3-color/> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Dev.Opera article](https://dev.opera.com/articles/view/color-in-opera-10-hsl-rgb-and-alpha-transparency/) * [WebPlatform Docs](https://webplatform.github.io/docs/css/color#RGBA_Notation) browser_support_tables Data URIs Data URIs ========= Method of embedding images and other files in webpages as a string of text, generally using base64 encoding. | | | | --- | --- | | Spec | <https://tools.ietf.org/html/rfc2397> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (2) | 108 | 108 | 108 | 16.2 | 92 | | 10 (2) | 107 | 107 | 107 | 16.1 | 91 | | 9 (2) | 106 | 106 | 106 | 16.0 | 90 | | 8 (1) | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 (2) | 79 | 78 | 3.2 | 63 | | | 17 (2) | 78 | 77 | 3.1 | 62 | | | 16 (2) | 77 | 76 | | 60 | | | 15 (2) | 76 | 75 | | 58 | | | 14 (2,3) | 75 | 74 | | 57 | | | 13 (2) | 74 | 73 | | 56 | | | 12 (2) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 (2) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 (2) | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Support is limited to images and linked resources like CSS files, not HTML or JS files. Max URI length is 32KB. 2. Support is limited to images and linked resources like CSS or JS, not HTML files. Maximum size limit is 4GB. 3. SVGs with XML declarations are not displayed when used in data-urls Bugs ---- * Non-base64-encoded SVG data URIs need to be uriencoded to work in IE, Edge and Firefox < 4 as according to the specification. For Edge 18 it is needed to encode '', '^', '`', '|', and 'x7F'. Resources --------- * [Information page](https://css-tricks.com/data-uris/) * [Wikipedia](https://en.wikipedia.org/wiki/data_URI_scheme) * [Data URL converter](https://www.websiteoptimization.com/speed/tweak/inline-images/) * [Information on security issues](https://klevjers.com/papers/phishing.pdf) browser_support_tables Custom Elements (V1) Custom Elements (V1) ==================== One of the key features of the Web Components system, custom elements allow new HTML tags to be defined. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/scripting.html#custom-elements> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP (1) | | | | | 109 | 109 | 16.3 (1) | | | 11 | 108 | 108 | 108 | 16.2 (1) | 92 | | 10 | 107 | 107 | 107 | 16.1 (1) | 91 | | 9 | 106 | 106 | 106 | 16.0 (1) | 90 | | 8 | 105 | 105 | 105 | 15.6 (1) | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 (1) | 88 | | 6 | 103 | 103 | 103 | 15.4 (1) | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 (1) | 86 | | | 101 | 101 | 101 | 15.1 (1) | 85 | | | 100 | 100 | 100 | 15 (1) | 84 | | | 99 | 99 | 99 | 14.1 (1) | 83 | | | 98 | 98 | 98 | 14 (1) | 82 | | | 97 | 97 | 97 | 13.1 (1) | 81 | | | 96 | 96 | 96 | 13 (1) | 80 | | | 95 | 95 | 95 | 12.1 (1) | 79 | | | 94 | 94 | 94 | 12 (1) | 78 | | | 93 | 93 | 93 | 11.1 (1) | 77 | | | 92 | 92 | 92 | 11 (1) | 76 | | | 91 | 91 | 91 | 10.1 (1) | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 (1) | | | 17 | 78 | 77 | 3.1 | 62 (1) | | | 16 | 77 | 76 | | 60 (1) | | | 15 | 76 | 75 | | 58 (1) | | | 14 | 75 | 74 | | 57 (1) | | | 13 | 74 | 73 | | 56 (1) | | | 12 | 73 | 72 | | 55 (1) | | | | 72 | 71 | | 54 (1) | | | | 71 | 70 | | 53 (1) | | | | 70 | 69 | | 52 (1) | | | | 69 | 68 | | 51 (1) | | | | 68 | 67 | | 50 (1) | | | | 67 | 66 (1) | | 49 (1) | | | | 66 | 65 (1) | | 48 (1) | | | | 65 | 64 (1) | | 47 (1) | | | | 64 | 63 (1) | | 46 (1) | | | | 63 | 62 (1) | | 45 (1) | | | | 62 (3,1) | 61 (1) | | 44 (1) | | | | 61 (3,1) | 60 (1) | | 43 (1) | | | | 60 (3,1) | 59 (1) | | 42 (1) | | | | 59 (3,1) | 58 (1) | | 41 (1) | | | | 58 (2,1) | 57 (1) | | 40 | | | | 57 (2,1) | 56 (1) | | 39 | | | | 56 (2,1) | 55 (1) | | 38 | | | | 55 (2,1) | 54 (1) | | 37 | | | | 54 (2,1) | 53 | | 36 | | | | 53 (2,1) | 52 | | 35 | | | | 52 (2,1) | 51 | | 34 | | | | 51 (2,1) | 50 | | 33 | | | | 50 (2,1) | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (1) | | | | | | | | | | | | | | 16.2 (1) | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 (1) | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 (1) | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 (1) | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 (1) | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 (1) | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 (1) | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 (1) | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 (1) | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (1) | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (1) | | | | | | | | | 9.2 | | | | | 13.3 (1) | | | | | | | | | 8.2 | | | | | 13.2 (1) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (1) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (1) | | | | | | | | | 5.0-5.4 (1) | | | | | 12.0-12.1 (1) | | | | | | | | | 4 | | | | | 11.3-11.4 (1) | | | | | | | | | | | | | | 11.0-11.2 (1) | | | | | | | | | | | | | | 10.3 (1) | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Supports "Autonomous custom elements" but not "Customized built-in elements" see [WebKit bug 182671](https://bugs.webkit.org/show_bug.cgi?id=182671). 2. Enabled through the `dom.webcomponents.enabled` preference in `about:config`. 3. Enabled through the `dom.webcomponents.customelements.enabled` preference in `about:config`. Resources --------- * [Google Developers - Custom elements v1: reusable web components](https://developers.google.com/web/fundamentals/primers/customelements/) * [customElements.define polyfill](https://github.com/webcomponents/polyfills/tree/master/packages/custom-elements) * [WebKit Blog: Introducing Custom Elements](https://webkit.org/blog/7027/introducing-custom-elements/) browser_support_tables CSS Exclusions Level 1 CSS Exclusions Level 1 ====================== Exclusions defines how inline content flows around elements. It extends the content wrapping ability of floats to any block-level element. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css3-exclusions/> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (\*) | 108 | 108 | 108 | 16.2 | 92 | | 10 (\*) | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 (\*) | 79 | 78 | 3.2 | 63 | | | 17 (\*) | 78 | 77 | 3.1 | 62 | | | 16 (\*) | 77 | 76 | | 60 | | | 15 (\*) | 76 | 75 | | 58 | | | 14 (\*) | 75 | 74 | | 57 | | | 13 (\*) | 74 | 73 | | 56 | | | 12 (\*) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 (\*) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 (\*) | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- \* Partial support with prefix. Resources --------- * [CSS Exclusions](https://msdn.microsoft.com/en-us/library/ie/hh673558(v=vs.85).aspx) * [Firefox tracking bug](https://bugzilla.mozilla.org/show_bug.cgi?id=674804) * [WebKit tracking bug](https://bugs.webkit.org/show_bug.cgi?id=57311) * [Chromium tracking bug](https://crbug.com/700838)
programming_docs
browser_support_tables Canvas blend modes Canvas blend modes ================== Method of defining the effect resulting from overlaying two layers on a Canvas element. | | | | --- | --- | | Spec | <https://www.w3.org/TR/compositing-1/#blending> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Blog post](https://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/) browser_support_tables Background Sync API Background Sync API =================== Provides one-off and periodic synchronization for Service Workers with an onsync event. | | | | --- | --- | | Spec | <https://wicg.github.io/BackgroundSync/spec/> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1217544) * [SyncManager on MDN Web Docs](https://developer.mozilla.org/docs/Web/API/SyncManager) * [Google Developers blog: Introducing Background Sync](https://developers.google.com/web/updates/2015/12/background-sync) browser_support_tables CSS3 Overflow-wrap CSS3 Overflow-wrap ================== Allows lines to be broken within words if an otherwise unbreakable string is too long to fit. Currently mostly supported using the `word-wrap` property. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css3-text/#overflow-wrap> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Partial support refers to requiring the legacy name "word-wrap" (rather than "overflow-wrap") to work. Resources --------- * [WebPlatform Docs](https://webplatform.github.io/docs/css/properties/word-wrap) * [Bug on Firefox support](https://bugzilla.mozilla.org/show_bug.cgi?id=955857) * [MDN Web Docs - CSS overflow-wrap](https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-wrap) browser_support_tables getElementsByClassName getElementsByClassName ====================== Method of accessing DOM elements by class name | | | | --- | --- | | Spec | <https://dom.spec.whatwg.org/#dom-document-getelementsbyclassname> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Bugs ---- * Safari 3.1 has a caching bug. If the class of an element changes it won't be available for getElementsByClassName. * Opera Mobile (Classic) has a caching bug when getElementsByClassName is used while document.readyState is "loading" * Reported to not work for SVG elements in IE11. Resources --------- * [Test page](https://www.quirksmode.org/dom/tests/basics.html#getElementsByClassName) * [getElementsByClassName on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/getElementsByClassName)
programming_docs
browser_support_tables CSS3 2D Transforms CSS3 2D Transforms ================== Method of transforming an element including rotating, scaling, etc. Includes support for `transform` as well as `transform-origin` properties. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css3-2d-transforms/> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (1) | 108 | 108 | 108 | 16.2 | 92 | | 10 (1) | 107 | 107 | 107 | 16.1 | 91 | | 9 (1,\*) | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 (\*) | 71 | | | 86 | 86 | 86 | 7.1 (\*) | 70 | | | 85 | 85 | 85 | 7 (\*) | 69 | | | 84 | 84 | 84 | 6.1 (\*) | 68 | | | 83 | 83 | 83 | 6 (\*) | 67 | | | 81 | 82 | 81 | 5.1 (\*) | 66 | | | 80 | 81 | 80 | 5 (\*) | 65 | | | 79 | 80 | 79 | 4 (\*) | 64 | | | 18 | 79 | 78 | 3.2 (\*) | 63 | | | 17 | 78 | 77 | 3.1 (\*) | 62 | | | 16 (1) | 77 | 76 | | 60 | | | 15 (1) | 76 | 75 | | 58 | | | 14 (1) | 75 | 74 | | 57 | | | 13 (1) | 74 | 73 | | 56 | | | 12 (1) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 (\*) | | | | 39 | 38 | | 21 (\*) | | | | 38 | 37 | | 20 (\*) | | | | 37 | 36 | | 19 (\*) | | | | 36 | 35 (\*) | | 18 (\*) | | | | 35 | 34 (\*) | | 17 (\*) | | | | 34 | 33 (\*) | | 16 (\*) | | | | 33 | 32 (\*) | | 15 (\*) | | | | 32 | 31 (\*) | | 12.1 | | | | 31 | 30 (\*) | | 12 (\*) | | | | 30 | 29 (\*) | | 11.6 (\*) | | | | 29 | 28 (\*) | | 11.5 (\*) | | | | 28 | 27 (\*) | | 11.1 (\*) | | | | 27 | 26 (\*) | | 11 (\*) | | | | 26 | 25 (\*) | | 10.6 (\*) | | | | 25 | 24 (\*) | | 10.5 (\*) | | | | 24 | 23 (\*) | | 10.0-10.1 | | | | 23 | 22 (\*) | | 9.5-9.6 | | | | 22 | 21 (\*) | | 9 | | | | 21 | 20 (\*) | | | | | | 20 | 19 (\*) | | | | | | 19 | 18 (\*) | | | | | | 18 | 17 (\*) | | | | | | 17 | 16 (\*) | | | | | | 16 | 15 (\*) | | | | | | 15 (\*) | 14 (\*) | | | | | | 14 (\*) | 13 (\*) | | | | | | 13 (\*) | 12 (\*) | | | | | | 12 (\*) | 11 (\*) | | | | | | 11 (\*) | 10 (\*) | | | | | | 10 (\*) | 9 (\*) | | | | | | 9 (\*) | 8 (\*) | | | | | | 8 (\*) | 7 (\*) | | | | | | 7 (\*) | 6 (\*) | | | | | | 6 (\*) | 5 (\*) | | | | | | 5 (\*) | 4 (\*) | | | | | | 4 (\*) | | | | | | | 3.6 (\*) | | | | | | | 3.5 (\*) | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 (\*) | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 (\*) | 7 (\*) | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 (\*) | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 (\*) | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 (\*) | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 (\*) | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 (\*) | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 (\*) | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 (\*) | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 (\*) | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 (\*) | | | | | | | | | | | | | | 8 (\*) | | | | | | | | | | | | | | 7.0-7.1 (\*) | | | | | | | | | | | | | | 6.0-6.1 (\*) | | | | | | | | | | | | | | 5.0-5.1 (\*) | | | | | | | | | | | | | | 4.2-4.3 (\*) | | | | | | | | | | | | | | 4.0-4.1 (\*) | | | | | | | | | | | | | | 3.2 (\*) | | | | | | | | | | | | | Notes ----- The scale transform can be emulated in IE < 9 using Microsoft's "zoom" extension, others are (not easily) possible using the MS Matrix filter 1. Does not support CSS transforms on SVG elements (transform attribute can be used instead) \* Partial support with prefix. Bugs ---- * Scaling transforms in Android 2.3 fails to scale element background images. * In IE9 the caret of a `textarea` disappears when you use translate. * Firefox 42 and below do not support [`transform-origin` on SVG elements](https://bugzilla.mozilla.org/show_bug.cgi?id=923193). Resources --------- * [Live editor](https://www.westciv.com/tools/transforms/) * [MDN Web Docs - CSS transform](https://developer.mozilla.org/en-US/docs/Web/CSS/transform) * [Workaround script for IE](http://www.webresourcesdepot.com/cross-browser-css-transforms-csssandpaper/) * [Converter for IE](https://www.useragentman.com/IETransformsTranslator/) * [has.js test](https://raw.github.com/phiggins42/has.js/master/detect/css.js#css-transform) * [WebPlatform Docs](https://webplatform.github.io/docs/css/properties/transform/) * [Microsoft Edge Platform Status (SVG)](https://developer.microsoft.com/en-us/microsoft-edge/status/supportcsstransformsonsvg/) browser_support_tables SVG favicons SVG favicons ============ Icon used by browsers to identify a webpage or site. While all browsers support the `.ico` format, the SVG format can be preferable to more easily support higher resolutions or larger icons. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/semantics.html#rel-icon> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (3,4) | | | | | | 110 (3) | 110 (3,4) | TP | | | | | 109 (3) | 109 (3,4) | 16.3 | | | 11 | 108 (3,4) | 108 (3) | 108 (3,4) | 16.2 | 92 (3,4) | | 10 | 107 (3,4) | 107 (3) | 107 (3,4) | 16.1 | 91 (3,4) | | 9 | 106 (3,4) | 106 (3) | 106 (3,4) | 16.0 | 90 (3,4) | | 8 | 105 (3,4) | 105 (3) | 105 (3,4) | 15.6 | 89 (3,4) | | [Show all](#) | | 7 | 104 (3,4) | 104 (3) | 104 (3,4) | 15.5 | 88 (3,4) | | 6 | 103 (3,4) | 103 (3) | 103 (3,4) | 15.4 | 87 (3,4) | | 5.5 | 102 (3,4) | 102 (3) | 102 (3,4) | 15.2-15.3 | 86 (3,4) | | | 101 (3,4) | 101 (3) | 101 (3,4) | 15.1 | 85 (3,4) | | | 100 (3,4) | 100 (3) | 100 (3,4) | 15 | 84 (3,4) | | | 99 (3,4) | 99 (3) | 99 (3,4) | 14.1 | 83 (3,4) | | | 98 (3,4) | 98 (3) | 98 (3,4) | 14 | 82 (3,4) | | | 97 (3,4) | 97 (3) | 97 (3,4) | 13.1 | 81 (3,4) | | | 96 (3,4) | 96 (3) | 96 (3,4) | 13 | 80 (3,4) | | | 95 (3,4) | 95 (3) | 95 (3,4) | 12.1 | 79 (3,4) | | | 94 (3,4) | 94 (3) | 94 (3,4) | 12 | 78 (3,4) | | | 93 (3,4) | 93 (3) | 93 (3,4) | 11.1 | 77 (3,4) | | | 92 (3,4) | 92 (3) | 92 (3,4) | 11 | 76 (3,4) | | | 91 (3,4) | 91 (3) | 91 (3,4) | 10.1 | 75 (3,4) | | | 90 (3,4) | 90 (3) | 90 (3,4) | 10 | 74 (3,4) | | | 89 (3,4) | 89 (3) | 89 (3,4) | 9.1 | 73 (3,4) | | | 88 (3,4) | 88 (3) | 88 (3,4) | 9 | 72 (3,4) | | | 87 (3,4) | 87 (3) | 87 (3,4) | 8 | 71 (3,4) | | | 86 (3,4) | 86 (3) | 86 (3,4) | 7.1 | 70 (3,4) | | | 85 (3,4) | 85 (3) | 85 (3,4) | 7 | 69 (3,4) | | | 84 (3,4) | 84 (3) | 84 (3,4) | 6.1 | 68 (3,4) | | | 83 (3,4) | 83 (3) | 83 (3,4) | 6 | 67 (3,4) | | | 81 (3,4) | 82 (3) | 81 (3,4) | 5.1 | 66 | | | 80 (3,4) | 81 (3) | 80 (3,4) | 5 | 65 | | | 79 | 80 (3) | 79 | 4 | 64 | | | 18 | 79 (3) | 78 | 3.2 | 63 | | | 17 | 78 (3) | 77 | 3.1 | 62 | | | 16 | 77 (3) | 76 | | 60 | | | 15 | 76 (3) | 75 | | 58 | | | 14 | 75 (3) | 74 | | 57 | | | 13 | 74 (3) | 73 | | 56 | | | 12 | 73 (3) | 72 | | 55 | | | | 72 (3) | 71 | | 54 | | | | 71 (3) | 70 | | 53 | | | | 70 (3) | 69 | | 52 | | | | 69 (3) | 68 | | 51 | | | | 68 (3) | 67 | | 50 | | | | 67 (3) | 66 | | 49 | | | | 66 (3) | 65 | | 48 | | | | 65 (3) | 64 | | 47 | | | | 64 (3) | 63 | | 46 | | | | 63 (3) | 62 | | 45 | | | | 62 (3) | 61 | | 44 | | | | 61 (3) | 60 | | 43 | | | | 60 (3) | 59 | | 42 | | | | 59 (3) | 58 | | 41 | | | | 58 (3) | 57 | | 40 | | | | 57 (3) | 56 | | 39 | | | | 56 (3) | 55 | | 38 | | | | 55 (3) | 54 | | 37 | | | | 54 (3) | 53 | | 36 | | | | 53 (3) | 52 | | 35 | | | | 52 (3) | 51 | | 34 | | | | 51 (3) | 50 | | 33 | | | | 50 (3) | 49 | | 32 | | | | 49 (3) | 48 | | 31 | | | | 48 (3) | 47 | | 30 | | | | 47 (3) | 46 | | 29 | | | | 46 (3) | 45 | | 28 | | | | 45 (3) | 44 | | 27 | | | | 44 (3) | 43 | | 26 | | | | 43 (3) | 42 | | 25 | | | | 42 (3) | 41 | | 24 | | | | 41 (3) | 40 | | 23 | | | | 40 (2) | 39 | | 22 | | | | 39 (2) | 38 | | 21 | | | | 38 (2) | 37 | | 20 | | | | 37 (2) | 36 | | 19 | | | | 36 (2) | 35 | | 18 | | | | 35 (2) | 34 | | 17 | | | | 34 (2) | 33 | | 16 | | | | 33 (2) | 32 | | 15 | | | | 32 (2) | 31 | | 12.1 | | | | 31 (2) | 30 | | 12 | | | | 30 (2) | 29 | | 11.6 | | | | 29 (2) | 28 | | 11.5 | | | | 28 (2) | 27 | | 11.1 | | | | 27 (2) | 26 | | 11 | | | | 26 (2) | 25 | | 10.6 | | | | 25 (2) | 24 | | 10.5 | | | | 24 (2) | 23 | | 10.0-10.1 | | | | 23 (2) | 22 | | 9.5-9.6 | | | | 22 (2) | 21 | | 9 | | | | 21 (2) | 20 | | | | | | 20 (2) | 19 | | | | | | 19 (2) | 18 | | | | | | 18 (2) | 17 | | | | | | 17 (2) | 16 | | | | | | 16 (2) | 15 | | | | | | 15 (2) | 14 | | | | | | 14 (2) | 13 | | | | | | 13 (2) | 12 | | | | | | 12 (2) | 11 | | | | | | 11 (2) | 10 | | | | | | 10 (2) | 9 | | | | | | 9 (2) | 8 | | | | | | 8 (2) | 7 | | | | | | 7 (2) | 6 | | | | | | 6 (2) | 5 | | | | | | 5 (2) | 4 | | | | | | 4 (2) | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all (1) | 108 | 10 (1) | 72 (3,4) | 108 (3,4) | 107 | 11 (1) | 13.4 | 19.0 (3,4) | 13.1 | 13.18 (3,4) | 2.5 (3) | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 (1) | | | 10 (1) | | 18.0 (3,4) | | | | | 16.0 | | 4.4 | | 12 (1) | | | | | 17.0 (3,4) | | | | | 15.6 | | 4.2-4.3 | | 11.5 (1) | | | | | 16.0 (3,4) | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 (1) | | | | | 15.0 (3,4) | | | | | 15.4 | | 4 | | 11 (1) | | | | | 14.0 (3,4) | | | | | 15.2-15.3 | | 3 | | 10 (1) | | | | | 13.0 (3,4) | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 (1) | | | | | | | | | | | | | | 11.0-11.2 (1) | | | | | | | | | | | | | | 10.3 (1) | | | | | | | | | | | | | | 10.0-10.2 (1) | | | | | | | | | | | | | | 9.3 (1) | | | | | | | | | | | | | | 9.0-9.2 (1) | | | | | | | | | | | | | | 8.1-8.4 (1) | | | | | | | | | | | | | | 8 (1) | | | | | | | | | | | | | | 7.0-7.1 (1) | | | | | | | | | | | | | | 6.0-6.1 (1) | | | | | | | | | | | | | | 5.0-5.1 (1) | | | | | | | | | | | | | | 4.2-4.3 (1) | | | | | | | | | | | | | | 4.0-4.1 (1) | | | | | | | | | | | | | | 3.2 (1) | | | | | | | | | | | | | Notes ----- Favicon support is a complicated topic. See [this guide](https://dev.to/masakudamatsu/favicon-nightmare-how-to-maintain-sanity-3al7) for more information. See also [PNG favicons](/link-icon-png). 1. Does not use favicons at all (but may have alternative for bookmarks, etc.). 2. Partial support in Firefox before version 41 refers to only loading the SVG favicon the first time, but not [on subsequent loads](https://bugzilla.mozilla.org/show_bug.cgi?id=366324#c14). 3. Requires the served mime-type to be `image/svg+xml`. 4. Chromium browsers serve the SVG in [secure static mode](https://svgwg.org/svg2-draft/conform.html#secure-static-mode), but apply SMIL animations using the document start time (0). 5. Chromium browsers serve the SVG in [secure static mode](https://svgwg.org/svg2-draft/conform.html#secure-static-mode), but apply SMIL animations using the document start time (0). Resources --------- * [Chrome bug](https://bugs.chromium.org/p/chromium/issues/detail?id=294179) * [Firefox bug, highlights comment that confirms note #4](https://bugzilla.mozilla.org/show_bug.cgi?id=366324#c50) * [WebKit feature request bug](https://bugs.webkit.org/show_bug.cgi?id=136059) * [How to favicon in 2021](https://dev.to/masakudamatsu/favicon-nightmare-how-to-maintain-sanity-3al7) browser_support_tables Datalist element Datalist element ================ Method of setting a list of options for a user to select in a text field, while leaving the ability to enter a custom value. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/forms.html#the-datalist-element> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 (3) | 110 | TP | | | | | 109 (3) | 109 | 16.3 | | | 11 (2) | 108 | 108 (3) | 108 | 16.2 | 92 | | 10 (2) | 107 | 107 (3) | 107 | 16.1 | 91 | | 9 | 106 | 106 (3) | 106 | 16.0 | 90 | | 8 | 105 | 105 (3) | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 (3) | 104 | 15.5 | 88 | | 6 | 103 | 103 (3) | 103 | 15.4 | 87 | | 5.5 | 102 | 102 (3) | 102 | 15.2-15.3 | 86 | | | 101 | 101 (3,6) | 101 | 15.1 | 85 | | | 100 | 100 (3,6) | 100 | 15 | 84 | | | 99 | 99 (3,6) | 99 | 14.1 | 83 | | | 98 | 98 (3,6) | 98 | 14 | 82 | | | 97 | 97 (3,6) | 97 | 13.1 | 81 | | | 96 | 96 (3,6) | 96 | 13 | 80 | | | 95 | 95 (3,6) | 95 | 12.1 | 79 | | | 94 | 94 (3,6) | 94 | 12 | 78 | | | 93 | 93 (3,6) | 93 | 11.1 | 77 | | | 92 | 92 (3,6) | 92 | 11 | 76 | | | 91 | 91 (3,6) | 91 | 10.1 | 75 | | | 90 | 90 (3,6) | 90 | 10 | 74 | | | 89 | 89 (3,6) | 89 | 9.1 | 73 | | | 88 | 88 (3,6) | 88 | 9 | 72 | | | 87 | 87 (3,6) | 87 | 8 | 71 | | | 86 | 86 (3,6) | 86 | 7.1 | 70 | | | 85 | 85 (3,6) | 85 | 7 | 69 | | | 84 | 84 (3,6) | 84 | 6.1 | 68 | | | 83 | 83 (3,6) | 83 | 6 | 67 | | | 81 | 82 (3,6) | 81 | 5.1 | 66 | | | 80 | 81 (3,6) | 80 | 5 | 65 | | | 79 | 80 (3,6) | 79 | 4 | 64 | | | 18 (2,4) | 79 (3,6) | 78 | 3.2 | 63 (1) | | | 17 (2,4) | 78 (3,6) | 77 | 3.1 | 62 (1) | | | 16 (2,4) | 77 (3,6) | 76 | | 60 (1) | | | 15 (2) | 76 (3,6) | 75 | | 58 (1) | | | 14 (2) | 75 (3,6) | 74 | | 57 (1) | | | 13 (2) | 74 (3,6) | 73 | | 56 (1) | | | 12 (2) | 73 (3,6) | 72 | | 55 (1) | | | | 72 (3,6) | 71 | | 54 (1) | | | | 71 (3,6) | 70 | | 53 (1) | | | | 70 (3,6) | 69 | | 52 (1) | | | | 69 (3,6) | 68 (1) | | 51 (1) | | | | 68 (3,6) | 67 (1) | | 50 (1) | | | | 67 (3,6) | 66 (1) | | 49 (1) | | | | 66 (3,6) | 65 (1) | | 48 (1) | | | | 65 (3,6) | 64 (1) | | 47 (1) | | | | 64 (3,6) | 63 (1) | | 46 (1) | | | | 63 (3,6) | 62 (1) | | 45 (1) | | | | 62 (3,6) | 61 (1) | | 44 (1) | | | | 61 (3,6) | 60 (1) | | 43 (1) | | | | 60 (3,6) | 59 (1) | | 42 (1) | | | | 59 (3,6) | 58 (1) | | 41 (1) | | | | 58 (3,6) | 57 (1) | | 40 (1) | | | | 57 (3,6) | 56 (1) | | 39 (1) | | | | 56 (3,6) | 55 (1) | | 38 (1) | | | | 55 (3,6) | 54 (1) | | 37 (1) | | | | 54 (3,6) | 53 (1) | | 36 (1) | | | | 53 (3,6) | 52 (1) | | 35 (1) | | | | 52 (3,6) | 51 (1) | | 34 (1) | | | | 51 (3,6) | 50 (1) | | 33 (1) | | | | 50 (3,6) | 49 (1) | | 32 (1) | | | | 49 (3,6) | 48 (1) | | 31 (1) | | | | 48 (3,6) | 47 (1) | | 30 (1) | | | | 47 (3,6) | 46 (1) | | 29 (1) | | | | 46 (3,6) | 45 (1) | | 28 (1) | | | | 45 (3,6) | 44 (1) | | 27 (1) | | | | 44 (3,6) | 43 (1) | | 26 (1) | | | | 43 (3,6) | 42 (1) | | 25 (1) | | | | 42 (3,6) | 41 (1) | | 24 (1) | | | | 41 (3,6) | 40 (1) | | 23 (1) | | | | 40 (3,6) | 39 (1) | | 22 (1) | | | | 39 (3,6) | 38 (1) | | 21 (1) | | | | 38 (3,6) | 37 (1) | | 20 (1) | | | | 37 (3,6) | 36 (1) | | 19 (1) | | | | 36 (3,6) | 35 (1) | | 18 (1) | | | | 35 (3,6) | 34 (1) | | 17 (1) | | | | 34 (3,6) | 33 (1) | | 16 (1) | | | | 33 (3,6) | 32 (1) | | 15 (1) | | | | 32 (3,6) | 31 (1) | | 12.1 | | | | 31 (3,6) | 30 (1) | | 12 | | | | 30 (3,6) | 29 (1) | | 11.6 | | | | 29 (3,6) | 28 (1) | | 11.5 | | | | 28 (3,6) | 27 (1) | | 11.1 | | | | 27 (3,6) | 26 (1) | | 11 | | | | 26 (3,6) | 25 (1) | | 10.6 | | | | 25 (3,6) | 24 (1) | | 10.5 | | | | 24 (3,6) | 23 (1) | | 10.0-10.1 | | | | 23 (3,6) | 22 (1) | | 9.5-9.6 | | | | 22 (3,6) | 21 (1) | | 9 | | | | 21 (3,6) | 20 (1) | | | | | | 20 (3,6) | 19 | | | | | | 19 (3,6) | 18 | | | | | | 18 (3,6) | 17 | | | | | | 17 (3,6) | 16 | | | | | | 16 (3,6) | 15 | | | | | | 15 (3,6) | 14 | | | | | | 14 (3,6) | 13 | | | | | | 13 (3,6) | 12 | | | | | | 12 (3,6) | 11 | | | | | | 11 (3,6) | 10 | | | | | | 10 (3,6) | 9 | | | | | | 9 (3,6) | 8 | | | | | | 8 (3,6) | 7 | | | | | | 7 (3,6) | 6 | | | | | | 6 (3,6) | 5 | | | | | | 5 (3,6) | 4 | | | | | | 4 (3,6) | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (5) | | | | | | | | | | | | | | 16.2 (5) | all | 108 | 10 | 72 | 108 | 107 (3) | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 (5) | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 (5) | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 (5) | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 (5) | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 (5) | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 (5) | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 (5) | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 (5) | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (5) | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (5) | | | | | | | | | 9.2 | | | | | 13.3 (5) | | | | | | | | | 8.2 | | | | | 13.2 (5) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (5) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (5) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- While most commonly used on text fields, datalists can also be used on other input types. IE11 supports the element on `range` fields. Chrome and Opera also support datalists to suggest given values on `range`, `color` and date/time fields. 1. Partial support refers to [a bug](https://bugs.chromium.org/p/chromium/issues/detail?id=773041) where long lists of items are unscrollable resulting in unselectable options. 2. Partial support in IE refers to [significantly buggy behavior](https://web.archive.org/web/20170121011936/http://playground.onereason.eu/2013/04/ie10s-lousy-support-for-datalists/) (IE11+ does send the input and change events upon selection). 3. Partial support refers to no support for datalists on non-text fields (e.g. number, [range](https://bugzilla.mozilla.org/show_bug.cgi?id=841942), [color](https://bugzilla.mozilla.org/show_bug.cgi?id=960984)). 4. Partial support in Edge refers [to disappearing option elements on focusing the input element via tab](https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/20066595/). 5. Supported through WKWebView and Safari but not through UIWebView 6. In Firefox, autocomplete must be set to off to make dynamic datalist work due to [a bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1474137) Bugs ---- * In UIWebView Apps in iOS 12.2, using the datalist element may cause the input type to become incapable of being able to type in it despite not supporting it. Resources --------- * [Mozilla Hacks article](https://hacks.mozilla.org/2010/11/firefox-4-html5-forms/) * [HTML5 Library including datalist support](https://afarkas.github.io/webshim/demos/) * [MDN Web Docs - datalist](https://developer.mozilla.org/en/HTML/Element/datalist) * [WebPlatform Docs](https://webplatform.github.io/docs/html/elements/datalist) * [Eiji Kitamura's options demos & tests](https://demo.agektmr.com/datalist/) * [Minimal Datalist polyfill w/tutorial](https://github.com/thgreasi/datalist-polyfill) * [Minimal and library dependency-free vanilla JavaScript polyfill](https://github.com/mfranzke/datalist-polyfill)
programming_docs
browser_support_tables :in-range and :out-of-range CSS pseudo-classes :in-range and :out-of-range CSS pseudo-classes ============================================== If a temporal or number `<input>` has `max` and/or `min` attributes, then `:in-range` matches when the value is within the specified range and `:out-of-range` matches when the value is outside the specified range. If there are no range constraints, then neither pseudo-class matches. | | | | --- | --- | | Spec | <https://www.w3.org/TR/selectors4/#range-pseudos> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 (2,3) | 74 | | | 89 | 89 | 89 | 9.1 (2,3) | 73 | | | 88 | 88 | 88 | 9 (2,3) | 72 | | | 87 | 87 | 87 | 8 (2,3) | 71 | | | 86 | 86 | 86 | 7.1 (2,3) | 70 | | | 85 | 85 | 85 | 7 (2,3) | 69 | | | 84 | 84 | 84 | 6.1 (2,3) | 68 | | | 83 | 83 | 83 | 6 (2,3) | 67 | | | 81 | 82 | 81 | 5.1 (2,3) | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 (2) | 79 | 78 | 3.2 | 63 | | | 17 (2) | 78 | 77 | 3.1 | 62 | | | 16 (2) | 77 | 76 | | 60 | | | 15 (2) | 76 | 75 | | 58 | | | 14 (2) | 75 | 74 | | 57 | | | 13 (2) | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 (2) | | | | 56 | 55 | | 38 (2,3) | | | | 55 | 54 | | 37 (2,3) | | | | 54 | 53 | | 36 (2,3) | | | | 53 | 52 (2) | | 35 (2,3) | | | | 52 | 51 (2,3) | | 34 (2,3) | | | | 51 | 50 (2,3) | | 33 (2,3) | | | | 50 | 49 (2,3) | | 32 (2,3) | | | | 49 (3) | 48 (2,3) | | 31 (2,3) | | | | 48 (3) | 47 (2,3) | | 30 (2,3) | | | | 47 (3) | 46 (2,3) | | 29 (2,3) | | | | 46 (3) | 45 (2,3) | | 28 (2,3) | | | | 45 (3) | 44 (2,3) | | 27 (2,3) | | | | 44 (3) | 43 (2,3) | | 26 (2,3) | | | | 43 (3) | 42 (2,3) | | 25 (2,3) | | | | 42 (3) | 41 (2,3) | | 24 (2,3) | | | | 41 (3) | 40 (2,3) | | 23 (2,3) | | | | 40 (3) | 39 (2,3) | | 22 (2,3) | | | | 39 (3) | 38 (2,3) | | 21 (2,3) | | | | 38 (3) | 37 (2,3) | | 20 (2,3) | | | | 37 (3) | 36 (2,3) | | 19 (2,3) | | | | 36 (3) | 35 (2,3) | | 18 (2,3) | | | | 35 (3) | 34 (2,3) | | 17 (2,3) | | | | 34 (3) | 33 (2,3) | | 16 (2,3) | | | | 33 (3) | 32 (2,3) | | 15 (2,3) | | | | 32 (3) | 31 (2,3) | | 12.1 (2) | | | | 31 (3) | 30 (2,3) | | 12 (2) | | | | 30 (3) | 29 (2,3) | | 11.6 (2) | | | | 29 (3) | 28 (2,3) | | 11.5 (2) | | | | 28 | 27 (2,3) | | 11.1 (2) | | | | 27 | 26 (2,3) | | 11 (2) | | | | 26 | 25 (2,3) | | 10.6 (2) | | | | 25 | 24 (2,3) | | 10.5 (2) | | | | 24 | 23 (2,3) | | 10.0-10.1 (2) | | | | 23 | 22 (2,3) | | 9.5-9.6 | | | | 22 | 21 (2,3) | | 9 | | | | 21 | 20 (2,3) | | | | | | 20 | 19 (2,3) | | | | | | 19 | 18 (2,3) | | | | | | 18 | 17 (2,3) | | | | | | 17 | 16 (2,3) | | | | | | 16 | 15 (2,3) | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all (1) | 108 | 10 (2) | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (3) | | 16.1 | | 4.4.3-4.4.4 (2) | 7 | 12.1 (2) | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 (2) | | 12 (2) | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 (2) | | 11.5 (2) | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 (2) | | 11.1 (2) | | | | | 15.0 | | | | | 15.4 | | 4 (2) | | 11 (2) | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 (2) | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 (2) | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 (2,3) | | | | | | | | | | | | | | 9.3 (2,3) | | | | | | | | | | | | | | 9.0-9.2 (2,3) | | | | | | | | | | | | | | 8.1-8.4 (2,3) | | | | | | | | | | | | | | 8 (2,3) | | | | | | | | | | | | | | 7.0-7.1 (2,3) | | | | | | | | | | | | | | 6.0-6.1 (2,3) | | | | | | | | | | | | | | 5.0-5.1 (2,3) | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Note that `<input type="range">` can never match `:out-of-range` because the user cannot input such a value, and if the initial value is outside the range, the browser immediately clamps it to the minimum or maximum (as appropriate) bound of the range. 1. Opera Mini correctly applies style on initial load, but does not correctly update when value is changed. 2. `:in-range` also incorrectly matches temporal and `number` inputs which don't have `min` or `max` attributes. See [Edge bug](https://web.archive.org/web/20171213080515/https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/7200501/), [Chrome bug](https://bugs.chromium.org/p/chromium/issues/detail?id=603268), [WebKit bug](https://bugs.webkit.org/show_bug.cgi?id=156558). 3. `:in-range` and `:out-of-range` incorrectly match inputs which are disabled or readonly. See [Edge bug](https://web.archive.org/web/20171213073431/https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/7190958/), [Mozilla bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1264157), [WebKit bug](https://bugs.webkit.org/show_bug.cgi?id=156530), [Chrome bug](https://bugs.chromium.org/p/chromium/issues/detail?id=602568). Resources --------- * [MDN Web Docs - CSS :out-of-range](https://developer.mozilla.org/en-US/docs/Web/CSS/:out-of-range) * [WHATWG HTML specification for `:in-range` and `:out-of-range`](https://html.spec.whatwg.org/multipage/scripting.html#selector-in-range) browser_support_tables HEVC/H.265 video format HEVC/H.265 video format ======================= The High Efficiency Video Coding (HEVC) compression standard is a video compression format intended to succeed H.264 | | | | --- | --- | | Spec | <https://www.itu.int/rec/T-REC-H.265> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (5) | | | | | | 110 | 110 (5) | TP | | | | | 109 | 109 (5) | 16.3 | | | 11 (1) | 108 (4) | 108 | 108 (5) | 16.2 | 92 | | 10 | 107 (4) | 107 | 107 (5) | 16.1 | 91 | | 9 | 106 (4) | 106 | 106 | 16.0 | 90 | | 8 | 105 (4) | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 (4) | 104 | 104 | 15.5 | 88 | | 6 | 103 (4) | 103 | 103 | 15.4 | 87 | | 5.5 | 102 (4) | 102 | 102 | 15.2-15.3 | 86 | | | 101 (4) | 101 | 101 | 15.1 | 85 | | | 100 (4) | 100 | 100 | 15 | 84 | | | 99 (4) | 99 | 99 | 14.1 | 83 | | | 98 (4) | 98 | 98 | 14 | 82 | | | 97 (4) | 97 | 97 | 13.1 | 81 | | | 96 (4) | 96 | 96 | 13 | 80 | | | 95 (4) | 95 | 95 | 12.1 (3) | 79 | | | 94 (4) | 94 | 94 | 12 (3) | 78 | | | 93 (4) | 93 | 93 | 11.1 (3) | 77 | | | 92 (4) | 92 | 92 | 11 (3) | 76 | | | 91 (4) | 91 | 91 | 10.1 | 75 | | | 90 (4) | 90 | 90 | 10 | 74 | | | 89 (4) | 89 | 89 | 9.1 | 73 | | | 88 (4) | 88 | 88 | 9 | 72 | | | 87 (4) | 87 | 87 | 8 | 71 | | | 86 (4) | 86 | 86 | 7.1 | 70 | | | 85 (4) | 85 | 85 | 7 | 69 | | | 84 (4) | 84 | 84 | 6.1 | 68 | | | 83 (4) | 83 | 83 | 6 | 67 | | | 81 (4) | 82 | 81 | 5.1 | 66 | | | 80 (4) | 81 | 80 | 5 | 65 | | | 79 (4) | 80 | 79 | 4 | 64 | | | 18 (1) | 79 | 78 | 3.2 | 63 | | | 17 (1) | 78 | 77 | 3.1 | 62 | | | 16 (1) | 77 | 76 | | 60 | | | 15 (1) | 76 | 75 | | 58 | | | 14 (1) | 75 | 74 | | 57 | | | 13 (1) | 74 | 73 | | 56 | | | 12 (1) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 (5) | 10 | 72 (2) | 108 (5) | 107 | 11 | 13.4 | 19.0 (2) | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 (2) | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 (2) | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 (2) | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 (2) | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 (2) | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 (2) | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 (2) | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 (2) | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 (2) | | | | | 13.4-13.7 | | | | | | | | | 9.2 (2) | | | | | 13.3 | | | | | | | | | 8.2 (2) | | | | | 13.2 | | | | | | | | | 7.2-7.4 (2) | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 (2) | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 (2) | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Supported only for devices with [hardware support](https://answers.microsoft.com/en-us/insider/forum/insider_apps-insider_wmp/windows-10-hevc-playback-yes-or-no/3c1ab780-a6b2-4b77-ac0f-9faeefd4680d) 2. Reported to work in certain Android devices with hardware support 3. Supported only on macOS High Sierra or later 4. Supported on macOS (Edge >= 107, OS >= Big Sur 11.0) and Windows(>= Windows 10 1709) when [HEVC video extensions from the Microsoft Store](https://apps.microsoft.com/store/detail/hevc-video-extension/9NMZLZ57R3T7) is installed for devices with [hardware support](https://techcommunity.microsoft.com/t5/discussions/updated-dev-channel-build-77-0-211-3-is-live/m-p/745801#M6548) 5. Supported on Windows(>= Windows 8), macOS(>= Big Sur 11.0), Android, Linux(Chrome >= 108.0.5354.0) and Chrome OS platforms with [hardware support](https://github.com/StaZhu/enable-chromium-hevc-hardware-decoding) Resources --------- * [Firefox support bug (WONTFIX)](https://bugzilla.mozilla.org/show_bug.cgi?format=default&id=1332136) * [Wikipedia article](https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding) * [Chrome support bug (WontFix)](https://bugs.chromium.org/p/chromium/issues/detail?id=684382) browser_support_tables SVG SMIL animation SVG SMIL animation ================== Method of using animation elements to animate SVG images | | | | --- | --- | | Spec | <https://www.w3.org/TR/SVG11/animate.html> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 (1) | 66 | | | 80 | 81 | 80 | 5 (1) | 65 | | | 79 | 80 | 79 | 4 (1) | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 (1) | | | | | | | | | | | | | | 4.2-4.3 (1) | | | | | | | | | | | | | | 4.0-4.1 (1) | | | | | | | | | | | | | | 3.2 (1) | | | | | | | | | | | | | Notes ----- 1. Partial support in older Safari versions refers to not working in HTML files or CSS background images. Bugs ---- * No events are fired at all in WebKit/Blink browsers during animation (onbegin/onrepeat/onend) [see bug](https://bugs.webkit.org/show_bug.cgi?id=63727) * Animation in SVG is not supported in inline SVG on Android browsers prior to version 4.4. Resources --------- * [Examples on SVG WOW](http://svg-wow.org/blog/category/animation/) * [MDN Web Docs - animation with SMIL](https://developer.mozilla.org/en/SVG/SVG_animation_with_SMIL) * [JS library to support SMIL in SVG](https://leunen.me/fakesmile/) * [has.js test](https://raw.github.com/phiggins42/has.js/master/detect/graphics.js#svg-smil) * [Polyfill for SMIL animate events on SVG](https://github.com/madsgraphics/SVGEventListener)
programming_docs
browser_support_tables let let === Declares a variable with block level scope | | | | --- | --- | | Spec | <https://tc39.es/ecma262/#sec-let-and-const-declarations> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (5) | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 (4) | 75 | | | 90 | 90 | 90 | 10 (4) | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 (3) | | | | 52 | 51 | | 34 (3) | | | | 51 | 50 | | 33 (3) | | | | 50 | 49 | | 32 (3) | | | | 49 | 48 (3) | | 31 (3) | | | | 48 | 47 (3) | | 30 (3) | | | | 47 | 46 (3) | | 29 (3) | | | | 46 | 45 (3) | | 28 (3) | | | | 45 | 44 (3) | | 27 (2) | | | | 44 | 43 (3) | | 26 (2) | | | | 43 (1) | 42 (3) | | 25 (2) | | | | 42 (1) | 41 (3) | | 24 (2) | | | | 41 (1) | 40 (2) | | 23 (2) | | | | 40 (1) | 39 (2) | | 22 (2) | | | | 39 (1) | 38 (2) | | 21 (2) | | | | 38 (1) | 37 (2) | | 20 (2) | | | | 37 (1) | 36 (2) | | 19 (2) | | | | 36 (1) | 35 (2) | | 18 (2) | | | | 35 (1) | 34 (2) | | 17 (2) | | | | 34 (1) | 33 (2) | | 16 (2) | | | | 33 (1) | 32 (2) | | 15 (2) | | | | 32 (1) | 31 (2) | | 12.1 | | | | 31 (1) | 30 (2) | | 12 | | | | 30 (1) | 29 (2) | | 11.6 | | | | 29 (1) | 28 (2) | | 11.5 | | | | 28 (1) | 27 (2) | | 11.1 | | | | 27 (1) | 26 (2) | | 11 | | | | 26 (1) | 25 (2) | | 10.6 | | | | 25 (1) | 24 (2) | | 10.5 | | | | 24 (1) | 23 (2) | | 10.0-10.1 | | | | 23 (1) | 22 (2) | | 9.5-9.6 | | | | 22 (1) | 21 (2) | | 9 | | | | 21 (1) | 20 (2) | | | | | | 20 (1) | 19 (2) | | | | | | 19 (1) | 18 | | | | | | 18 (1) | 17 | | | | | | 17 (1) | 16 | | | | | | 16 (1) | 15 | | | | | | 15 (1) | 14 | | | | | | 14 (1) | 13 | | | | | | 13 (1) | 12 | | | | | | 12 (1) | 11 | | | | | | 11 (1) | 10 | | | | | | 10 (1) | 9 | | | | | | 9 (1) | 8 | | | | | | 8 (1) | 7 | | | | | | 7 (1) | 6 | | | | | | 6 (1) | 5 | | | | | | 5 (1) | 4 | | | | | | 4 (1) | | | | | | | 3.6 (1) | | | | | | | 3.5 (1) | | | | | | | 3 (1) | | | | | | | 2 (1) | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 (3) | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 (4) | | | | | | | | | | | | | | 10.0-10.2 (4) | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Supports a non-standard version that can only be used in script elements with a type attribute of `application/javascript;version=1.7`. As other browsers do not support these types of `script` tags this makes support useless for cross-browser support. 2. Requires the ‘Experimental JavaScript features’ flag to be enabled 3. Only supported in strict mode 4. `let` bindings in for loops are incorrectly treated as function-scoped instead of block scoped. 5. `let` variables are not bound separately to each iteration of `for` loops Resources --------- * [Variables and Constants in ES6](https://generatedcontent.org/post/54444832868/variables-and-constants-in-es6) * [MDN Web Docs - let](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let) browser_support_tables selector list argument of :not() selector list argument of :not() ================================ Selectors Level 3 only allowed `:not()` pseudo-class to accept a single simple selector, which the element must not match any of. Thus, `:not(a, .b, [c])` or `:not(a.b[c])` did not work. Selectors Level 4 allows `:not()` to accept a list of selectors. Thus, `:not(a):not(.b):not([c])` can instead be written as `:not(a, .b, [c])` and `:not(a.b[c])` works as intended. | | | | --- | --- | | Spec | <https://www.w3.org/TR/selectors4/#negation> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [MDN Web Docs - CSS :not](https://developer.mozilla.org/en-US/docs/Web/CSS/:not) * [Chrome feature request issue](https://bugs.chromium.org/p/chromium/issues/detail?id=580628) * [Firefox feature request bug](https://bugzilla.mozilla.org/show_bug.cgi?id=933562) browser_support_tables Battery Status API Battery Status API ================== Method to provide information about the battery status of the hosting device. | | | | --- | --- | | Spec | <https://www.w3.org/TR/battery-status/> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 (1) | 41 | | 24 | | | | 41 (1) | 40 | | 23 | | | | 40 (1) | 39 | | 22 | | | | 39 (1) | 38 | | 21 | | | | 38 (1) | 37 | | 20 | | | | 37 (1) | 36 | | 19 | | | | 36 (1) | 35 | | 18 | | | | 35 (1) | 34 | | 17 | | | | 34 (1) | 33 | | 16 | | | | 33 (1) | 32 | | 15 | | | | 32 (1) | 31 | | 12.1 | | | | 31 (1) | 30 | | 12 | | | | 30 (1) | 29 | | 11.6 | | | | 29 (1) | 28 | | 11.5 | | | | 28 (1) | 27 | | 11.1 | | | | 27 (1) | 26 | | 11 | | | | 26 (1) | 25 | | 10.6 | | | | 25 (1) | 24 | | 10.5 | | | | 24 (1) | 23 | | 10.0-10.1 | | | | 23 (1) | 22 | | 9.5-9.6 | | | | 22 (1) | 21 | | 9 | | | | 21 (1) | 20 | | | | | | 20 (1) | 19 | | | | | | 19 (1) | 18 | | | | | | 18 (1) | 17 | | | | | | 17 (1) | 16 | | | | | | 16 (1) | 15 | | | | | | 15 (1,\*) | 14 | | | | | | 14 (1,\*) | 13 | | | | | | 13 (1,\*) | 12 | | | | | | 12 (1,\*) | 11 | | | | | | 11 (1,\*) | 10 | | | | | | 10 (1,\*) | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Firefox 52+ [removed access to this API due to privacy concerns.](https://bugzilla.mozilla.org/show_bug.cgi?id=1313580) 1. Partial support refers to support for the older specification's `navigator.battery` rather than `navigator.getBattery()` to access the `BatteryManager`. \* Partial support with prefix. Resources --------- * [MDN Web Docs - battery status](https://developer.mozilla.org/en-US/docs/WebAPI/Battery_Status) * [Simple demo](https://pazguille.github.io/demo-battery-api/) browser_support_tables WebGL 2.0 WebGL 2.0 ========= Next version of WebGL. Based on OpenGL ES 3.0. | | | | --- | --- | | Spec | <https://www.khronos.org/registry/webgl/specs/latest/2.0/> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 (4) | 83 | | | 98 | 98 | 98 | 14 (4) | 82 | | | 97 | 97 | 97 | 13.1 (4) | 81 | | | 96 | 96 | 96 | 13 (4) | 80 | | | 95 | 95 | 95 | 12.1 (4) | 79 | | | 94 | 94 | 94 | 12 (4) | 78 | | | 93 | 93 | 93 | 11.1 (4) | 77 | | | 92 | 92 | 92 | 11 (4) | 76 | | | 91 | 91 | 91 | 10.1 (4) | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 (3) | | 38 | | | | 55 | 54 (3) | | 37 | | | | 54 | 53 (3) | | 36 | | | | 53 | 52 (3) | | 35 | | | | 52 | 51 (3) | | 34 | | | | 51 | 50 (3) | | 33 | | | | 50 (1,5) | 49 (3) | | 32 | | | | 49 (1,5) | 48 (3) | | 31 | | | | 48 (1,5) | 47 (3) | | 30 | | | | 47 (1,5) | 46 (3) | | 29 | | | | 46 (1,5) | 45 (3) | | 28 | | | | 45 (1,5) | 44 (3) | | 27 | | | | 44 (1) | 43 (3) | | 26 | | | | 43 (1) | 42 | | 25 | | | | 42 (1) | 41 | | 24 | | | | 41 (1,2) | 40 | | 23 | | | | 40 (1,2) | 39 | | 22 | | | | 39 (1,2) | 38 | | 21 | | | | 38 (1,2) | 37 | | 20 | | | | 37 (1,2) | 36 | | 19 | | | | 36 (1,2) | 35 | | 18 | | | | 35 (1,2) | 34 | | 17 | | | | 34 (1,2) | 33 | | 16 | | | | 33 (1,2) | 32 | | 15 | | | | 32 (1,2) | 31 | | 12.1 | | | | 31 (1,2) | 30 | | 12 | | | | 30 (1,2) | 29 | | 11.6 | | | | 29 (1,2) | 28 | | 11.5 | | | | 28 (1,2) | 27 | | 11.1 | | | | 27 (1,2) | 26 | | 11 | | | | 26 (1,2) | 25 | | 10.6 | | | | 25 (1,2) | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (1,5) | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 (4) | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (4) | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (4) | | | | | | | | | 9.2 | | | | | 13.3 (4) | | | | | | | | | 8.2 | | | | | 13.2 (4) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (4) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (4) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 (4) | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled in Firefox by setting the about:config preference webgl.enable-prototype-webgl2 to true 2. WebGL2 context is accessed from "experimental-webgl2" rather than "webgl2" 3. Can be enabled in Chrome by passing the "--enable-unsafe-es3-apis" flag when starting the browser through the command line 4. Can be enabled in the "Experimental Features" developer menu 5. Enabled by default for Nightly and Dev Edition Resources --------- * [Firefox blog post](https://blog.mozilla.org/futurereleases/2015/03/03/an-early-look-at-webgl-2/) * [Getting a WebGL Implementation](https://www.khronos.org/webgl/wiki/Getting_a_WebGL_Implementation)
programming_docs
browser_support_tables Form validation Form validation =============== Method of setting required fields and field types without requiring JavaScript. This includes preventing forms from being submitted when appropriate, the `checkValidity()` method as well as support for the `:invalid`, `:valid`, and `:required` CSS pseudo-classes. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/forms.html#client-side-form-validation> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 (1) | 74 | | | 89 | 89 | 89 | 9.1 (1) | 73 | | | 88 | 88 | 88 | 9 (1) | 72 | | | 87 | 87 | 87 | 8 (1) | 71 | | | 86 | 86 | 86 | 7.1 (1) | 70 | | | 85 | 85 | 85 | 7 (1) | 69 | | | 84 | 84 | 84 | 6.1 (1) | 68 | | | 83 | 83 | 83 | 6 (1) | 67 | | | 81 | 82 | 81 | 5.1 (1) | 66 | | | 80 | 81 | 80 | 5 (1) | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all (3) | 108 | 10 | 72 | 108 | 107 | 11 (2) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (1) | | 16.1 | | 4.4.3-4.4.4 | 7 (1) | 12.1 | | | 10 (2) | | 18.0 | | | | | 16.0 | | 4.4 (1) | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 (1) | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 (1) | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 (1) | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 (1) | | | | | | | | | | | | | | 9.3 (1) | | | | | | | | | | | | | | 9.0-9.2 (1) | | | | | | | | | | | | | | 8.1-8.4 (1) | | | | | | | | | | | | | | 8 (1) | | | | | | | | | | | | | | 7.0-7.1 (1) | | | | | | | | | | | | | | 6.0-6.1 (1) | | | | | | | | | | | | | | 5.0-5.1 (1) | | | | | | | | | | | | | | 4.2-4.3 (1) | | | | | | | | | | | | | | 4.0-4.1 (1) | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Partial support refers to lack of notice when form with required fields is attempted to be submitted. 2. Partial support in IE10 mobile refers to lack of warning when blocking submission. 3. Partial support in Opera Mini refers to only supporting the CSS pseudo classes. Bugs ---- * IE10 and 11 [have a problem](https://stackoverflow.com/questions/20241415/html5-number-input-field-step-attribute-broken-in-internet-explorer-10-and-inter) validating number fields in combination with the `step` attribute and certain values * In Chrome (tested in 45) inputs marked as disabled or hidden while also marked as required are [incorrectly](https://html.spec.whatwg.org/multipage/forms.html#concept-fe-disabled) being considered for constraint validation. https://html.spec.whatwg.org/multipage/forms.html#concept-fe-disabled * [IE & Edge do not support `:valid` on `form` elements.](https://web.archive.org/web/20171210190022/https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8114184/) Firefox<51 seemed to only match `:valid` on `form`s after child element values have changed from an invalid to valid state; see [bug #1285425](https://bugzilla.mozilla.org/show_bug.cgi?id=1285425). Resources --------- * [WebPlatform Docs](https://webplatform.github.io/docs/html/attributes/required) * [WebKit Blog: HTML Interactive Form Validation](https://webkit.org/blog/7099/html-interactive-form-validation/) browser_support_tables Upgrade Insecure Requests Upgrade Insecure Requests ========================= Declare that browsers should transparently upgrade HTTP resources on a website to HTTPS. | | | | --- | --- | | Spec | <https://www.w3.org/TR/upgrade-insecure-requests/> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- The HTTP header is `Content-Security-Policy: upgrade-insecure-requests`. Alternatively, the HTML tag is `<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">`. Resources --------- * [MDN Web Docs - Upgrade Insecure Requests](https://developer.mozilla.org/en-US/docs/Web/Security/CSP/CSP_policy_directives#upgrade-insecure-requests) * [Demo Website](https://googlechrome.github.io/samples/csp-upgrade-insecure-requests/index.html) * [WebKit feature request bug](https://bugs.webkit.org/show_bug.cgi?id=143653) browser_support_tables Web SQL Database Web SQL Database ================ Method of storing data client-side, allows SQLite database queries for access and manipulation. | | | | --- | --- | | Spec | <https://www.w3.org/TR/webdatabase/> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (1) | | | | | | 110 | 110 (1) | TP | | | | | 109 | 109 (1) | 16.3 | | | 11 | 108 (1) | 108 | 108 (1) | 16.2 | 92 (1) | | 10 | 107 (1) | 107 | 107 (1) | 16.1 | 91 (1) | | 9 | 106 (1) | 106 | 106 (1) | 16.0 | 90 | | 8 | 105 (1) | 105 | 105 (1) | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 (1) | 10 | 72 (1) | 108 (1) | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- The Web SQL Database specification is no longer being maintained and support intended to be dropped in future versions. Migrate to e.g. [Web Storage](/namevalue-storage) or [IndexedDB](/?search=IndexedDB). 1. Requires a [secure context](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts) Bugs ---- * Reported to not be supported on the Samsung-based Android 4. * Is not supported from Web Workers in Chrome. Furthermore it is not supported in Third-Party Contexts since Chrome v97. Additionally it requires a [secure context](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts) starting with Chrome v105. Resources --------- * [HTML5 Doctor article](https://html5doctor.com/introducing-web-sql-databases/) * [has.js test](https://raw.github.com/phiggins42/has.js/master/detect/features.js#native-sql-db) * [Chrome platform status: Deprecate and remove WebSQL in non-secure contexts](https://chromestatus.com/feature/5175124599767040)
programming_docs
browser_support_tables CSS Counters CSS Counters ============ Method of controlling number values in generated content, using the `counter-reset` and `counter-increment` properties. | | | | --- | --- | | Spec | <https://www.w3.org/TR/CSS21/generate.html#counters> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Tutorial and information](https://onwebdev.blogspot.com/2012/02/css-counters-tutorial.html) * [MDN Web Docs - CSS Counters](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Counter_Styles/Using_CSS_counters) * [WebPlatform Docs](https://webplatform.github.io/docs/css/properties/counter-reset) browser_support_tables Shared Array Buffer Shared Array Buffer =================== Type of ArrayBuffer that can be shared across Workers. | | | | --- | --- | | Spec | <https://tc39.es/ecma262/#sec-sharedarraybuffer-objects> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (3) | | | | | | 110 (3) | 110 (3) | TP (3) | | | | | 109 (3) | 109 (3) | 16.3 (3) | | | 11 | 108 (3) | 108 (3) | 108 (3) | 16.2 (3) | 92 | | 10 | 107 (3) | 107 (3) | 107 (3) | 16.1 (3) | 91 | | 9 | 106 (3) | 106 (3) | 106 (3) | 16.0 (3) | 90 | | 8 | 105 (3) | 105 (3) | 105 (3) | 15.6 (3) | 89 | | [Show all](#) | | 7 | 104 (3) | 104 (3) | 104 (3) | 15.5 (3) | 88 | | 6 | 103 (3) | 103 (3) | 103 (3) | 15.4 (3) | 87 | | 5.5 | 102 (3) | 102 (3) | 102 (3) | 15.2-15.3 (3) | 86 | | | 101 (3) | 101 (3) | 101 (3) | 15.1 (1) | 85 | | | 100 (3) | 100 (3) | 100 (3) | 15 (1) | 84 | | | 99 (3) | 99 (3) | 99 (3) | 14.1 (1) | 83 | | | 98 (3) | 98 (3) | 98 (3) | 14 (1) | 82 | | | 97 (3) | 97 (3) | 97 (3) | 13.1 (1) | 81 | | | 96 (3) | 96 (3) | 96 (3) | 13 (1) | 80 | | | 95 (3) | 95 (3) | 95 (3) | 12.1 (1) | 79 | | | 94 (3) | 94 (3) | 94 (3) | 12 (1) | 78 | | | 93 (3) | 93 (3) | 93 (3) | 11.1 (1) | 77 | | | 92 (3) | 92 (3) | 92 (3) | 11 (1) | 76 | | | 91 (3) | 91 (3) | 91 (3) | 10.1 (1) | 75 | | | 90 | 90 (3) | 90 | 10 | 74 | | | 89 | 89 (3) | 89 | 9.1 | 73 | | | 88 | 88 (3) | 88 | 9 | 72 | | | 87 | 87 (3) | 87 | 8 | 71 | | | 86 | 86 (3) | 86 | 7.1 | 70 | | | 85 | 85 (3) | 85 | 7 | 69 | | | 84 | 84 (3) | 84 | 6.1 | 68 | | | 83 | 83 (3) | 83 | 6 | 67 | | | 81 | 82 (3) | 81 | 5.1 | 66 | | | 80 | 81 (3) | 80 | 5 | 65 | | | 79 | 80 (3) | 79 | 4 | 64 | | | 18 (1) | 79 (3) | 78 | 3.2 | 63 (1) | | | 17 (1) | 78 (1,2) | 77 | 3.1 | 62 (1) | | | 16 (1) | 77 (1,2) | 76 | | 60 (1) | | | 15 | 76 (1,2) | 75 | | 58 (1) | | | 14 | 75 (1,2) | 74 | | 57 (1) | | | 13 | 74 (1,2) | 73 | | 56 (1) | | | 12 | 73 (1) | 72 | | 55 (1) | | | | 72 (1) | 71 | | 54 (1) | | | | 71 (1) | 70 | | 53 (1) | | | | 70 (1) | 69 | | 52 (1) | | | | 69 (1) | 68 | | 51 (1) | | | | 68 (1) | 67 (1) | | 50 (1) | | | | 67 (1) | 66 (1) | | 49 (1) | | | | 66 (1) | 65 (1) | | 48 (1) | | | | 65 (1) | 64 (1) | | 47 (1) | | | | 64 (1) | 63 (1) | | 46 | | | | 63 (1) | 62 (1) | | 45 | | | | 62 (1) | 61 (1) | | 44 | | | | 61 (1) | 60 (1) | | 43 | | | | 60 (1) | 59 | | 42 | | | | 59 (1) | 58 | | 41 | | | | 58 (1) | 57 | | 40 | | | | 57 (1) | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (3) | | | | | | | | | | | | | | 16.2 (3) | all | 108 | 10 | 72 (3) | 108 (3) | 107 (3) | 11 | 13.4 | 19.0 (3) | 13.1 | 13.18 (3) | 2.5 | | 16.1 (3) | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 (3) | | | | | 16.0 (3) | | 4.4 | | 12 | | | | | 17.0 (3) | | | | | 15.6 (3) | | 4.2-4.3 | | 11.5 | | | | | 16.0 (3) | | | | | [Show all](#) | | 15.5 (3) | | 4.1 | | 11.1 | | | | | 15.0 (3) | | | | | 15.4 (3) | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 (3) | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 (1) | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 (1) | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (1) | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (1) | | | | | | | | | 9.2 | | | | | 13.3 (1) | | | | | | | | | 8.2 | | | | | 13.2 (1) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (1) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (1) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 (1) | | | | | | | | | 4 | | | | | 11.3-11.4 (1) | | | | | | | | | | | | | | 11.0-11.2 (1) | | | | | | | | | | | | | | 10.3 (1) | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Has support, but was disabled across browsers in January 2018 due to Spectre & Meltdown vulnerabilities. 2. Enabled by default in Nightly, but not in Beta/Developer/Release. 3. Requires cross-origin isolation by having [Cross-Origin-Embedder-Policy (COEP)](/mdn-http_headers_cross-origin-embedder-policy) and [Cross-Origin-Opener-Policy (COOP)](/mdn-http_headers_cross-origin-opener-policy) headers set. [Mozilla Hacks article](https://hacks.mozilla.org/2020/07/safely-reviving-shared-memory/) for context. Resources --------- * [MDN article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) * [Mozilla Hacks article on safely reviving shared memory](https://hacks.mozilla.org/2020/07/safely-reviving-shared-memory/) browser_support_tables Resize Observer Resize Observer =============== Method for observing and reacting to changes to sizes of DOM elements. | | | | --- | --- | | Spec | <https://w3c.github.io/csswg-drafts/resize-observer/> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 (1) | | | | 68 | 67 | | 50 (1) | | | | 67 | 66 | | 49 (1) | | | | 66 | 65 | | 48 (1) | | | | 65 | 64 | | 47 (1) | | | | 64 | 63 (1) | | 46 (1) | | | | 63 | 62 (1) | | 45 (1) | | | | 62 | 61 (1) | | 44 (1) | | | | 61 | 60 (1) | | 43 (1) | | | | 60 | 59 (1) | | 42 (1) | | | | 59 | 58 (1) | | 41 (1) | | | | 58 | 57 (1) | | 40 | | | | 57 | 56 (1) | | 39 | | | | 56 | 55 (1) | | 38 | | | | 55 | 54 (1) | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled via the "Experimental Web Platform Features" flag Resources --------- * [Google Developers Article](https://developers.google.com/web/updates/2016/10/resizeobserver) * [Explainer Doc](https://github.com/WICG/ResizeObserver/blob/master/explainer.md) * [Polyfill based on initial specification](https://github.com/que-etc/resize-observer-polyfill) * [Firefox implementation bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1272409) * [WebKit implementation bug](https://bugs.webkit.org/show_bug.cgi?id=157743) * [Polyfill based on latest specification which includes support for observer options](https://github.com/juggle/resize-observer) browser_support_tables JavaScript modules: dynamic import() JavaScript modules: dynamic import() ==================================== Loading JavaScript modules dynamically using the import() syntax | | | | --- | --- | | Spec | <https://tc39.es/ecma262/#sec-import-calls> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 (1) | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Support can be enabled via `javascript.options.dynamicImport` flag. See [bug 1517546](https://bugzil.la/1517546). Bugs ---- * Safari [does not honor `<base>`](https://bugs.webkit.org/show_bug.cgi?id=201692) when `moduleName` (specifier) is relative (starts with `./`) in inline scripts Resources --------- * [Counterpart ECMAScript specification for import() syntax](https://tc39.es/ecma262/#sec-import-calls) * [Blog post: Native ECMAScript modules - dynamic import()](https://hospodarets.com/native-ecmascript-modules-dynamic-import) * [Dynamic import()](https://developers.google.com/web/updates/2017/11/dynamic-import) * [Firefox implementation bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1342012) * [Integration with the HTML specification](https://html.spec.whatwg.org/multipage/webappapis.html#integration-with-the-javascript-module-system)
programming_docs
browser_support_tables document.scrollingElement document.scrollingElement ========================= `document.scrollingElement` refers to the element that scrolls the document. | | | | --- | --- | | Spec | <https://w3c.github.io/csswg-drafts/cssom-view/#dom-document-scrollingelement> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Polyfill](https://github.com/mathiasbynens/document.scrollingElement) * [MDN on scrollingElement](https://developer.mozilla.org/en-US/docs/Web/API/Document/scrollingElement) browser_support_tables JPEG 2000 image format JPEG 2000 image format ====================== JPEG 2000 was built to supersede the original JPEG format by having better compression and more features. [WebP](/webp), [AVIF](/avif) and [JPEG XL](/jpegxl) are all designed to supersede JPEG 2000. | | | | --- | --- | | Spec | <https://www.itu.int/rec/T-REC-T.800-200208-I> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 (1) | 66 | | | 80 | 81 | 80 | 5 (1) | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Not supported by Safari for Windows Resources --------- * [Wikipedia article](https://en.wikipedia.org/wiki/JPEG_2000) browser_support_tables Media Queries: resolution feature Media Queries: resolution feature ================================= Allows a media query to be set based on the device pixels used per CSS unit. While the standard uses `min`/`max-resolution` for this, some browsers support the older non-standard `device-pixel-ratio` media query. | | | | --- | --- | | Spec | <https://www.w3.org/TR/mediaqueries-4/#resolution> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (1) | 108 | 108 | 108 | 16.2 | 92 | | 10 (1) | 107 | 107 | 107 | 16.1 | 91 | | 9 (1) | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 (3,\*) | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 (3,\*) | 88 | | 6 | 103 | 103 | 103 | 15.4 (3,\*) | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 (3,\*) | 86 | | | 101 | 101 | 101 | 15.1 (3,\*) | 85 | | | 100 | 100 | 100 | 15 (3,\*) | 84 | | | 99 | 99 | 99 | 14.1 (3,\*) | 83 | | | 98 | 98 | 98 | 14 (3,\*) | 82 | | | 97 | 97 | 97 | 13.1 (3,\*) | 81 | | | 96 | 96 | 96 | 13 (3,\*) | 80 | | | 95 | 95 | 95 | 12.1 (3,\*) | 79 | | | 94 | 94 | 94 | 12 (3,\*) | 78 | | | 93 | 93 | 93 | 11.1 (3,\*) | 77 | | | 92 | 92 | 92 | 11 (3,\*) | 76 | | | 91 | 91 | 91 | 10.1 (3,\*) | 75 | | | 90 | 90 | 90 | 10 (3,\*) | 74 | | | 89 | 89 | 89 | 9.1 (3,\*) | 73 | | | 88 | 88 | 88 | 9 (3,\*) | 72 | | | 87 | 87 | 87 | 8 (3,\*) | 71 | | | 86 | 86 | 86 | 7.1 (3,\*) | 70 | | | 85 | 85 | 85 | 7 (3,\*) | 69 | | | 84 | 84 | 84 | 6.1 (3,\*) | 68 | | | 83 | 83 | 83 | 6 (3,\*) | 67 | | | 81 | 82 | 81 | 5.1 (3,\*) | 66 | | | 80 | 81 | 80 | 5 (3,\*) | 65 | | | 79 | 80 | 79 | 4 (3,\*) | 64 | | | 18 (4) | 79 | 78 | 3.2 | 63 | | | 17 (4) | 78 | 77 | 3.1 | 62 | | | 16 (4) | 77 | 76 | | 60 | | | 15 (4) | 76 | 75 | | 58 | | | 14 (4) | 75 | 74 | | 57 | | | 13 (4) | 74 | 73 | | 56 | | | 12 (4) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 (4) | | | | 71 | 70 | | 53 (4) | | | | 70 | 69 | | 52 (4) | | | | 69 | 68 | | 51 (4) | | | | 68 | 67 (4) | | 50 (4) | | | | 67 | 66 (4) | | 49 (4) | | | | 66 | 65 (4) | | 48 (4) | | | | 65 | 64 (4) | | 47 (4) | | | | 64 | 63 (4) | | 46 (4) | | | | 63 | 62 (4) | | 45 (4) | | | | 62 | 61 (4) | | 44 (4) | | | | 61 (4) | 60 (4) | | 43 (4) | | | | 60 (4) | 59 (4) | | 42 (4) | | | | 59 (4) | 58 (4) | | 41 (4) | | | | 58 (4) | 57 (4) | | 40 (4) | | | | 57 (4) | 56 (4) | | 39 (4) | | | | 56 (4) | 55 (4) | | 38 (4) | | | | 55 (4) | 54 (4) | | 37 (4) | | | | 54 (4) | 53 (4) | | 36 (4) | | | | 53 (4) | 52 (4) | | 35 (4) | | | | 52 (4) | 51 (4) | | 34 (4) | | | | 51 (4) | 50 (4) | | 33 (4) | | | | 50 (4) | 49 (4) | | 32 (4) | | | | 49 (4) | 48 (4) | | 31 (4) | | | | 48 (4) | 47 (4) | | 30 (4) | | | | 47 (4) | 46 (4) | | 29 (4) | | | | 46 (4) | 45 (4) | | 28 (4) | | | | 45 (4) | 44 (4) | | 27 (4) | | | | 44 (4) | 43 (4) | | 26 (4) | | | | 43 (4) | 42 (4) | | 25 (4) | | | | 42 (4) | 41 (4) | | 24 (4) | | | | 41 (4) | 40 (4) | | 23 (4) | | | | 40 (4) | 39 (4) | | 22 (4) | | | | 39 (4) | 38 (4) | | 21 (4) | | | | 38 (4) | 37 (4) | | 20 (4) | | | | 37 (4) | 36 (4) | | 19 (4) | | | | 36 (4) | 35 (4) | | 18 (4) | | | | 35 (4) | 34 (4) | | 17 (4) | | | | 34 (4) | 33 (4) | | 16 (4) | | | | 33 (4) | 32 (4) | | 15 (4) | | | | 32 (4) | 31 (4) | | 12.1 | | | | 31 (4) | 30 (4) | | 12 (3,\*) | | | | 30 (4) | 29 (4) | | 11.6 (3,\*) | | | | 29 (4) | 28 (3,\*) | | 11.5 (3,\*) | | | | 28 (4) | 27 (3,\*) | | 11.1 (3,\*) | | | | 27 (4) | 26 (3,\*) | | 11 (3,\*) | | | | 26 (4) | 25 (3,\*) | | 10.6 (3,\*) | | | | 25 (4) | 24 (3,\*) | | 10.5 (3,\*) | | | | 24 (4) | 23 (3,\*) | | 10.0-10.1 (3,\*) | | | | 23 (4) | 22 (3,\*) | | 9.5-9.6 (3,\*) | | | | 22 (4) | 21 (3,\*) | | 9 | | | | 21 (4) | 20 (3,\*) | | | | | | 20 (4) | 19 (3,\*) | | | | | | 19 (4) | 18 (3,\*) | | | | | | 18 (4) | 17 (3,\*) | | | | | | 17 (4) | 16 (3,\*) | | | | | | 16 (4) | 15 (3,\*) | | | | | | 15 (2) | 14 (3,\*) | | | | | | 14 (2) | 13 (3,\*) | | | | | | 13 (2) | 12 (3,\*) | | | | | | 12 (2) | 11 (3,\*) | | | | | | 11 (2) | 10 (3,\*) | | | | | | 10 (2) | 9 (3,\*) | | | | | | 9 (2) | 8 (3,\*) | | | | | | 8 (2) | 7 (3,\*) | | | | | | 7 (2) | 6 (3,\*) | | | | | | 6 (2) | 5 (3,\*) | | | | | | 5 (2) | 4 (3,\*) | | | | | | 4 (2) | | | | | | | 3.6 (2) | | | | | | | 3.5 (2) | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all (1) | 108 | 10 (3,\*) | 72 | 108 | 107 | 11 (1) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 (4) | 7 (3,\*) | 12.1 | | | 10 (1) | | 18.0 | | | | | 16.0 | | 4.4 (4) | | 12 (3,\*) | | | | | 17.0 | | | | | 15.6 (3,\*) | | 4.2-4.3 (3,\*) | | 11.5 (3,\*) | | | | | 16.0 | | | | | [Show all](#) | | 15.5 (3,\*) | | 4.1 (3,\*) | | 11.1 (3,\*) | | | | | 15.0 | | | | | 15.4 (3,\*) | | 4 (3,\*) | | 11 (3,\*) | | | | | 14.0 | | | | | 15.2-15.3 (3,\*) | | 3 (3,\*) | | 10 (3,\*) | | | | | 13.0 | | | | | 15.0-15.1 (3,\*) | | 2.3 (3,\*) | | | | | | | 12.0 | | | | | 14.5-14.8 (3,\*) | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (3,\*) | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (3,\*) | | | | | | | | | 9.2 (4) | | | | | 13.3 (3,\*) | | | | | | | | | 8.2 (4) | | | | | 13.2 (3,\*) | | | | | | | | | 7.2-7.4 (4) | | | | | 13.0-13.1 (3,\*) | | | | | | | | | 6.2-6.4 (4) | | | | | 12.2-12.5 (3,\*) | | | | | | | | | 5.0-5.4 (4) | | | | | 12.0-12.1 (3,\*) | | | | | | | | | 4 (4) | | | | | 11.3-11.4 (3,\*) | | | | | | | | | | | | | | 11.0-11.2 (3,\*) | | | | | | | | | | | | | | 10.3 (3,\*) | | | | | | | | | | | | | | 10.0-10.2 (3,\*) | | | | | | | | | | | | | | 9.3 (3,\*) | | | | | | | | | | | | | | 9.0-9.2 (3,\*) | | | | | | | | | | | | | | 8.1-8.4 (3,\*) | | | | | | | | | | | | | | 8 (3,\*) | | | | | | | | | | | | | | 7.0-7.1 (3,\*) | | | | | | | | | | | | | | 6.0-6.1 (3,\*) | | | | | | | | | | | | | | 5.0-5.1 (3,\*) | | | | | | | | | | | | | | 4.2-4.3 (3,\*) | | | | | | | | | | | | | | 4.0-4.1 (3,\*) | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Supports the `dpi` unit, but does not support `dppx` or `dpcm` units. 2. Firefox before 16 supports only `dpi` unit, but you can set `2dppx` per `min--moz-device-pixel-ratio: 2`. 3. Supports the non-standard `min`/`max-device-pixel-ratio`. 4. Does not support `x` unit (alias for `dppx` unit), e.g: `@media (min-resolution: 2x) { }`. \* Partial support with prefix. Bugs ---- * Microsoft Edge Legacy (v18 and below) has a bug where `min-resolution` less than `1dpcm` [is ignored](https://jsfiddle.net/behmjd5t/). Resources --------- * [How to unprefix -webkit-device-pixel-ratio](https://www.w3.org/blog/CSS/2012/06/14/unprefix-webkit-device-pixel-ratio/) * [WebKit Bug 78087: Implement the 'resolution' media query](https://bugs.webkit.org/show_bug.cgi?id=78087) * [WHATWG Compatibility Standard: -webkit-device-pixel-ratio](https://compat.spec.whatwg.org/#css-media-queries-webkit-device-pixel-ratio) * [MDN Web Docs - CSS @media resolution](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/resolution) * [CSS Values and Units Module Level 4 add the `x` unit as an alias for `dppx`.](https://drafts.csswg.org/css-values/#dppx) * [Chrome support 'x' as a resolution unit.](https://chromestatus.com/feature/5150549246738432) * [Firefox support 'x' as a resolution unit.](https://bugzilla.mozilla.org/show_bug.cgi?id=1460655)
programming_docs
browser_support_tables CSS Regions CSS Regions =========== Method of flowing content into multiple elements, allowing magazine-like layouts. While once supported in WebKit-based browsers and Internet Explorer, implementing the feature is no longer being pursued by any browser. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css3-regions/> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (1,2,\*) | 108 | 108 | 108 | 16.2 | 92 | | 10 (1,2,\*) | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 (\*) | 76 | | | 91 | 91 | 91 | 10.1 (\*) | 75 | | | 90 | 90 | 90 | 10 (\*) | 74 | | | 89 | 89 | 89 | 9.1 (\*) | 73 | | | 88 | 88 | 88 | 9 (\*) | 72 | | | 87 | 87 | 87 | 8 (\*) | 71 | | | 86 | 86 | 86 | 7.1 (\*) | 70 | | | 85 | 85 | 85 | 7 (\*) | 69 | | | 84 | 84 | 84 | 6.1 (\*) | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 (1,2,\*) | 79 | 78 | 3.2 | 63 | | | 17 (1,2,\*) | 78 | 77 | 3.1 | 62 | | | 16 (1,2,\*) | 77 | 76 | | 60 | | | 15 (1,2,\*) | 76 | 75 | | 58 | | | 14 (1,2,\*) | 75 | 74 | | 57 | | | 13 (1,2,\*) | 74 | 73 | | 56 | | | 12 (1,2,\*) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 (\*) | | | | | | 18 | 17 (\*) | | | | | | 17 | 16 (\*) | | | | | | 16 | 15 (\*) | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 (1,2,\*) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 (1,2,\*) | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 (\*) | | | | | | | | | | | | | | 10.3 (\*) | | | | | | | | | | | | | | 10.0-10.2 (\*) | | | | | | | | | | | | | | 9.3 (\*) | | | | | | | | | | | | | | 9.0-9.2 (\*) | | | | | | | | | | | | | | 8.1-8.4 (\*) | | | | | | | | | | | | | | 8 (\*) | | | | | | | | | | | | | | 7.0-7.1 (\*) | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Support is limited to using an iframe as a content source with the `-ms-flow-into: flow_name;` and `-ms-flow-from: flow_name;` syntax. 2. Partial support refers to not supporting the `region-fragment` property. \* Partial support with prefix. Resources --------- * [Adobe demos and samples](https://web.archive.org/web/20121027050852/http://html.adobe.com:80/webstandards/cssregions/) * [IE10 developer guide info](https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/dev-guides/hh673537(v=vs.85)) * [Firefox feature request bug](https://bugzilla.mozilla.org/show_bug.cgi?id=674802) * [Beginner's guide to CSS Regions](https://www.sitepoint.com/a-beginners-guide-css-regions/) * [Discussion on removal in Blink](https://groups.google.com/a/chromium.org/g/blink-dev/c/kTktlHPJn4Q/m/YrnfLxeMO7IJ) browser_support_tables HTML5 semantic elements HTML5 semantic elements ======================= HTML5 offers some new elements, primarily for semantic purposes. The elements include: `section`, `article`, `aside`, `header`, `footer`, `nav`, `figure`, `figcaption`, `time`, `mark` & `main`. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/semantics.html#sections> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (2) | 108 | 108 | 108 | 16.2 | 92 | | 10 (2) | 107 | 107 | 107 | 16.1 | 91 | | 9 (2) | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 (2) | 67 | | | 81 | 82 | 81 | 5.1 (2) | 66 | | | 80 | 81 | 80 | 5 (2) | 65 | | | 79 | 80 | 79 | 4 (1) | 64 | | | 18 | 79 | 78 | 3.2 (1) | 63 | | | 17 | 78 | 77 | 3.1 (1) | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 (2) | | | | 31 | 30 | | 12 (2) | | | | 30 | 29 | | 11.6 (2) | | | | 29 | 28 | | 11.5 (2) | | | | 28 | 27 | | 11.1 (2) | | | | 27 | 26 | | 11 (1) | | | | 26 | 25 (2) | | 10.6 (1) | | | | 25 | 24 (2) | | 10.5 (1) | | | | 24 | 23 (2) | | 10.0-10.1 (1) | | | | 23 | 22 (2) | | 9.5-9.6 (1) | | | | 22 | 21 (2) | | 9 (1) | | | | 21 | 20 (2) | | | | | | 20 (2) | 19 (2) | | | | | | 19 (2) | 18 (2) | | | | | | 18 (2) | 17 (2) | | | | | | 17 (2) | 16 (2) | | | | | | 16 (2) | 15 (2) | | | | | | 15 (2) | 14 (2) | | | | | | 14 (2) | 13 (2) | | | | | | 13 (2) | 12 (2) | | | | | | 12 (2) | 11 (2) | | | | | | 11 (2) | 10 (2) | | | | | | 10 (2) | 9 (2) | | | | | | 9 (2) | 8 (2) | | | | | | 8 (2) | 7 (2) | | | | | | 7 (2) | 6 (2) | | | | | | 6 (2) | 5 (1) | | | | | | 5 (2) | 4 (1) | | | | | | 4 (2) | | | | | | | 3.6 (1) | | | | | | | 3.5 (1) | | | | | | | 3 (1) | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all (1) | 108 | 10 (2) | 72 | 108 | 107 | 11 (2) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 (2) | 12.1 (2) | | | 10 (2) | | 18.0 | | | | | 16.0 | | 4.4 | | 12 (2) | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 (2) | | 11.5 (2) | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 (2) | | 11.1 (2) | | | | | 15.0 | | | | | 15.4 | | 4 (2) | | 11 (2) | | | | | 14.0 | | | | | 15.2-15.3 | | 3 (2) | | 10 (1) | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 (2) | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 (2) | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 (1) | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 (2) | | | | | | | | | | | | | | 5.0-5.1 (2) | | | | | | | | | | | | | | 4.2-4.3 (2) | | | | | | | | | | | | | | 4.0-4.1 (2) | | | | | | | | | | | | | | 3.2 (1) | | | | | | | | | | | | | Notes ----- 1. Partial support refers to missing the default styling, as technically the elements are considered "[unknown](https://developer.mozilla.org/en-US/docs/Web/API/HTMLUnknownElement)". This is easily taken care of by manually setting the default `display` value for each tag. 2. Partial support refers to only the `<main>` element (added later to the spec) being "unknown", though it can still be used and styled. Bugs ---- * While the `time` and `data` elements can be used and work fine in all browsers, currently only Firefox and Edge 14+ recognize them officially as `HTMLTimeElement` and `HTMLDataElement` objects. Resources --------- * [Workaround for IE](https://blog.whatwg.org/supporting-new-elements-in-ie) * [Alternate workaround](https://blog.whatwg.org/styling-ie-noscript) * [has.js test](https://raw.github.com/phiggins42/has.js/master/detect/dom.js#dom-html5-elements) * [Chrome Platform Status: `` element](https://www.chromestatus.com/feature/5633937149788160) browser_support_tables XMLHttpRequest advanced features XMLHttpRequest advanced features ================================ Adds more functionality to XHR (aka AJAX) requests like file uploads, transfer progress information and the ability to send form data. Previously known as [XMLHttpRequest Level 2](https://www.w3.org/TR/2012/WD-XMLHttpRequest-20120117/), these features now appear simply in the XMLHttpRequest spec. | | | | --- | --- | | Spec | <https://xhr.spec.whatwg.org/> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (1) | 108 | 108 | 108 | 16.2 | 92 | | 10 (1) | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 (1) | 69 | | | 84 | 84 | 84 | 6.1 (1) | 68 | | | 83 | 83 | 83 | 6 (1,2) | 67 | | | 81 | 82 | 81 | 5.1 (1,2) | 66 | | | 80 | 81 | 80 | 5 (1,2) | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 (1) | | | | 34 | 33 | | 16 (1) | | | | 33 | 32 | | 15 (1) | | | | 32 | 31 | | 12.1 | | | | 31 | 30 (1) | | 12 | | | | 30 | 29 (1) | | 11.6 | | | | 29 | 28 (1,2) | | 11.5 | | | | 28 | 27 (1,2) | | 11.1 | | | | 27 | 26 (1,2) | | 11 | | | | 26 | 25 (1,2) | | 10.6 | | | | 25 | 24 (1,2) | | 10.5 | | | | 24 | 23 (1,2) | | 10.0-10.1 | | | | 23 | 22 (1,2) | | 9.5-9.6 | | | | 22 | 21 (1,2) | | 9 | | | | 21 | 20 (1,2) | | | | | | 20 | 19 (1,2) | | | | | | 19 | 18 (1,2) | | | | | | 18 | 17 (1,2) | | | | | | 17 | 16 (1,2) | | | | | | 16 | 15 (1,2) | | | | | | 15 | 14 (1,2) | | | | | | 14 | 13 (1,2) | | | | | | 13 | 12 (1,2) | | | | | | 12 | 11 (1,2) | | | | | | 11 (2) | 10 (1,2) | | | | | | 10 (2) | 9 (1,2) | | | | | | 9 (1,2) | 8 (1,2) | | | | | | 8 (1,2) | 7 (1,2) | | | | | | 7 (1,2) | 6 | | | | | | 6 (1,2) | 5 | | | | | | 5 (1,2,3) | 4 | | | | | | 4 (1,2,3) | | | | | | | 3.6 (1,2,3) | | | | | | | 3.5 (1,2,3) | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 (1) | 72 | 108 | 107 | 11 (1) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 (1,2) | 12.1 | | | 10 (1) | | 18.0 | | | | | 16.0 | | 4.4 (1,2) | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 (1,2,3) | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 (1,2,3) | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 (1,2,3) | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 (1,2,3) | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 (1) | | | | | | | | | | | | | | 6.0-6.1 (1,2) | | | | | | | | | | | | | | 5.0-5.1 (1,2) | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Partial support refers to not supporting `json` as `responseType` 2. Partial support refers to not supporting `.timeout` and `.ontimeout` 3. Partial support refers to not supporting `blob` as `responseType` Bugs ---- * Firefox 3.5 and 3.6 partial support refers to only including support for the progress event. * WebKit versions 535 and older (r103502) do not implement the onloadend event * IE10 and 11 do not support synchronous requests, with support being phased out in other browsers too. This is due to [detrimental effects](https://xhr.spec.whatwg.org/#sync-warning) resulting from making them. * The "progress" event is reported to not work in Chrome for iOS * In Internet Explorer the `timeout` property may only be set after calling `open` and before calling `send`. Resources --------- * [MDN Web Docs - FormData](https://developer.mozilla.org/en/XMLHttpRequest/FormData) * [Polyfill for FormData object](https://github.com/jimmywarting/FormData) * [WebPlatform Docs](https://webplatform.github.io/docs/apis/xhr/XMLHttpRequest)
programming_docs
browser_support_tables Audio element Audio element ============= Method of playing sound on webpages (without requiring a plug-in). Includes support for the following media properties: `currentSrc`, `currentTime`, `paused`, `playbackRate`, `buffered`, `duration`, `played`, `seekable`, `ended`, `autoplay`, `loop`, `controls`, `volume` & `muted` | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/embedded-content.html#the-audio-element> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 (1) | 18 | | | | | | 18 (1) | 17 | | | | | | 17 (1) | 16 | | | | | | 16 (1) | 15 | | | | | | 15 (1) | 14 | | | | | | 14 (1) | 13 | | | | | | 13 (1) | 12 | | | | | | 12 (1) | 11 | | | | | | 11 (1) | 10 | | | | | | 10 (1) | 9 | | | | | | 9 (1) | 8 | | | | | | 8 (1) | 7 | | | | | | 7 (1) | 6 | | | | | | 6 (1) | 5 | | | | | | 5 (1) | 4 | | | | | | 4 (1) | | | | | | | 3.6 (1) | | | | | | | 3.5 (1) | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Old Firefox versions were missing support for some properties: `loop` was added in v11, `played` in v15, `playbackRate` in v20. Bugs ---- * Volume is read-only on iOS. * [iOS](https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html) and [Chrome on Android](https://code.google.com/p/chromium/issues/detail?id=178297) do not support autoplay as advised by the specification. * On iOS the [`ended` event is not fired](https://bugs.webkit.org/show_bug.cgi?id=173332) when the screen is off or the browser is in the background (meaning that e.g. `src` cannot be changed). Resources --------- * [HTML5 Doctor article](https://html5doctor.com/native-audio-in-the-browser/) * [Detailed article on video/audio elements](https://dev.opera.com/articles/everything-you-need-to-know-html5-video-audio/) * [Demos of audio player that uses the audio element](https://www.jplayer.org/latest/demos/) * [Detailed article on support](https://24ways.org/2010/the-state-of-html5-audio) * [has.js test](https://raw.github.com/phiggins42/has.js/master/detect/audio.js#audio) * [WebPlatform Docs](https://webplatform.github.io/docs/html/elements/audio) * [The State of HTML5 Audio](https://www.phoboslab.org/log/2011/03/the-state-of-html5-audio) browser_support_tables Import maps Import maps =========== Import maps allows control over what URLs get fetched by JavaScript `import` statements and `import()` expressions. | | | | --- | --- | | Spec | <https://wicg.github.io/import-maps/> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 (2) | 107 | 16.1 | 91 | | 9 | 106 | 106 (2) | 106 | 16.0 | 90 | | 8 | 105 | 105 (2) | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 (2) | 104 | 15.5 | 88 | | 6 | 103 | 103 (2) | 103 | 15.4 | 87 | | 5.5 | 102 | 102 (2) | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 (1) | | | 90 | 90 | 90 | 10 | 74 (1) | | | 89 | 89 | 89 | 9.1 | 73 (1) | | | 88 (1) | 88 | 88 (1) | 9 | 72 (1) | | | 87 (1) | 87 | 87 (1) | 8 | 71 (1) | | | 86 (1) | 86 | 86 (1) | 7.1 | 70 (1) | | | 85 (1) | 85 | 85 (1) | 7 | 69 (1) | | | 84 (1) | 84 | 84 (1) | 6.1 | 68 (1) | | | 83 (1) | 83 | 83 (1) | 6 | 67 (1) | | | 81 (1) | 82 | 81 (1) | 5.1 | 66 (1) | | | 80 (1) | 81 | 80 (1) | 5 | 65 (1) | | | 79 (1) | 80 | 79 (1) | 4 | 64 (1) | | | 18 | 79 | 78 (1) | 3.2 | 63 (1) | | | 17 | 78 | 77 (1) | 3.1 | 62 (1) | | | 16 | 77 | 76 (1) | | 60 | | | 15 | 76 | 75 (1) | | 58 | | | 14 | 75 | 74 (1) | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled via the "Experimental Web Platform features" flag at `about:flags`. 2. Can be enabled via the `dom.importMaps.enabled` pref in `about:config`. Resources --------- * [Proposal information](https://github.com/WICG/import-maps#readme) * [Using ES modules in browsers with import-maps](https://blog.logrocket.com/es-modules-in-browsers-with-import-maps/) * [Firefox feature request bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1688879) * [WebKit feature request bug](https://bugs.webkit.org/show_bug.cgi?id=220823) browser_support_tables Arrow functions Arrow functions =============== Function shorthand using `=>` syntax and lexical `this` binding. | | | | --- | --- | | Spec | <https://tc39.es/ecma262/#sec-arrow-function-definitions> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [ECMAScript 6 features: Arrows](https://github.com/lukehoban/es6features#arrows) * [MDN Web Docs - Arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions)
programming_docs
browser_support_tables Object RTC (ORTC) API for WebRTC Object RTC (ORTC) API for WebRTC ================================ Enables mobile endpoints to talk to servers and web browsers with Real-Time Communications (RTC) capabilities via native and simple JavaScript APIs | | | | --- | --- | | Spec | <https://www.w3.org/community/ortc/> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 (1) | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- ORTC is often dubbed WebRTC 1.1. It is possible to make ORTC communicate with WebRTC 1.0 endpoints. See [WebRTC 1.0](https://caniuse.com/#feat=rtcpeerconnection) for support details for that API. Resources --------- * [Related blog posts by Microsoft](https://blogs.windows.com/msedgedev/tag/object-rtc/) browser_support_tables DOMMatrix DOMMatrix ========= The `DOMMatrix` interface represents 4x4 matrices, suitable for 2D and 3D operations. Supersedes the `WebKitCSSMatrix` and `SVGMatrix` interfaces. | | | | --- | --- | | Spec | <https://drafts.fxtf.org/geometry/#dommatrix> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (4) | | | | | | 110 (4) | 110 (4) | TP (4) | | | | | 109 (4) | 109 (4) | 16.3 (4) | | | 11 (1) | 108 (4) | 108 (4) | 108 (4) | 16.2 (4) | 92 (4) | | 10 (1) | 107 (4) | 107 (4) | 107 (4) | 16.1 (4) | 91 (4) | | 9 | 106 (4) | 106 (4) | 106 (4) | 16.0 (4) | 90 (4) | | 8 | 105 (4) | 105 (4) | 105 (4) | 15.6 (4) | 89 (4) | | [Show all](#) | | 7 | 104 (4) | 104 (4) | 104 (4) | 15.5 (4) | 88 (4) | | 6 | 103 (4) | 103 (4) | 103 (4) | 15.4 (4) | 87 (4) | | 5.5 | 102 (4) | 102 (4) | 102 (4) | 15.2-15.3 (4) | 86 (4) | | | 101 (4) | 101 (4) | 101 (4) | 15.1 (4) | 85 (4) | | | 100 (4) | 100 (4) | 100 (4) | 15 (4) | 84 (4) | | | 99 (4) | 99 (4) | 99 (4) | 14.1 (4) | 83 (4) | | | 98 (4) | 98 (4) | 98 (4) | 14 (4) | 82 (4) | | | 97 (4) | 97 (4) | 97 (4) | 13.1 (4) | 81 (4) | | | 96 (4) | 96 (4) | 96 (4) | 13 (4) | 80 (4) | | | 95 (4) | 95 (4) | 95 (4) | 12.1 (4) | 79 (4) | | | 94 (4) | 94 (4) | 94 (4) | 12 (4) | 78 (4) | | | 93 (4) | 93 (4) | 93 (4) | 11.1 (4) | 77 (4) | | | 92 (4) | 92 (4) | 92 (4) | 11 (4) | 76 (4) | | | 91 (4) | 91 (4) | 91 (4) | 10.1 (1) | 75 (4) | | | 90 (4) | 90 (4) | 90 (4) | 10 (1) | 74 (4) | | | 89 (4) | 89 (4) | 89 (4) | 9.1 (1) | 73 (4) | | | 88 (4) | 88 (4) | 88 (4) | 9 (1) | 72 (4) | | | 87 (4) | 87 (4) | 87 (4) | 8 (1) | 71 (4) | | | 86 (4) | 86 (4) | 86 (4) | 7.1 (1) | 70 (4) | | | 85 (4) | 85 (4) | 85 (4) | 7 (1) | 69 (4) | | | 84 (4) | 84 (4) | 84 (4) | 6.1 (1) | 68 (4) | | | 83 (4) | 83 (4) | 83 (4) | 6 (1) | 67 (4) | | | 81 (4) | 82 (4) | 81 (4) | 5.1 (1) | 66 (4) | | | 80 (4) | 81 (4) | 80 (4) | 5 (1) | 65 (4) | | | 79 (4) | 80 (4) | 79 (4) | 4 | 64 (4) | | | 18 (1) | 79 (4) | 78 (4) | 3.2 | 63 (4) | | | 17 (1) | 78 (4) | 77 (4) | 3.1 | 62 (4) | | | 16 (1) | 77 (4) | 76 (4) | | 60 (4) | | | 15 (1) | 76 (4) | 75 (4) | | 58 (4) | | | 14 (1) | 75 (4) | 74 (4) | | 57 (4) | | | 13 (1) | 74 (4) | 73 (4) | | 56 (4) | | | 12 (1) | 73 (4) | 72 (4) | | 55 (4) | | | | 72 (4) | 71 (4) | | 54 (4) | | | | 71 (4) | 70 (4) | | 53 (4) | | | | 70 (4) | 69 (4) | | 52 (4) | | | | 69 (4) | 68 (4) | | 51 (4) | | | | 68 (4,5) | 67 (4) | | 50 (4) | | | | 67 (4,5) | 66 (4) | | 49 (4) | | | | 66 (4,5) | 65 (4) | | 48 (4) | | | | 65 (4,5) | 64 (4) | | 47 (1) | | | | 64 (4,5) | 63 (4) | | 46 (1) | | | | 63 (4,5) | 62 (4) | | 45 (1) | | | | 62 (4,5) | 61 (4) | | 44 (1) | | | | 61 (4,5) | 60 (1) | | 43 (1) | | | | 60 (4,5) | 59 (1) | | 42 (1) | | | | 59 (4,5) | 58 (1) | | 41 (1) | | | | 58 (4,5) | 57 (1) | | 40 (1) | | | | 57 (4,5) | 56 (1) | | 39 (1) | | | | 56 (4,5) | 55 (1) | | 38 (1) | | | | 55 (4,5) | 54 (1) | | 37 (1) | | | | 54 (4,5) | 53 (1) | | 36 (1) | | | | 53 (4,5) | 52 (1) | | 35 (1) | | | | 52 (4,5) | 51 (1) | | 34 (1) | | | | 51 (4,5) | 50 (1) | | 33 (1) | | | | 50 (4,5) | 49 (1) | | 32 (1) | | | | 49 (4,5) | 48 (1) | | 31 (1) | | | | 48 (3,5) | 47 (1) | | 30 (1) | | | | 47 (3,5) | 46 (1) | | 29 (1) | | | | 46 (3,5) | 45 (1) | | 28 (1) | | | | 45 (3,5) | 44 (1) | | 27 (1) | | | | 44 (3,5) | 43 (1) | | 26 (1) | | | | 43 (3,5) | 42 (1) | | 25 (1) | | | | 42 (3,5) | 41 (1) | | 24 (1) | | | | 41 (3,5) | 40 (1) | | 23 (1) | | | | 40 (3,5) | 39 (1) | | 22 (1) | | | | 39 (3,5) | 38 (1) | | 21 (1) | | | | 38 (3,5) | 37 (1) | | 20 (1) | | | | 37 (3,5) | 36 (1) | | 19 (1) | | | | 36 (3,5) | 35 (1) | | 18 (1) | | | | 35 (3,5) | 34 (1) | | 17 (1) | | | | 34 (3,5) | 33 (1) | | 16 (1) | | | | 33 (3,5) | 32 (1) | | 15 (1) | | | | 32 | 31 (1) | | 12.1 | | | | 31 | 30 (1) | | 12 | | | | 30 | 29 (1) | | 11.6 | | | | 29 | 28 (1) | | 11.5 | | | | 28 | 27 (1) | | 11.1 | | | | 27 | 26 (1) | | 11 | | | | 26 | 25 (1) | | 10.6 | | | | 25 | 24 (1) | | 10.5 | | | | 24 | 23 (1) | | 10.0-10.1 | | | | 23 | 22 (1) | | 9.5-9.6 | | | | 22 | 21 (1) | | 9 | | | | 21 | 20 (1) | | | | | | 20 | 19 (1) | | | | | | 19 | 18 (1) | | | | | | 18 | 17 (1) | | | | | | 17 | 16 (1) | | | | | | 16 | 15 (1) | | | | | | 15 | 14 (1) | | | | | | 14 | 13 (1) | | | | | | 13 | 12 (1) | | | | | | 12 | 11 (1) | | | | | | 11 | 10 (1) | | | | | | 10 | 9 (1) | | | | | | 9 | 8 (1,2) | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (1) | | | | | | | | | | | | | | 16.2 (1) | all | 108 (4) | 10 (1) | 72 (4) | 108 (4) | 107 (4) | 11 (1) | 13.4 (4) | 19.0 (1) | 13.1 (4) | 13.18 (4) | 2.5 (3,5) | | 16.1 (1) | | 4.4.3-4.4.4 (1) | 7 | 12.1 | | | 10 (1) | | 18.0 (1) | | | | | 16.0 (1) | | 4.4 (1) | | 12 | | | | | 17.0 (1) | | | | | 15.6 (1) | | 4.2-4.3 (1) | | 11.5 | | | | | 16.0 (1) | | | | | [Show all](#) | | 15.5 (1) | | 4.1 (1) | | 11.1 | | | | | 15.0 (1) | | | | | 15.4 (1) | | 4 (1) | | 11 | | | | | 14.0 (1) | | | | | 15.2-15.3 (1) | | 3 (2,\*) | | 10 | | | | | 13.0 (1) | | | | | 15.0-15.1 (1) | | 2.3 (2,\*) | | | | | | | 12.0 (1) | | | | | 14.5-14.8 (1) | | 2.2 (2,\*) | | | | | | | 11.1-11.2 (1) | | | | | 14.0-14.4 (1) | | 2.1 (2,\*) | | | | | | | 10.1 (1) | | | | | 13.4-13.7 (1) | | | | | | | | | 9.2 (1) | | | | | 13.3 (1) | | | | | | | | | 8.2 (1) | | | | | 13.2 (1) | | | | | | | | | 7.2-7.4 (1) | | | | | 13.0-13.1 (1) | | | | | | | | | 6.2-6.4 (1) | | | | | 12.2-12.5 (1) | | | | | | | | | 5.0-5.4 (1) | | | | | 12.0-12.1 (1) | | | | | | | | | 4 (1) | | | | | 11.3-11.4 (1) | | | | | | | | | | | | | | 11.0-11.2 (1) | | | | | | | | | | | | | | 10.3 (1) | | | | | | | | | | | | | | 10.0-10.2 (1) | | | | | | | | | | | | | | 9.3 (1) | | | | | | | | | | | | | | 9.0-9.2 (1) | | | | | | | | | | | | | | 8.1-8.4 (1) | | | | | | | | | | | | | | 8 (1) | | | | | | | | | | | | | | 7.0-7.1 (1) | | | | | | | | | | | | | | 6.0-6.1 (1) | | | | | | | | | | | | | | 5.0-5.1 (1) | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Only supports the `WebKitCSSMatrix` version of the interface, not `DOMMatrix` 2. `WebKitCSSMatrix#skewX`, `WebKitCSSMatrix#skewY` are not supported 3. Only supports the `DOMMatrix` version of the interface, not `WebKitCSSMatrix` (support required by spec for legacy reasons) 4. Only replaces `WebkitCSSMatrix` and not `SVGMatrix` 5. Does not support `fromMatrix()`, `fromFloat32Array()`, `fromFloat64Array()`, and `toJSON()` methods \* Partial support with prefix. Resources --------- * [WebKitCSSMatrix API Reference](https://developer.apple.com/reference/webkitjs/webkitcssmatrix) * [WebKitCSSMatrix in Compatibility Standard](https://compat.spec.whatwg.org/#webkitcssmatrix-interface) * [MDN Web Docs - DOMMatrix](https://developer.mozilla.org/en-US/docs/Web/API/DOMMatrix) * [Chrome implementation bug](https://bugs.chromium.org/p/chromium/issues/detail?id=581955) browser_support_tables HTML Imports HTML Imports ============ Deprecated method of including and reusing HTML documents in other HTML documents. Superseded by ES modules. | | | | --- | --- | | Spec | <https://www.w3.org/TR/html-imports/> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Firefox [has no plans to support HTML imports](https://hacks.mozilla.org/2014/12/mozilla-and-web-components/) though for now it can be enabled through the "dom.webcomponents.enabled" preference in about:config 2. Enabled through the "Enable HTML Imports" flag in chrome://flags 3. Enabled through the "Experimental Web Platform features" flag in chrome://flags 4. Enabled through the "Enable HTML Imports" flag in opera://flags 5. Enabled through the "Experimental Web Platform features" flag in opera://flags Resources --------- * [HTML5Rocks - HTML Imports: #include for the web](https://www.html5rocks.com/tutorials/webcomponents/imports/) * [Chromium tracking bug: Implement HTML Imports](https://code.google.com/p/chromium/issues/detail?id=240592) * [Firefox tracking bug: Implement HTML Imports](https://bugzilla.mozilla.org/show_bug.cgi?id=877072) * [IE Web Platform Status and Roadmap: HTML Imports](https://developer.microsoft.com/en-us/microsoft-edge/status/htmlimports/)
programming_docs
browser_support_tables Speech Synthesis API Speech Synthesis API ==================== A web API for controlling a text-to-speech output. | | | | --- | --- | | Spec | <https://w3c.github.io/speech-api/speechapi.html#tts-section> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (2) | | | | | | 110 | 110 (2) | TP | | | | | 109 | 109 (2) | 16.3 | | | 11 | 108 (2) | 108 | 108 (2) | 16.2 | 92 (2) | | 10 | 107 (2) | 107 | 107 (2) | 16.1 | 91 (2) | | 9 | 106 (2) | 106 | 106 (2) | 16.0 | 90 (2) | | 8 | 105 (2) | 105 | 105 (2) | 15.6 | 89 (2) | | [Show all](#) | | 7 | 104 (2) | 104 | 104 (2) | 15.5 | 88 (2) | | 6 | 103 (2) | 103 | 103 (2) | 15.4 | 87 (2) | | 5.5 | 102 (2) | 102 | 102 (2) | 15.2-15.3 | 86 (2) | | | 101 (2) | 101 | 101 (2) | 15.1 | 85 (2) | | | 100 (2) | 100 | 100 (2) | 15 | 84 (2) | | | 99 (2) | 99 | 99 (2) | 14.1 | 83 (2) | | | 98 (2) | 98 | 98 (2) | 14 | 82 (2) | | | 97 (2) | 97 | 97 (2) | 13.1 | 81 (2) | | | 96 (2) | 96 | 96 (2) | 13 | 80 (2) | | | 95 (2) | 95 | 95 (2) | 12.1 | 79 (2) | | | 94 (2) | 94 | 94 (2) | 12 | 78 (2) | | | 93 (2) | 93 | 93 (2) | 11.1 | 77 (2) | | | 92 (2) | 92 | 92 (2) | 11 | 76 (2) | | | 91 (2) | 91 | 91 (2) | 10.1 | 75 (2) | | | 90 (2) | 90 | 90 (2) | 10 | 74 (2) | | | 89 (2) | 89 | 89 (2) | 9.1 | 73 (2) | | | 88 (2) | 88 | 88 (2) | 9 | 72 (2) | | | 87 (2) | 87 | 87 (2) | 8 | 71 (2) | | | 86 (2) | 86 | 86 (2) | 7.1 | 70 (2) | | | 85 (2) | 85 | 85 (2) | 7 | 69 (2) | | | 84 (2) | 84 | 84 (2) | 6.1 | 68 (2) | | | 83 (2) | 83 | 83 (2) | 6 | 67 (2) | | | 81 (2) | 82 | 81 (2) | 5.1 | 66 (2) | | | 80 (2) | 81 | 80 (2) | 5 | 65 (2) | | | 79 (2) | 80 | 79 (2) | 4 | 64 (2) | | | 18 | 79 | 78 (2) | 3.2 | 63 | | | 17 | 78 | 77 (2) | 3.1 | 62 | | | 16 | 77 | 76 (2) | | 60 | | | 15 | 76 | 75 (2) | | 58 | | | 14 | 75 | 74 (2) | | 57 | | | 13 | 74 | 73 (2) | | 56 | | | 12 | 73 | 72 (2) | | 55 | | | | 72 | 71 (2) | | 54 | | | | 71 | 70 (2) | | 53 | | | | 70 | 69 (2) | | 52 | | | | 69 | 68 (2) | | 51 | | | | 68 | 67 (2) | | 50 | | | | 67 | 66 (2) | | 49 | | | | 66 | 65 (2) | | 48 | | | | 65 | 64 (2) | | 47 | | | | 64 | 63 (2) | | 46 | | | | 63 | 62 (2) | | 45 | | | | 62 | 61 (2) | | 44 | | | | 61 | 60 (2) | | 43 | | | | 60 | 59 (2) | | 42 | | | | 59 | 58 (2) | | 41 | | | | 58 | 57 (2) | | 40 | | | | 57 | 56 (2) | | 39 | | | | 56 | 55 (2) | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 (1) | 47 | | 30 | | | | 47 (1) | 46 | | 29 | | | | 46 (1) | 45 | | 28 | | | | 45 (1) | 44 | | 27 | | | | 44 (1) | 43 | | 26 | | | | 43 (1) | 42 | | 25 | | | | 42 (1) | 41 | | 24 | | | | 41 (1) | 40 | | 23 | | | | 40 (1) | 39 | | 22 | | | | 39 (1) | 38 | | 21 | | | | 38 (1) | 37 | | 20 | | | | 37 (1) | 36 | | 19 | | | | 36 (1) | 35 | | 18 | | | | 35 (1) | 34 | | 17 | | | | 34 (1) | 33 | | 16 | | | | 33 (1) | 32 | | 15 | | | | 32 (1) | 31 | | 12.1 | | | | 31 (1) | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Samsung Internet for GearVR: In Development, release based on Chromium m53 due Q1/2017 1. Can be enabled in Firefox using the `media.webspeech.synth.enabled` about:config flag. 2. Speech Synthesis in Chrome since version 55 stops playback after about 15 seconds on Windows 7 & 10, and Ubuntu 14.04, possibly other platforms Bugs ---- * [Chrome issue 679437: Speech Synthesis stops abruptly after about 15 seconds](https://bugs.chromium.org/p/chromium/issues/detail?id=679437) Resources --------- * [SitePoint article](https://www.sitepoint.com/talking-web-pages-and-the-speech-synthesis-api/) * [Demo](https://www.audero.it/demo/speech-synthesis-api-demo.html) * [Advanced demo and resource](https://zenorocha.github.io/voice-elements/) * [MDN article](https://developer.mozilla.org//docs/Web/API/SpeechSynthesis) * [Google Developers article](https://developers.google.com/web/updates/2014/01/Web-apps-that-talk-Introduction-to-the-Speech-Synthesis-API) browser_support_tables Lookbehind in JS regular expressions Lookbehind in JS regular expressions ==================================== The positive lookbehind (`(?<= )`) and negative lookbehind (`(?<! )`) zero-width assertions in JavaScript regular expressions can be used to ensure a pattern is preceded by another pattern. | | | | --- | --- | | Spec | <https://tc39.es/ecma262/#sec-assertion> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Blog post on lookbehind assertions](https://2ality.com/2017/05/regexp-lookbehind-assertions.html) * [Firefox implementation bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1225665) * [MDN: Regular Expressions Assertions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Assertions) * [Safari implementation bug](https://bugs.webkit.org/show_bug.cgi?id=174931) browser_support_tables Push API Push API ======== API to allow messages to be pushed from a server to a browser, even when the site isn't focused or even open in the browser. | | | | --- | --- | | Spec | <https://w3c.github.io/push-api/> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (2) | | | | | | 110 (2) | 110 (2) | TP (3,6) | | | | | 109 (2) | 109 (2) | 16.3 (3,6) | | | 11 | 108 (2) | 108 (2) | 108 (2) | 16.2 (3,6) | 92 (2) | | 10 | 107 (2) | 107 (2) | 107 (2) | 16.1 (3,6) | 91 (2) | | 9 | 106 (2) | 106 (2) | 106 (2) | 16.0 (3) | 90 (2) | | 8 | 105 (2) | 105 (2) | 105 (2) | 15.6 (3) | 89 (2) | | [Show all](#) | | 7 | 104 (2) | 104 (2) | 104 (2) | 15.5 (3) | 88 (2) | | 6 | 103 (2) | 103 (2) | 103 (2) | 15.4 (3) | 87 (2) | | 5.5 | 102 (2) | 102 (2) | 102 (2) | 15.2-15.3 (3) | 86 (2) | | | 101 (2) | 101 (2) | 101 (2) | 15.1 (3) | 85 (2) | | | 100 (2) | 100 (2) | 100 (2) | 15 (3) | 84 (2) | | | 99 (2) | 99 (2) | 99 (2) | 14.1 (3) | 83 (2) | | | 98 (2) | 98 (2) | 98 (2) | 14 (3) | 82 (2) | | | 97 (2) | 97 (2) | 97 (2) | 13.1 (3) | 81 (2) | | | 96 (2) | 96 (2) | 96 (2) | 13 (3) | 80 (2) | | | 95 (2) | 95 (2) | 95 (2) | 12.1 (3) | 79 (2) | | | 94 (2) | 94 (2) | 94 (2) | 12 (3) | 78 (2) | | | 93 (2) | 93 (2) | 93 (2) | 11.1 (3) | 77 (2) | | | 92 (2) | 92 (2) | 92 (2) | 11 (3) | 76 (2) | | | 91 (2) | 91 (2) | 91 (2) | 10.1 (3) | 75 (2) | | | 90 (2) | 90 (2) | 90 (2) | 10 (3) | 74 (2) | | | 89 (2) | 89 (2) | 89 (2) | 9.1 (3) | 73 (2) | | | 88 (2) | 88 (2) | 88 (2) | 9 | 72 (2) | | | 87 (2) | 87 (2) | 87 (2) | 8 | 71 (2) | | | 86 (2) | 86 (2) | 86 (2) | 7.1 | 70 (2) | | | 85 (2) | 85 (2) | 85 (2) | 7 | 69 (2) | | | 84 (2) | 84 (2) | 84 (2) | 6.1 | 68 (2) | | | 83 (2) | 83 (2) | 83 (2) | 6 | 67 (2) | | | 81 (2) | 82 (2) | 81 (2) | 5.1 | 66 (2) | | | 80 (2) | 81 (2) | 80 (2) | 5 | 65 (2) | | | 79 (2) | 80 (2) | 79 (2) | 4 | 64 (2) | | | 18 | 79 (2) | 78 (2) | 3.2 | 63 (2) | | | 17 | 78 (2) | 77 (2) | 3.1 | 62 (2) | | | 16 | 77 (2) | 76 (2) | | 60 (2) | | | 15 | 76 (2) | 75 (2) | | 58 (2) | | | 14 | 75 (2) | 74 (2) | | 57 (2) | | | 13 | 74 (2) | 73 (2) | | 56 (2) | | | 12 | 73 (2) | 72 (2) | | 55 (2) | | | | 72 (2) | 71 (2) | | 54 (2) | | | | 71 (2) | 70 (2) | | 53 (2) | | | | 70 (2) | 69 (2) | | 52 (2) | | | | 69 (2) | 68 (2) | | 51 (2) | | | | 68 (2) | 67 (2) | | 50 (2) | | | | 67 (2) | 66 (2) | | 49 (2) | | | | 66 (2) | 65 (2) | | 48 (2) | | | | 65 (2) | 64 (2) | | 47 (2) | | | | 64 (2) | 63 (2) | | 46 (2) | | | | 63 (2) | 62 (2) | | 45 (2) | | | | 62 (2) | 61 (2) | | 44 (2) | | | | 61 (2) | 60 (2) | | 43 (2) | | | | 60 (2,4) | 59 (2) | | 42 (2) | | | | 59 (2) | 58 (2) | | 41 | | | | 58 (2) | 57 (2) | | 40 | | | | 57 (2) | 56 (2) | | 39 | | | | 56 (2) | 55 (2) | | 38 | | | | 55 (2) | 54 (2) | | 37 | | | | 54 (2) | 53 (2) | | 36 | | | | 53 (2) | 52 (2) | | 35 | | | | 52 (2,4) | 51 (2) | | 34 | | | | 51 (2) | 50 (2) | | 33 | | | | 50 (2) | 49 (1,2) | | 32 | | | | 49 (2) | 48 (1,2) | | 31 | | | | 48 (2) | 47 (1,2) | | 30 | | | | 47 (2) | 46 (1,2) | | 29 | | | | 46 (2) | 45 (1,2) | | 28 | | | | 45 (2,4) | 44 (1,2) | | 27 | | | | 44 (2) | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (2) | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Partial support refers to not supporting `PushEvent.data` and `PushMessageData` 2. Requires full browser to be running to receive messages 3. Safari 9.1 - 16.0 supported a custom implementation which remains available in later versions, see [Safari Push Notifications](https://developer.apple.com/notifications/safari-push-notifications/) and [WWDC video](https://web.archive.org/web/20210419000205/https://developer.apple.com/videos/play/wwdc2013/614/) 4. Disabled on Firefox ESR, but can be re-enabled with the `dom.serviceWorkers.enabled` and `dom.push.enabled` flags 5. Partial implementation can be enabled via "Push API" in the Experimental Features menu 6. Only available on macOS 13 Ventura or later and only in Safari itself, not WKWebView nor SFSafariViewController Resources --------- * [MDN Web Docs - Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API) * [Google Developers article](https://developers.google.com/web/updates/2015/03/push-notifications-on-the-open-web)
programming_docs
browser_support_tables CSS Cascade Layers CSS Cascade Layers ================== The `@layer` at-rule allows authors to explicitly layer their styles in the cascade, before specificity and order of appearance are considered. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css-cascade-5/> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 (2) | 98 | 98 (2) | 14 | 82 | | | 97 (2) | 97 | 97 (2) | 13.1 | 81 | | | 96 (2) | 96 (1) | 96 (2) | 13 | 80 | | | 95 | 95 (1) | 95 | 12.1 | 79 | | | 94 | 94 (1) | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled with the "layout.css.cascade-layers.enabled" feature flag under `about:config` 2. Can be enabled in Chrome Canary using the `--enable-blink-features=CSSCascadeLayers` runtime flag 3. Can be enabled in the Experimental Features developer menu Resources --------- * [The Future of CSS: Cascade Layers (CSS @layer)](https://www.bram.us/2021/09/15/the-future-of-css-cascade-layers-css-at-layer/) * [Chromium support bug](https://crbug.com/1095765) * [Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1699215) * [WebKit support bug](https://bugs.webkit.org/show_bug.cgi?id=220779) * [Collection of demos](https://codepen.io/collection/BNjmma) browser_support_tables Spellcheck attribute Spellcheck attribute ==================== Attribute for `input`/`textarea` fields to enable/disable the browser's spellchecker. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/interaction.html#spelling-and-grammar-checking> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- The partial support in mobile browsers results from their OS generally having built-in spell checking instead of using the wavy underline to indicate misspelled words. `spellcheck="false"` does not seem to have any effect in these browsers. Browsers have different behavior in how they deal with spellchecking in combination with the the `lang` attribute. Generally spelling is based on the browser's language, not the language of the document. Bugs ---- * Browsers can behave differently on when they should check spelling (e.g. immediately or only on focus) Resources --------- * [MDN Web Docs - Controlling spell checking](https://developer.mozilla.org/en-US/docs/Web/HTML/Controlling_spell_checking_in_HTML_formsControlling_spell_checking_in_HTML_forms) browser_support_tables WebUSB WebUSB ====== Allows communication with devices via USB (Universal Serial Bus). | | | | --- | --- | | Spec | <https://wicg.github.io/webusb/> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Google Developers article](https://developers.google.com/web/updates/2016/03/access-usb-devices-on-the-web) * [Mozilla Specification Positions: Harmful](https://mozilla.github.io/standards-positions/#webusb) browser_support_tables CSS math functions min(), max() and clamp() CSS math functions min(), max() and clamp() =========================================== More advanced mathematical expressions in addition to `calc()` | | | | --- | --- | | Spec | <https://www.w3.org/TR/css-values-4/#math-function> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 (1) | 80 | | | 95 | 95 | 95 | 12.1 (1) | 79 | | | 94 | 94 | 94 | 12 (1) | 78 | | | 93 | 93 | 93 | 11.1 (1) | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 (1) | | | | | | | | | 8.2 | | | | | 13.2 (1) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (1) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (1) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 (1) | | | | | | | | | 4 | | | | | 11.3-11.4 (1) | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Safari did not support `clamp()` Resources --------- * [Test case on JSFiddle](https://jsfiddle.net/as9t4jek/) * [Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=css-min-max) * [Chrome support bug](https://crbug.com/825895) * [MDN Web Docs article for min()](https://developer.mozilla.org/en-US/docs/Web/CSS/min) * [MDN Web Docs article for max()](https://developer.mozilla.org/en-US/docs/Web/CSS/max) * [MDN Web Docs article for clamp()](https://developer.mozilla.org/en-US/docs/Web/CSS/clamp) * [Getting Started With CSS Math Functions Level 4](https://webdesign.tutsplus.com/tutorials/mathematical-expressions-calc-min-and-max--cms-29735) * [Introduction to CSS Math Functions](https://stackdiary.com/css-math-functions/)
programming_docs
browser_support_tables Srcset and sizes attributes Srcset and sizes attributes =========================== The `srcset` and `sizes` attributes on `img` (or `source`) elements allow authors to define various image resources and "hints" that assist a user agent to determine the most appropriate image source to display (e.g. high-resolution displays, small monitors, etc). | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-srcset> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 (2) | 71 | | | 86 | 86 | 86 | 7.1 (2) | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 (3) | 76 | 75 | | 58 | | | 14 (3) | 75 | 74 | | 57 | | | 13 (3) | 74 | 73 | | 56 | | | 12 (2) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 (2) | | | | 41 | 40 | | 23 (2) | | | | 40 | 39 | | 22 (2) | | | | 39 | 38 | | 21 (2) | | | | 38 | 37 (2) | | 20 | | | | 37 (1) | 36 (2) | | 19 | | | | 36 (1) | 35 (2) | | 18 | | | | 35 (1) | 34 (2) | | 17 | | | | 34 (1) | 33 | | 16 | | | | 33 (1) | 32 | | 15 | | | | 32 (1) | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 (2) | | | | | | | | | | | | | | 8 (2) | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled in Firefox by setting the about:config preference dom.image.srcset.enabled to true 2. Supports the subset of the syntax for resolution switching (using the `x` descriptor), but not the full syntax that can be used with `sizes` (using the `w` descriptor). 3. Intermittently displays distorted images due to bug present (see known issues) Bugs ---- * Edge versions 13, 14 and 15 intermittently display distorted images as soon as they encounter a srcset attribute, seemingly dependent on caching and network timing. [see bug](https://web.archive.org/web/20171210184313/https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/7778808/) Resources --------- * [Improved support for high-resolution displays with the srcset image attribute](https://www.webkit.org/blog/2910/improved-support-for-high-resolution-displays-with-the-srcset-image-attribute/) * [Blog post on srcset & sizes](https://ericportis.com/posts/2014/srcset-sizes/) * [MDN: Responsive images](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images) * [MDN: ![]() element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img) browser_support_tables Mutation events Mutation events =============== Deprecated mechanism for listening to changes made to the DOM, replaced by Mutation Observers. | | | | --- | --- | | Spec | <https://www.w3.org/TR/DOM-Level-3-Events/#legacy-mutationevent-events> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (1) | | | | | | 110 (2) | 110 (1) | TP (1) | | | | | 109 (2) | 109 (1) | 16.3 (1) | | | 11 (2) | 108 (1) | 108 (2) | 108 (1) | 16.2 (1) | 92 (1) | | 10 (2) | 107 (1) | 107 (2) | 107 (1) | 16.1 (1) | 91 (1) | | 9 (2) | 106 (1) | 106 (2) | 106 (1) | 16.0 (1) | 90 (1) | | 8 | 105 (1) | 105 (2) | 105 (1) | 15.6 (1) | 89 (1) | | [Show all](#) | | 7 | 104 (1) | 104 (2) | 104 (1) | 15.5 (1) | 88 (1) | | 6 | 103 (1) | 103 (2) | 103 (1) | 15.4 (1) | 87 (1) | | 5.5 | 102 (1) | 102 (2) | 102 (1) | 15.2-15.3 (1) | 86 (1) | | | 101 (1) | 101 (2) | 101 (1) | 15.1 (1) | 85 (1) | | | 100 (1) | 100 (2) | 100 (1) | 15 (1) | 84 (1) | | | 99 (1) | 99 (2) | 99 (1) | 14.1 (1) | 83 (1) | | | 98 (1) | 98 (2) | 98 (1) | 14 (1) | 82 (1) | | | 97 (1) | 97 (2) | 97 (1) | 13.1 (1) | 81 (1) | | | 96 (1) | 96 (2) | 96 (1) | 13 (1) | 80 (1) | | | 95 (1) | 95 (2) | 95 (1) | 12.1 (1) | 79 (1) | | | 94 (1) | 94 (2) | 94 (1) | 12 (1) | 78 (1) | | | 93 (1) | 93 (2) | 93 (1) | 11.1 (1) | 77 (1) | | | 92 (1) | 92 (2) | 92 (1) | 11 (1) | 76 (1) | | | 91 (1) | 91 (2) | 91 (1) | 10.1 (1) | 75 (1) | | | 90 (1) | 90 (2) | 90 (1) | 10 (1) | 74 (1) | | | 89 (1) | 89 (2) | 89 (1) | 9.1 (1) | 73 (1) | | | 88 (1) | 88 (2) | 88 (1) | 9 (1) | 72 (1) | | | 87 (1) | 87 (2) | 87 (1) | 8 (1) | 71 (1) | | | 86 (1) | 86 (2) | 86 (1) | 7.1 (1) | 70 (1) | | | 85 (1) | 85 (2) | 85 (1) | 7 (1) | 69 (1) | | | 84 (1) | 84 (2) | 84 (1) | 6.1 (1) | 68 (1) | | | 83 (1) | 83 (2) | 83 (1) | 6 (1) | 67 (1) | | | 81 (1) | 82 (2) | 81 (1) | 5.1 (1) | 66 (1) | | | 80 (1) | 81 (2) | 80 (1) | 5 (1) | 65 (1) | | | 79 (1) | 80 (2) | 79 (1) | 4 (1) | 64 (1) | | | 18 (2) | 79 (2) | 78 (1) | 3.2 | 63 (1) | | | 17 (2) | 78 (2) | 77 (1) | 3.1 | 62 (1) | | | 16 (2) | 77 (2) | 76 (1) | | 60 (1) | | | 15 (2) | 76 (2) | 75 (1) | | 58 (1) | | | 14 (2) | 75 (2) | 74 (1) | | 57 (1) | | | 13 (2) | 74 (2) | 73 (1) | | 56 (1) | | | 12 (2) | 73 (2) | 72 (1) | | 55 (1) | | | | 72 (2) | 71 (1) | | 54 (1) | | | | 71 (2) | 70 (1) | | 53 (1) | | | | 70 (2) | 69 (1) | | 52 (1) | | | | 69 (2) | 68 (1) | | 51 (1) | | | | 68 (2) | 67 (1) | | 50 (1) | | | | 67 (2) | 66 (1) | | 49 (1) | | | | 66 (2) | 65 (1) | | 48 (1) | | | | 65 (2) | 64 (1) | | 47 (1) | | | | 64 (2) | 63 (1) | | 46 (1) | | | | 63 (2) | 62 (1) | | 45 (1) | | | | 62 (2) | 61 (1) | | 44 (1) | | | | 61 (2) | 60 (1) | | 43 (1) | | | | 60 (2) | 59 (1) | | 42 (1) | | | | 59 (2) | 58 (1) | | 41 (1) | | | | 58 (2) | 57 (1) | | 40 (1) | | | | 57 (2) | 56 (1) | | 39 (1) | | | | 56 (2) | 55 (1) | | 38 (1) | | | | 55 (2) | 54 (1) | | 37 (1) | | | | 54 (2) | 53 (1) | | 36 (1) | | | | 53 (2) | 52 (1) | | 35 (1) | | | | 52 (2) | 51 (1) | | 34 (1) | | | | 51 (2) | 50 (1) | | 33 (1) | | | | 50 (2) | 49 (1) | | 32 (1) | | | | 49 (2) | 48 (1) | | 31 (1) | | | | 48 (2) | 47 (1) | | 30 (1) | | | | 47 (2) | 46 (1) | | 29 (1) | | | | 46 (2) | 45 (1) | | 28 (1) | | | | 45 (2) | 44 (1) | | 27 (1) | | | | 44 (2) | 43 (1) | | 26 (1) | | | | 43 (2) | 42 (1) | | 25 (1) | | | | 42 (2) | 41 (1) | | 24 (1) | | | | 41 (2) | 40 (1) | | 23 (1) | | | | 40 (2) | 39 (1) | | 22 (1) | | | | 39 (2) | 38 (1) | | 21 (1) | | | | 38 (2) | 37 (1) | | 20 (1) | | | | 37 (2) | 36 (1) | | 19 (1) | | | | 36 (2) | 35 (1) | | 18 (1) | | | | 35 (2) | 34 (1) | | 17 (1) | | | | 34 (2) | 33 (1) | | 16 (1) | | | | 33 (2) | 32 (1) | | 15 (1) | | | | 32 (2) | 31 (1) | | 12.1 | | | | 31 (2) | 30 (1) | | 12 | | | | 30 (2) | 29 (1) | | 11.6 | | | | 29 (2) | 28 (1) | | 11.5 | | | | 28 (2) | 27 (1) | | 11.1 | | | | 27 (2) | 26 (1) | | 11 | | | | 26 (2) | 25 (1) | | 10.6 | | | | 25 (2) | 24 (1) | | 10.5 | | | | 24 (2) | 23 (1) | | 10.0-10.1 | | | | 23 (2) | 22 (1) | | 9.5-9.6 | | | | 22 (2) | 21 (1) | | 9 | | | | 21 (2) | 20 (1) | | | | | | 20 (2) | 19 (1) | | | | | | 19 (2) | 18 (1) | | | | | | 18 (2) | 17 (1) | | | | | | 17 (2) | 16 (1) | | | | | | 16 (2) | 15 (1) | | | | | | 15 (2) | 14 | | | | | | 14 (2) | 13 | | | | | | 13 (2) | 12 | | | | | | 12 (2) | 11 | | | | | | 11 (2) | 10 | | | | | | 10 (2) | 9 | | | | | | 9 (2) | 8 | | | | | | 8 (2) | 7 | | | | | | 7 (2) | 6 | | | | | | 6 (2) | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (1) | | | | | | | | | | | | | | 16.2 (1) | all | 108 (1) | 10 (1) | 72 (1) | 108 (1) | 107 (2) | 11 (2) | 13.4 (1) | 19.0 (1) | 13.1 (1) | 13.18 (1) | 2.5 (2) | | 16.1 (1) | | 4.4.3-4.4.4 (1) | 7 (1) | 12.1 | | | 10 (2) | | 18.0 (1) | | | | | 16.0 (1) | | 4.4 (1) | | 12 | | | | | 17.0 (1) | | | | | 15.6 (1) | | 4.2-4.3 (1) | | 11.5 | | | | | 16.0 (1) | | | | | [Show all](#) | | 15.5 (1) | | 4.1 (1) | | 11.1 | | | | | 15.0 (1) | | | | | 15.4 (1) | | 4 (1) | | 11 | | | | | 14.0 (1) | | | | | 15.2-15.3 (1) | | 3 (1) | | 10 | | | | | 13.0 (1) | | | | | 15.0-15.1 (1) | | 2.3 (1) | | | | | | | 12.0 (1) | | | | | 14.5-14.8 (1) | | 2.2 | | | | | | | 11.1-11.2 (1) | | | | | 14.0-14.4 (1) | | 2.1 | | | | | | | 10.1 (1) | | | | | 13.4-13.7 (1) | | | | | | | | | 9.2 (1) | | | | | 13.3 (1) | | | | | | | | | 8.2 (1) | | | | | 13.2 (1) | | | | | | | | | 7.2-7.4 (1) | | | | | 13.0-13.1 (1) | | | | | | | | | 6.2-6.4 (1) | | | | | 12.2-12.5 (1) | | | | | | | | | 5.0-5.4 (1) | | | | | 12.0-12.1 (1) | | | | | | | | | 4 (1) | | | | | 11.3-11.4 (1) | | | | | | | | | | | | | | 11.0-11.2 (1) | | | | | | | | | | | | | | 10.3 (1) | | | | | | | | | | | | | | 10.0-10.2 (1) | | | | | | | | | | | | | | 9.3 (1) | | | | | | | | | | | | | | 9.0-9.2 (1) | | | | | | | | | | | | | | 8.1-8.4 (1) | | | | | | | | | | | | | | 8 (1) | | | | | | | | | | | | | | 7.0-7.1 (1) | | | | | | | | | | | | | | 6.0-6.1 (1) | | | | | | | | | | | | | | 5.0-5.1 (1) | | | | | | | | | | | | | | 4.2-4.3 (1) | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- See also support for [Mutation Observer](https://caniuse.com/#feat=mutationobserver), which replaces mutation events and does not have the same performance drawbacks. 1. Does not support `DOMAttrModified` 2. Does not support `DOMNodeInsertedIntoDocument` & `DOMNodeRemovedFromDocument` Resources --------- * [MDN Web Docs - Mutation events](https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Mutation_events) browser_support_tables Beacon API Beacon API ========== Allows data to be sent asynchronously to a server with `navigator.sendBeacon`, even after a page was closed. Useful for posting analytics data the moment a user was finished using the page. | | | | --- | --- | | Spec | <https://www.w3.org/TR/beacon/> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Bugs ---- * Safari 11.1 – 12.2 on macOS and iOS [have a bug](https://bugs.webkit.org/show_bug.cgi?id=188329) with sendBeacon in a pagehide event listener. Fixed in iOS 12.3. * Safari 11.1 – 12 on iOS [can’t sendBeacons to unvisited origins](https://bugs.webkit.org/show_bug.cgi?id=193508). Fixed in iOS 13. * Safari on iOS [won’t sendBeacons from pages that quickly redirect to another location](https://www.ctrl.blog/entry/safari-beacon-issues.html). Resources --------- * [MDN Web Docs - Beacon](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon)
programming_docs
browser_support_tables CSS zoom CSS zoom ======== Non-standard method of scaling content. | | | | --- | --- | | Spec | <https://developer.mozilla.org/en-US/docs/Web/CSS/zoom> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (1) | 108 | 108 | 108 | 16.2 | 92 | | 10 (1) | 107 | 107 | 107 | 16.1 | 91 | | 9 (1) | 106 | 106 | 106 | 16.0 | 90 | | 8 (1) | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 (1) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 (1) | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Originally implemented only in Internet Explorer. Although several other browsers support the property, using `transform: scale()` is the recommended solution to scale content. Note though that `transform: scale()` does not work the same as `zoom`. If e.g. `transform: scale(0.6)` is used on the `html` or `body` element then it resizes the entire page, showing a minified page with huge white margins around it, whereas `zoom: 0.6` scales the \*elements\* on the page, but not the page itself on which the elements are drawn. 1. The `-ms-zoom` property is an extension to CSS, and can be used as a synonym for `zoom` in IE8 Standards mode. Bugs ---- * When both `zoom` and `transform: scale()` are applied, Chrome will perform zooming operation twice. Resources --------- * [CSS Tricks](https://css-tricks.com/almanac/properties/z/zoom/) * [Safari Developer Library](https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html#//apple_ref/doc/uid/TP30001266-SW1) * [Article explaining usage of zoom as the hack for fixing rendering bugs in IE6 and IE7.](https://web.archive.org/web/20160809134322/http://www.satzansatz.de/cssd/onhavinglayout.html) * [MDN Web Docs - CSS zoom](https://developer.mozilla.org/en-US/docs/Web/CSS/zoom) browser_support_tables CSS background-repeat round and space CSS background-repeat round and space ===================================== Allows CSS background images to be repeated without clipping. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css3-background/#the-background-repeat> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 (1) | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. IE9 does not appear to render "background-repeat: round" correctly. Resources --------- * [MDN Web Docs - background-repeat](https://developer.mozilla.org//docs/Web/CSS/background-repeat) * [CSS-Tricks article on background-repeat](https://css-tricks.com/almanac/properties/b/background-repeat/) browser_support_tables querySelector/querySelectorAll querySelector/querySelectorAll ============================== Method of accessing DOM elements using CSS selectors | | | | --- | --- | | Spec | <https://dom.spec.whatwg.org/#dom-parentnode-queryselector> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 (1) | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Partial support in IE8 is due to being limited to [CSS 2.1 selectors](/#feat=css-sel2) and a small subset of [CSS 3 selectors](/#feat=css-sel3) (see notes there). Additionally, it will have trouble with selectors including unrecognized tags (for example HTML5 ones). Bugs ---- * iOS 8.\* contains a [bug](https://github.com/jquery/sizzle/issues/290) where selecting siblings of filtered id selections are no longer working (for example #a + p). Resources --------- * [MDN Web Docs - querySelector](https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelector) * [MDN Web Docs - querySelectorAll](https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelectorAll) * [WebPlatform Docs](https://webplatform.github.io/docs/css/selectors_api/querySelector)
programming_docs
browser_support_tables disabled attribute of the fieldset element disabled attribute of the fieldset element ========================================== Allows disabling all of the form control descendants of a fieldset via a `disabled` attribute on the fieldset element itself. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/forms.html#attr-fieldset-disabled> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (1,2) | 108 | 108 | 108 | 16.2 | 92 | | 10 (1,2) | 107 | 107 | 107 | 16.1 | 91 | | 9 (1) | 106 | 106 | 106 | 16.0 | 90 | | 8 (1) | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 (1,2) | 104 | 104 | 104 | 15.5 | 88 | | 6 (1,2) | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all (1,2) | 108 | 10 | 72 | 108 | 107 | 11 (2) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Text inputs that are descendants of a disabled fieldset appear disabled but the user can still interact with them. [See IE bug #962368.](https://web.archive.org/web/20170306075528/https://connect.microsoft.com/IE/feedbackdetail/view/962368/can-still-edit-input-type-text-within-fieldset-disabled) 2. File inputs that are descendants of a disabled fieldset appear disabled but the user can still interact with them. [See IE bug #817488.](https://web.archive.org/web/20170306075531/https://connect.microsoft.com/IE/feedbackdetail/view/817488) Resources --------- * [JS Bin Testcase/Demo](https://jsbin.com/bibiqi/1/edit?html,output) browser_support_tables :default CSS pseudo-class :default CSS pseudo-class ========================= The `:default` pseudo-class matches checkboxes and radio buttons which are checked by default, `<option>`s with the `selected` attribute, and the default submit button (if any) of a form. | | | | --- | --- | | Spec | <https://w3c.github.io/csswg-drafts/selectors-4/#the-default-pseudo> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 (1) | 74 | | | 89 | 89 | 89 | 9.1 (1) | 73 | | | 88 | 88 | 88 | 9 (1) | 72 | | | 87 | 87 | 87 | 8 (1) | 71 | | | 86 | 86 | 86 | 7.1 (1) | 70 | | | 85 | 85 | 85 | 7 (1) | 69 | | | 84 | 84 | 84 | 6.1 (1) | 68 | | | 83 | 83 | 83 | 6 (1) | 67 | | | 81 | 82 | 81 | 5.1 (1) | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 (1) | | | | 54 | 53 | | 36 (1) | | | | 53 | 52 | | 35 (1) | | | | 52 | 51 | | 34 (1) | | | | 51 | 50 (1) | | 33 (1) | | | | 50 | 49 (1) | | 32 (1) | | | | 49 | 48 (1) | | 31 (1) | | | | 48 | 47 (1) | | 30 (1) | | | | 47 | 46 (1) | | 29 (1) | | | | 46 | 45 (1) | | 28 (1) | | | | 45 | 44 (1) | | 27 (1) | | | | 44 | 43 (1) | | 26 (1) | | | | 43 | 42 (1) | | 25 (1) | | | | 42 | 41 (1) | | 24 (1) | | | | 41 | 40 (1) | | 23 (1) | | | | 40 | 39 (1) | | 22 (1) | | | | 39 | 38 (1) | | 21 (1) | | | | 38 | 37 (1) | | 20 (1) | | | | 37 | 36 (1) | | 19 (1) | | | | 36 | 35 (1) | | 18 (1) | | | | 35 | 34 (1) | | 17 (1) | | | | 34 | 33 (1) | | 16 (1) | | | | 33 | 32 (1) | | 15 (1) | | | | 32 | 31 (1) | | 12.1 (2) | | | | 31 | 30 (1) | | 12 (2) | | | | 30 | 29 (1) | | 11.6 (2) | | | | 29 | 28 (1) | | 11.5 | | | | 28 | 27 (1) | | 11.1 | | | | 27 | 26 (1) | | 11 | | | | 26 | 25 (1) | | 10.6 | | | | 25 | 24 (1) | | 10.5 | | | | 24 | 23 (1) | | 10.0-10.1 | | | | 23 | 22 (1) | | 9.5-9.6 | | | | 22 | 21 (1) | | 9 | | | | 21 | 20 (1) | | | | | | 20 | 19 (1) | | | | | | 19 | 18 (1) | | | | | | 18 | 17 (1) | | | | | | 17 | 16 (1) | | | | | | 16 | 15 (1) | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all (2) | 108 | 10 (1) | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 (1) | 7 | 12.1 (2) | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 (1) | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 (1) | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 (1) | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 (1) | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 (1) | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 (1) | | | | | | | | | | | | | | 9.3 (1) | | | | | | | | | | | | | | 9.0-9.2 (1) | | | | | | | | | | | | | | 8.1-8.4 (1) | | | | | | | | | | | | | | 8 (1) | | | | | | | | | | | | | | 7.0-7.1 (1) | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Whether `<option selected>` matches `:default` (per the spec) was not tested since `<select>`s and `<option>`s are generally not styleable, which makes it hard to formulate a test for this. 1. Does not match `<input type="checkbox" checked>` or `<input type="radio" checked>` 2. Does not match the default submit button of a form Resources --------- * [HTML specification for `:default`](https://html.spec.whatwg.org/multipage/scripting.html#selector-default) * [MDN Web Docs - CSS :default](https://developer.mozilla.org/en-US/docs/Web/CSS/:default) * [WebKit bug 156230 - `:default` CSS pseudo-class should match checkboxes+radios with a `checked` attribute](https://bugs.webkit.org/show_bug.cgi?id=156230) * [JS Bin testcase](https://jsbin.com/hiyada/edit?html,css,output) browser_support_tables Picture element Picture element =============== A responsive images method to control which image resource a user agent presents to a user, based on resolution, media query and/or support for a particular image format | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/embedded-content.html#the-picture-element> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 (2) | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 (1) | | 20 | | | | 37 (3) | 36 | | 19 | | | | 36 (3) | 35 | | 18 | | | | 35 (3) | 34 | | 17 | | | | 34 (3) | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Enabled in Chrome through the "experimental Web Platform features" flag in chrome://flags 2. Enabled in Opera through the "experimental Web Platform features" flag in opera://flags 3. Enabled in Firefox by setting the about:config preference dom.image.picture.enable to true Bugs ---- * See [a list](https://github.com/ResponsiveImagesCG/picture-element/issues?state=open) of unresolved issues / feature requests within the specification Resources --------- * [Demo](https://responsiveimages.org/demos/) * [Tutorial](https://code.tutsplus.com/tutorials/better-responsive-images-with-the-picture-element--net-36583) * [Read about the use cases](https://usecases.responsiveimages.org/) * [General information about Responsive Images](https://responsiveimages.org/) * [Blog post on usage](https://dev.opera.com/articles/responsive-images/) * [HTML5 Rocks tutorial](https://www.html5rocks.com/tutorials/responsive/picture-element/) * [Picturefill - polyfill for picture, srcset, sizes, and more](https://github.com/scottjehl/picturefill)
programming_docs
browser_support_tables scrollIntoView scrollIntoView ============== The `Element.scrollIntoView()` method scrolls the current element into the visible area of the browser window. Parameters can be provided to set the position inside the visible area as well as whether scrolling should be instant or smooth. | | | | --- | --- | | Spec | <https://w3c.github.io/csswg-drafts/cssom-view/#dom-element-scrollintoview> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (1) | 108 | 108 | 108 | 16.2 | 92 | | 10 (1) | 107 | 107 | 107 | 16.1 | 91 | | 9 (1) | 106 | 106 | 106 | 16.0 | 90 | | 8 (1) | 105 | 105 | 105 | 15.6 (1) | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 (1) | 88 | | 6 | 103 | 103 | 103 | 15.4 (1) | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 (1) | 86 | | | 101 | 101 | 101 | 15.1 (1) | 85 | | | 100 | 100 | 100 | 15 (1) | 84 | | | 99 | 99 | 99 | 14.1 (1) | 83 | | | 98 | 98 | 98 | 14 (1) | 82 | | | 97 | 97 | 97 | 13.1 (1) | 81 | | | 96 | 96 | 96 | 13 (1) | 80 | | | 95 | 95 | 95 | 12.1 (1) | 79 | | | 94 | 94 | 94 | 12 (1) | 78 | | | 93 | 93 | 93 | 11.1 (1) | 77 | | | 92 | 92 | 92 | 11 (1) | 76 | | | 91 | 91 | 91 | 10.1 (1) | 75 | | | 90 | 90 | 90 | 10 (1) | 74 | | | 89 | 89 | 89 | 9.1 (1) | 73 | | | 88 | 88 | 88 | 9 (1) | 72 | | | 87 | 87 | 87 | 8 (1) | 71 | | | 86 | 86 | 86 | 7.1 (1) | 70 | | | 85 | 85 | 85 | 7 (1) | 69 | | | 84 | 84 | 84 | 6.1 (1) | 68 | | | 83 | 83 | 83 | 6 (1) | 67 | | | 81 | 82 | 81 | 5.1 (1) | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 (1) | 79 | 78 | 3.2 | 63 | | | 17 (1) | 78 | 77 | 3.1 | 62 | | | 16 (1) | 77 | 76 | | 60 | | | 15 (1) | 76 | 75 | | 58 | | | 14 (1) | 75 | 74 | | 57 | | | 13 (1) | 74 | 73 | | 56 | | | 12 (1) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 (1) | | | | 64 | 63 | | 46 (1) | | | | 63 | 62 | | 45 (1) | | | | 62 | 61 | | 44 (1) | | | | 61 | 60 (1) | | 43 (1) | | | | 60 | 59 (1) | | 42 (1) | | | | 59 | 58 (1) | | 41 (1) | | | | 58 | 57 (1) | | 40 (1) | | | | 57 | 56 (1) | | 39 (1) | | | | 56 | 55 (1) | | 38 (1) | | | | 55 | 54 (1) | | 37 (1) | | | | 54 | 53 (1) | | 36 (1) | | | | 53 | 52 (1) | | 35 (1) | | | | 52 | 51 (1) | | 34 (1) | | | | 51 | 50 (1) | | 33 (1) | | | | 50 | 49 (1) | | 32 (1) | | | | 49 | 48 (1) | | 31 (1) | | | | 48 | 47 (1) | | 30 (1) | | | | 47 | 46 (1) | | 29 (1) | | | | 46 | 45 (1) | | 28 (1) | | | | 45 | 44 (1) | | 27 (1) | | | | 44 | 43 (1) | | 26 (1) | | | | 43 | 42 (1) | | 25 (1) | | | | 42 | 41 (1) | | 24 (1) | | | | 41 | 40 (1) | | 23 (1) | | | | 40 | 39 (1) | | 22 (1) | | | | 39 | 38 (1) | | 21 (1) | | | | 38 | 37 (1) | | 20 (1) | | | | 37 | 36 (1) | | 19 (1) | | | | 36 | 35 (1) | | 18 (1) | | | | 35 (1) | 34 (1) | | 17 (1) | | | | 34 (1) | 33 (1) | | 16 (1) | | | | 33 (1) | 32 (1) | | 15 (1) | | | | 32 (1) | 31 (1) | | 12.1 (1) | | | | 31 (1) | 30 (1) | | 12 (1) | | | | 30 (1) | 29 (1) | | 11.6 (1) | | | | 29 (1) | 28 (1) | | 11.5 | | | | 28 (1) | 27 (1) | | 11.1 | | | | 27 (1) | 26 (1) | | 11 | | | | 26 (1) | 25 (1) | | 10.6 | | | | 25 (1) | 24 (1) | | 10.5 | | | | 24 (1) | 23 (1) | | 10.0-10.1 | | | | 23 (1) | 22 (1) | | 9.5-9.6 | | | | 22 (1) | 21 (1) | | 9 | | | | 21 (1) | 20 (1) | | | | | | 20 (1) | 19 (1) | | | | | | 19 (1) | 18 (1) | | | | | | 18 (1) | 17 (1) | | | | | | 17 (1) | 16 (1) | | | | | | 16 (1) | 15 (1) | | | | | | 15 (1) | 14 (1) | | | | | | 14 (1) | 13 (1) | | | | | | 13 (1) | 12 (1) | | | | | | 12 (1) | 11 (1) | | | | | | 11 (1) | 10 (1) | | | | | | 10 (1) | 9 (1) | | | | | | 9 (1) | 8 (1) | | | | | | 8 (1) | 7 (1) | | | | | | 7 (1) | 6 (1) | | | | | | 6 (1) | 5 (1) | | | | | | 5 (1) | 4 (1) | | | | | | 4 (1) | | | | | | | 3.6 (1) | | | | | | | 3.5 (1) | | | | | | | 3 (1) | | | | | | | 2 (1) | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 (1) | 72 | 108 | 107 | 11 (1) | 13.4 | 19.0 (1) | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 (1) | 7 (1) | 12.1 (1) | | | 10 (1) | | 18.0 (1) | | | | | 16.0 | | 4.4 (1) | | 12 (1) | | | | | 17.0 (1) | | | | | 15.6 (1) | | 4.2-4.3 (1) | | 11.5 (1) | | | | | 16.0 (1) | | | | | [Show all](#) | | 15.5 (1) | | 4.1 (1) | | 11.1 (1) | | | | | 15.0 (1) | | | | | 15.4 (1) | | 4 (1) | | 11 (1) | | | | | 14.0 (1) | | | | | 15.2-15.3 (1) | | 3 (1) | | 10 (1) | | | | | 13.0 (1) | | | | | 15.0-15.1 (1) | | 2.3 (1) | | | | | | | 12.0 (1) | | | | | 14.5-14.8 (1) | | 2.2 | | | | | | | 11.1-11.2 (1) | | | | | 14.0-14.4 (1) | | 2.1 | | | | | | | 10.1 (1) | | | | | 13.4-13.7 (1) | | | | | | | | | 9.2 (1) | | | | | 13.3 (1) | | | | | | | | | 8.2 (1) | | | | | 13.2 (1) | | | | | | | | | 7.2-7.4 (1) | | | | | 13.0-13.1 (1) | | | | | | | | | 6.2-6.4 (1) | | | | | 12.2-12.5 (1) | | | | | | | | | 5.0-5.4 (1) | | | | | 12.0-12.1 (1) | | | | | | | | | 4 (1) | | | | | 11.3-11.4 (1) | | | | | | | | | | | | | | 11.0-11.2 (1) | | | | | | | | | | | | | | 10.3 (1) | | | | | | | | | | | | | | 10.0-10.2 (1) | | | | | | | | | | | | | | 9.3 (1) | | | | | | | | | | | | | | 9.0-9.2 (1) | | | | | | | | | | | | | | 8.1-8.4 (1) | | | | | | | | | | | | | | 8 (1) | | | | | | | | | | | | | | 7.0-7.1 (1) | | | | | | | | | | | | | | 6.0-6.1 (1) | | | | | | | | | | | | | | 5.0-5.1 (1) | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Supports scrollIntoView with boolean parameter, but not `smooth` behavior option Resources --------- * [MDN Web Docs - scrollIntoView](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) * [smooth scroll polyfill : polyfill for smooth behavior option](http://iamdustan.com/smoothscroll/) browser_support_tables ::placeholder CSS pseudo-element ::placeholder CSS pseudo-element ================================ The ::placeholder pseudo-element represents placeholder text in an input field: text that represents the input and provides a hint to the user on how to fill out the form. For example, a date-input field might have the placeholder text `YYYY-MM-DD` to clarify that numeric dates are to be entered in year-month-day order. | | | | --- | --- | | Spec | <https://w3c.github.io/csswg-drafts/css-pseudo-4/#placeholder-pseudo> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 (\*) | 74 | | | 89 | 89 | 89 | 9.1 (\*) | 73 | | | 88 | 88 | 88 | 9 (\*) | 72 | | | 87 | 87 | 87 | 8 (\*) | 71 | | | 86 | 86 | 86 | 7.1 (\*) | 70 | | | 85 | 85 | 85 | 7 (\*) | 69 | | | 84 | 84 | 84 | 6.1 (\*) | 68 | | | 83 | 83 | 83 | 6 (\*) | 67 | | | 81 | 82 | 81 | 5.1 (\*) | 66 | | | 80 | 81 | 80 | 5 (\*) | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 (\*) | 79 | 78 | 3.2 | 63 | | | 17 (\*) | 78 | 77 | 3.1 | 62 | | | 16 (\*) | 77 | 76 | | 60 | | | 15 (\*) | 76 | 75 | | 58 | | | 14 (\*) | 75 | 74 | | 57 | | | 13 (\*) | 74 | 73 | | 56 | | | 12 (\*) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 (\*) | | | | 60 | 59 | | 42 (\*) | | | | 59 | 58 | | 41 (\*) | | | | 58 | 57 | | 40 (\*) | | | | 57 | 56 (\*) | | 39 (\*) | | | | 56 | 55 (\*) | | 38 (\*) | | | | 55 | 54 (\*) | | 37 (\*) | | | | 54 | 53 (\*) | | 36 (\*) | | | | 53 | 52 (\*) | | 35 (\*) | | | | 52 | 51 (\*) | | 34 (\*) | | | | 51 | 50 (\*) | | 33 (\*) | | | | 50 (\*) | 49 (\*) | | 32 (\*) | | | | 49 (\*) | 48 (\*) | | 31 (\*) | | | | 48 (\*) | 47 (\*) | | 30 (\*) | | | | 47 (\*) | 46 (\*) | | 29 (\*) | | | | 46 (\*) | 45 (\*) | | 28 (\*) | | | | 45 (\*) | 44 (\*) | | 27 (\*) | | | | 44 (\*) | 43 (\*) | | 26 (\*) | | | | 43 (\*) | 42 (\*) | | 25 (\*) | | | | 42 (\*) | 41 (\*) | | 24 (\*) | | | | 41 (\*) | 40 (\*) | | 23 (\*) | | | | 40 (\*) | 39 (\*) | | 22 (\*) | | | | 39 (\*) | 38 (\*) | | 21 (\*) | | | | 38 (\*) | 37 (\*) | | 20 (\*) | | | | 37 (\*) | 36 (\*) | | 19 (\*) | | | | 36 (\*) | 35 (\*) | | 18 (\*) | | | | 35 (\*) | 34 (\*) | | 17 (\*) | | | | 34 (\*) | 33 (\*) | | 16 (\*) | | | | 33 (\*) | 32 (\*) | | 15 (\*) | | | | 32 (\*) | 31 (\*) | | 12.1 | | | | 31 (\*) | 30 (\*) | | 12 | | | | 30 (\*) | 29 (\*) | | 11.6 | | | | 29 (\*) | 28 (\*) | | 11.5 | | | | 28 (\*) | 27 (\*) | | 11.1 | | | | 27 (\*) | 26 (\*) | | 11 | | | | 26 (\*) | 25 (\*) | | 10.6 | | | | 25 (\*) | 24 (\*) | | 10.5 | | | | 24 (\*) | 23 (\*) | | 10.0-10.1 | | | | 23 (\*) | 22 (\*) | | 9.5-9.6 | | | | 22 (\*) | 21 (\*) | | 9 | | | | 21 (\*) | 20 (\*) | | | | | | 20 (\*) | 19 (\*) | | | | | | 19 (\*) | 18 (\*) | | | | | | 18 | 17 (\*) | | | | | | 17 | 16 (\*) | | | | | | 16 | 15 (\*) | | | | | | 15 | 14 (\*) | | | | | | 14 | 13 (\*) | | | | | | 13 | 12 (\*) | | | | | | 12 | 11 (\*) | | | | | | 11 | 10 (\*) | | | | | | 10 | 9 (\*) | | | | | | 9 | 8 (\*) | | | | | | 8 | 7 (\*) | | | | | | 7 | 6 (\*) | | | | | | 6 | 5 (\*) | | | | | | 5 | 4 (\*) | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 (\*) | 72 | 108 | 107 | 11 (\*) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (\*) | | 16.1 | | 4.4.3-4.4.4 (\*) | 7 (\*) | 12.1 | | | 10 (\*) | | 18.0 | | | | | 16.0 | | 4.4 (\*) | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 (\*) | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 (\*) | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 (\*) | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 (\*) | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 (\*) | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 (\*) | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 (\*) | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 (\*) | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 (\*) | | | | | 12.0-12.1 | | | | | | | | | 4 (\*) | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 (\*) | | | | | | | | | | | | | | 9.3 (\*) | | | | | | | | | | | | | | 9.0-9.2 (\*) | | | | | | | | | | | | | | 8.1-8.4 (\*) | | | | | | | | | | | | | | 8 (\*) | | | | | | | | | | | | | | 7.0-7.1 (\*) | | | | | | | | | | | | | | 6.0-6.1 (\*) | | | | | | | | | | | | | | 5.0-5.1 (\*) | | | | | | | | | | | | | | 4.2-4.3 (\*) | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Partial support refers to using alternate names: `::-webkit-input-placeholder` for Chrome/Safari/Opera ([Chrome issue #623345](https://bugs.chromium.org/p/chromium/issues/detail?id=623345)) `::-ms-input-placeholder` for Edge (also supports webkit prefix) 1. Firefox 18 and below supported the `:-moz-placeholder` pseudo-class rather than the `::-moz-placeholder` pseudo-element. \* Partial support with prefix. Resources --------- * [CSS-Tricks article with all prefixes](https://css-tricks.com/snippets/css/style-placeholder-text/) * [CSSWG discussion](https://wiki.csswg.org/ideas/placeholder-styling) * [MDN Web Docs - CSS ::-moz-placeholder](https://developer.mozilla.org/en-US/docs/Web/CSS/::-moz-placeholder) * [Mozilla Bug 1069012 - unprefix :placeholder-shown pseudo-class and ::placeholder pseudo-element](https://bugzilla.mozilla.org/show_bug.cgi?id=1069012) * [MDN web docs - ::placeholder](https://developer.mozilla.org/en-US/docs/Web/CSS/::placeholder) browser_support_tables accept attribute for file input accept attribute for file input =============================== Allows a filter to be defined for what type of files a user may pick with from an `<input type="file">` dialog | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/forms.html#attr-input-accept> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 (1) | 76 | | | 91 | 91 | 91 | 10.1 (1) | 75 | | | 90 | 90 | 90 | 10 (1) | 74 | | | 89 | 89 | 89 | 9.1 (1) | 73 | | | 88 | 88 | 88 | 9 (1) | 72 | | | 87 | 87 | 87 | 8 (1) | 71 | | | 86 | 86 | 86 | 7.1 (1) | 70 | | | 85 | 85 | 85 | 7 (1) | 69 | | | 84 | 84 | 84 | 6.1 (1) | 68 | | | 83 | 83 | 83 | 6 (1) | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 (1) | 35 | | 18 | | | | 35 (1) | 34 | | 17 | | | | 34 (1) | 33 | | 16 | | | | 33 (1) | 32 | | 15 | | | | 32 (1) | 31 | | 12.1 | | | | 31 (1) | 30 | | 12 | | | | 30 (1) | 29 | | 11.6 | | | | 29 (1) | 28 | | 11.5 | | | | 28 (1) | 27 | | 11.1 | | | | 27 (1) | 26 | | 11 | | | | 26 (1) | 25 | | 10.6 | | | | 25 (1) | 24 | | 10.5 | | | | 24 (1) | 23 | | 10.0-10.1 | | | | 23 (1) | 22 | | 9.5-9.6 | | | | 22 (1) | 21 | | 9 | | | | 21 (1) | 20 (1) | | | | | | 20 (1) | 19 (1) | | | | | | 19 (1) | 18 (1) | | | | | | 18 (1) | 17 (1) | | | | | | 17 (1) | 16 (1) | | | | | | 16 (1) | 15 (1) | | | | | | 15 (1) | 14 (1) | | | | | | 14 (1) | 13 (1) | | | | | | 13 (1) | 12 (1) | | | | | | 12 (1) | 11 (1) | | | | | | 11 (1) | 10 (1) | | | | | | 10 (1) | 9 (1) | | | | | | 9 (1) | 8 | | | | | | 8 (1) | 7 | | | | | | 7 (1) | 6 | | | | | | 6 (1) | 5 | | | | | | 5 (1) | 4 | | | | | | 4 (1) | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (1) | | | | | | | | | | | | | | 16.2 (1) | all | 108 (3) | 10 (1) | 72 (3) | 108 (2) | 107 | 11 (4) | 13.4 | 19.0 (2) | 13.1 (2) | 13.18 (2) | 2.5 | | 16.1 (1) | | 4.4.3-4.4.4 (3) | 7 (2) | 12.1 | | | 10 (3) | | 18.0 (2) | | | | | 16.0 (1) | | 4.4 (3) | | 12 | | | | | 17.0 (2) | | | | | 15.6 (1) | | 4.2-4.3 (2) | | 11.5 | | | | | 16.0 (2) | | | | | [Show all](#) | | 15.5 (1) | | 4.1 (2) | | 11.1 | | | | | 15.0 (2) | | | | | 15.4 (1) | | 4 (2) | | 11 | | | | | 14.0 (2) | | | | | 15.2-15.3 (1) | | 3 (2) | | 10 | | | | | 13.0 (2) | | | | | 15.0-15.1 (1) | | 2.3 | | | | | | | 12.0 (2) | | | | | 14.5-14.8 (1) | | 2.2 | | | | | | | 11.1-11.2 (2) | | | | | 14.0-14.4 (1) | | 2.1 | | | | | | | 10.1 (2) | | | | | 13.4-13.7 (1) | | | | | | | | | 9.2 (2) | | | | | 13.3 (1) | | | | | | | | | 8.2 (2) | | | | | 13.2 (1) | | | | | | | | | 7.2-7.4 (2) | | | | | 13.0-13.1 (1) | | | | | | | | | 6.2-6.4 (2) | | | | | 12.2-12.5 (1) | | | | | | | | | 5.0-5.4 (2) | | | | | 12.0-12.1 (1) | | | | | | | | | 4 (2) | | | | | 11.3-11.4 (1) | | | | | | | | | | | | | | 11.0-11.2 (1) | | | | | | | | | | | | | | 10.3 (1) | | | | | | | | | | | | | | 10.0-10.2 (1) | | | | | | | | | | | | | | 9.3 (1) | | | | | | | | | | | | | | 9.0-9.2 (1) | | | | | | | | | | | | | | 8.1-8.4 (1) | | | | | | | | | | | | | | 8 (1) | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 (3) | | | | | | | | | | | | | | 4.2-4.3 (3) | | | | | | | | | | | | | | 4.0-4.1 (3) | | | | | | | | | | | | | | 3.2 (3) | | | | | | | | | | | | | Notes ----- Not supported means any file can be picked as if the `accept` attribute was not set, unless otherwise noted. On Windows, files that do not apply are hidden. On OSX they are grayed out and disabled. 1. Supports the type format (e.g. `image/*`) but not the extension format (e.g. `.png`) 2. Offers appropriate file locations/input based on format type, but does not prevent other files from being selected. 3. Does not allow any files to be picked at all 4. Supports the type format but does not allow any file to be picked when using the extension format Resources --------- * [Demo & information](https://www.wufoo.com/html5/attributes/07-accept.html)
programming_docs
browser_support_tables CSS.supports() API CSS.supports() API ================== The CSS.supports() static methods returns a Boolean value indicating if the browser supports a given CSS feature, or not. | | | | --- | --- | | Spec | <https://w3c.github.io/csswg-drafts/css-conditional/#the-css-interface> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 (2) | 79 | 78 | 3.2 | 63 | | | 17 (2) | 78 | 77 | 3.1 | 62 | | | 16 (2) | 77 | 76 | | 60 | | | 15 (2) | 76 | 75 | | 58 | | | 14 (2) | 75 | 74 | | 57 | | | 13 (2) | 74 | 73 | | 56 | | | 12 (2) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 (2) | | 43 | | | | 60 | 59 (2) | | 42 | | | | 59 | 58 (2) | | 41 | | | | 58 | 57 (2) | | 40 | | | | 57 | 56 (2) | | 39 | | | | 56 | 55 (2) | | 38 | | | | 55 | 54 (2) | | 37 | | | | 54 (2) | 53 (2) | | 36 | | | | 53 (2) | 52 (2) | | 35 | | | | 52 (2) | 51 (2) | | 34 | | | | 51 (2) | 50 (2) | | 33 | | | | 50 (2) | 49 (2) | | 32 | | | | 49 (2) | 48 (2) | | 31 | | | | 48 (2) | 47 (2) | | 30 | | | | 47 (2) | 46 (2) | | 29 | | | | 46 (2) | 45 (2) | | 28 | | | | 45 (2) | 44 (2) | | 27 | | | | 44 (2) | 43 (2) | | 26 | | | | 43 (2) | 42 (2) | | 25 | | | | 42 (2) | 41 (2) | | 24 | | | | 41 (2) | 40 (2) | | 23 | | | | 40 (2) | 39 (2) | | 22 | | | | 39 (2) | 38 (2) | | 21 | | | | 38 (2) | 37 (2) | | 20 | | | | 37 (2) | 36 (2) | | 19 | | | | 36 (2) | 35 (2) | | 18 | | | | 35 (2) | 34 (2) | | 17 | | | | 34 (2) | 33 (2) | | 16 | | | | 33 (2) | 32 (2) | | 15 | | | | 32 (2) | 31 (2) | | 12.1 (1) | | | | 31 (2) | 30 (2) | | 12 | | | | 30 (2) | 29 (2) | | 11.6 | | | | 29 (2) | 28 (2) | | 11.5 | | | | 28 (2) | 27 | | 11.1 | | | | 27 (2) | 26 | | 11 | | | | 26 (2) | 25 | | 10.6 | | | | 25 (2) | 24 | | 10.5 | | | | 24 (2) | 23 | | 10.0-10.1 | | | | 23 (2) | 22 | | 9.5-9.6 | | | | 22 (2) | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all (1) | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 (1) | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- See also [@supports in CSS](css-featurequeries) 1. Partial support in Presto-based Opera browsers refers to using an older API (`window.supportsCSS`) 2. Does not support parentheses-less one-argument version. Resources --------- * [MDN Web Docs - CSS supports()](https://developer.mozilla.org/en-US/docs/Web/API/CSS.supports) * [Demo (Chinese)](https://jsbin.com/rimevilotari/1/edit?html,output) * [Native CSS Feature Detection via the @supports Rule](https://dev.opera.com/articles/native-css-feature-detection/) * [CSS @supports](https://davidwalsh.name/css-supports) * [Article (Chinese)](https://blog.csdn.net/hfahe/article/details/8619480) browser_support_tables Vibration API Vibration API ============= Method to access the vibration mechanism of the hosting device. | | | | --- | --- | | Spec | <https://www.w3.org/TR/vibration/> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 (\*) | 14 | | | | | | 14 (\*) | 13 | | | | | | 13 (\*) | 12 | | | | | | 12 (\*) | 11 | | | | | | 11 (\*) | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- \* Partial support with prefix. Resources --------- * [MDN Web Docs - Vibration](https://developer.mozilla.org/en-US/docs/Web/Guide/API/Vibration) * [Vibration API sample code & demo](https://davidwalsh.name/vibration-api) * [Tuts+ article](https://code.tutsplus.com/tutorials/html5-vibration-api--mobile-22585) * [Demo](https://audero.it/demo/vibration-api-demo.html) * [Article and Usage Examples](https://www.illyism.com/journal/vibrate-mobile-phone-web-vibration-api/) browser_support_tables JSON parsing JSON parsing ============ Method of converting JavaScript objects to JSON strings and JSON back to objects using JSON.stringify() and JSON.parse() | | | | --- | --- | | Spec | <https://www.ecma-international.org/ecma-262/5.1/#sec-15.12> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 (1) | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Requires document to be in IE8+ [standards mode](http://msdn.microsoft.com/en-us/library/cc288325%28VS.85%29.aspx) to work in IE8. Bugs ---- * IE9-IE11 fail to call the "reviver" argument recursively (in some versions of windows). [see discussion](https://github.com/Fyrd/caniuse/issues/1653) Resources --------- * [MDN Web Docs - Working with JSON](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON) * [JSON in JS (includes script w/support)](https://www.json.org/json-en.html) * [has.js test](https://raw.github.com/phiggins42/has.js/master/detect/json.js#json) * [WebPlatform Docs](https://webplatform.github.io/docs/apis/json) * [JSON explainer](https://www.json.org/) browser_support_tables Video element Video element ============= Method of playing videos on webpages (without requiring a plug-in). Includes support for the following media properties: `currentSrc`, `currentTime`, `paused`, `playbackRate`, `buffered`, `duration`, `played`, `seekable`, `ended`, `autoplay`, `loop`, `controls`, `volume` & `muted` | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/embedded-content.html#the-video-element> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP (3) | | | | | 109 | 109 | 16.3 (3) | | | 11 | 108 | 108 | 108 | 16.2 (3) | 92 | | 10 | 107 | 107 | 107 | 16.1 (3) | 91 | | 9 | 106 | 106 | 106 | 16.0 (3) | 90 | | 8 | 105 | 105 | 105 | 15.6 (3) | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 (3) | 88 | | 6 | 103 | 103 | 103 | 15.4 (3) | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 (3) | 86 | | | 101 | 101 | 101 | 15.1 (3) | 85 | | | 100 | 100 | 100 | 15 (3) | 84 | | | 99 | 99 | 99 | 14.1 (3) | 83 | | | 98 | 98 | 98 | 14 (3) | 82 | | | 97 | 97 | 97 | 13.1 (3) | 81 | | | 96 | 96 | 96 | 13 (3) | 80 | | | 95 | 95 | 95 | 12.1 (3) | 79 | | | 94 | 94 | 94 | 12 (3) | 78 | | | 93 | 93 | 93 | 11.1 (3) | 77 | | | 92 | 92 | 92 | 11 (3) | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 (2) | 18 | | | | | | 18 (2) | 17 | | | | | | 17 (2) | 16 | | | | | | 16 (2) | 15 | | | | | | 15 (2) | 14 | | | | | | 14 (2) | 13 | | | | | | 13 (2) | 12 | | | | | | 12 (2) | 11 | | | | | | 11 (2) | 10 | | | | | | 10 (2) | 9 | | | | | | 9 (2) | 8 | | | | | | 8 (2) | 7 | | | | | | 7 (2) | 6 | | | | | | 6 (2) | 5 | | | | | | 5 (2) | 4 | | | | | | 4 (2) | | | | | | | 3.6 (2) | | | | | | | 3.5 (2) | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (3) | | | | | | | | | | | | | | 16.2 (3) | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 (3) | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 (3) | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 (3) | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 (3) | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 (3) | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 (3) | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 (3) | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 (3) | | 2.2 (1) | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (3) | | 2.1 (1) | | | | | | | 10.1 | | | | | 13.4-13.7 (3) | | | | | | | | | 9.2 | | | | | 13.3 (3) | | | | | | | | | 8.2 | | | | | 13.2 (3) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (3) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (3) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 (3) | | | | | | | | | 4 | | | | | 11.3-11.4 (3) | | | | | | | | | | | | | | 11.0-11.2 (3) | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Different browsers have support for different video formats, see sub-features for details. 1. The Android browser (before 2.3) requires [specific handling](http://www.broken-links.com/2010/07/08/making-html5-video-work-on-android-phones/) to run the video element. 2. Old Firefox versions were missing support for some properties: `loop` was added in v11, `played` in v15, `playbackRate` in v20. 3. Ignores the `autoplay` attribute by default, though autoplay behavior can be [enabled by users](https://webkit.org/blog/7734/auto-play-policy-changes-for-macos/) Bugs ---- * The default [media playback controls are not displayed](https://www.ctrl.blog/entry/safari-csp-media-controls) with a strict Content-Security-Policy in Safari 11 and 12 unless you allow loading images from data URIs. (`img-src data:`, like `unsafe-inline`). Resources --------- * [Detailed article on video/audio elements](https://dev.opera.com/articles/everything-you-need-to-know-html5-video-audio/) * [WebM format information](https://www.webmproject.org) * [Video for Everybody](http://camendesign.co.uk/code/video_for_everybody) * [Video on the Web - includes info on Android support](http://diveintohtml5.info/video.html) * [has.js test](https://raw.github.com/phiggins42/has.js/master/detect/video.js#video) * [WebPlatform Docs](https://webplatform.github.io/docs/html/elements/video)
programming_docs
browser_support_tables Web Sockets Web Sockets =========== Bidirectional communication technology for web apps | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/comms.html#network> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 (2) | 68 | | | 83 | 83 | 83 | 6 (2) | 67 | | | 81 | 82 | 81 | 5.1 (1) | 66 | | | 80 | 81 | 80 | 5 (1) | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 (1) | | | | 30 | 29 | | 11.6 (1) | | | | 29 | 28 | | 11.5 (1) | | | | 28 | 27 | | 11.1 (1) | | | | 27 | 26 | | 11 (1) | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 (2) | | | | | | 15 | 14 (1) | | | | | | 14 | 13 (1) | | | | | | 13 | 12 (1) | | | | | | 12 | 11 (1) | | | | | | 11 | 10 (1) | | | | | | 10 (2,\*) | 9 (1) | | | | | | 9 (2,\*) | 8 (1) | | | | | | 8 (2,\*) | 7 (1) | | | | | | 7 (2,\*) | 6 (1) | | | | | | 6 (2,\*) | 5 (1) | | | | | | 5 (1) | 4 (1) | | | | | | 4 (1) | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 (1) | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 (1) | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 (1) | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 (1) | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 (1) | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 (1) | | | | | | | | | | | | | | 4.2-4.3 (1) | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Reported to be supported in some Android 4.x browsers, including Sony Xperia S, Sony TX and HTC. 1. Partial support in older browsers refers to the websockets implementation using an older version of the protocol and/or the implementation being disabled by default (due to security issues with the older protocol). 2. Partial support in older browsers refers to lacking support for binary data. \* Partial support with prefix. Bugs ---- * Firefox 37 and lower cannot host a WebSocket within a WebWorker context Resources --------- * [Details on newer protocol](https://developer.chrome.com/blog/what-s-different-in-the-new-websocket-protocol/) * [Wikipedia](https://en.wikipedia.org/wiki/WebSocket) * [has.js test](https://raw.github.com/phiggins42/has.js/master/detect/features.js#native-websockets) * [WebPlatform Docs](https://webplatform.github.io/docs/apis/websocket) * [MDN Web Docs - WebSockets API](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) browser_support_tables Web NFC Web NFC ======= This API allows a website to communicate with NFC tags through a device's NFC reader. | | | | --- | --- | | Spec | <https://w3c.github.io/web-nfc/> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 (1,2) | | 10 | 107 | 107 | 107 | 16.1 | 91 (1,2) | | 9 | 106 | 106 | 106 | 16.0 | 90 (1,2) | | 8 | 105 | 105 | 105 | 15.6 | 89 (1,2) | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 (1,2) | | 6 | 103 | 103 | 103 | 15.4 | 87 (1,2) | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 (1,2) | | | 101 | 101 | 101 | 15.1 | 85 (1,2) | | | 100 | 100 | 100 | 15 | 84 (1,2) | | | 99 | 99 | 99 | 14.1 | 83 (1,2) | | | 98 | 98 | 98 | 14 | 82 (1,2) | | | 97 | 97 | 97 | 13.1 | 81 (1,2) | | | 96 | 96 | 96 | 13 | 80 (1,2) | | | 95 | 95 | 95 | 12.1 | 79 (1,2) | | | 94 | 94 | 94 | 12 | 78 (1,2) | | | 93 | 93 | 93 | 11.1 | 77 (1,2) | | | 92 | 92 | 92 | 11 | 76 (1,2) | | | 91 | 91 | 91 | 10.1 | 75 (1,2) | | | 90 | 90 | 90 | 10 | 74 (1,2) | | | 89 | 89 | 89 | 9.1 | 73 (1,2) | | | 88 (1,2) | 88 | 88 (1,2) | 9 | 72 (1,2) | | | 87 (1,2) | 87 | 87 (1,2) | 8 | 71 (1,2) | | | 86 (1,2) | 86 | 86 (1,2) | 7.1 | 70 (1,2) | | | 85 (1,2) | 85 | 85 (1,2) | 7 | 69 (1,2) | | | 84 (1,2) | 84 | 84 (1,2) | 6.1 | 68 (1,2) | | | 83 (1,2) | 83 | 83 (1,2) | 6 | 67 (1,2) | | | 81 (1,2) | 82 | 81 (1,2) | 5.1 | 66 | | | 80 (1,2) | 81 | 80 (1,2) | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 (2) | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Many devices are not equipped with NFC readers. They won't return any data, even though an installed browser might support this API. 1. Was experimentally supported in desktop Chromium browsers behind the `enable-experimental-web-platform-features` flag. 2. Current implementations only allow communication through the NDEF protocol in order to minimize security and privacy issues. Resources --------- * [Safari position: Opposed](https://lists.webkit.org/pipermail/webkit-dev/2020-January/031007.html) * [Firefox position: Harmful](https://mozilla.github.io/standards-positions/#web-nfc) * [Web.dev article on using WebNFC](https://web.dev/nfc/) browser_support_tables Gamepad API Gamepad API =========== API to support input from USB gamepad controllers through JavaScript. | | | | --- | --- | | Spec | <https://www.w3.org/TR/gamepad/> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 (\*) | | 10.5 | | | | 24 | 23 (\*) | | 10.0-10.1 | | | | 23 | 22 (\*) | | 9.5-9.6 | | | | 22 | 21 (\*) | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled via the "Experimental Features" developer menu \* Partial support with prefix. Resources --------- * [Controller demo](https://luser.github.io/gamepadtest/) * [MDN Web Docs - Gamepad](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API) * [HTML5Rocks article](https://www.html5rocks.com/en/tutorials/doodles/gamepad/) * [Detailed tutorial](https://gamedevelopment.tutsplus.com/tutorials/using-the-html5-gamepad-api-to-add-controller-support-to-browser-games--cms-21345)
programming_docs
browser_support_tables ChaCha20-Poly1305 cipher suites for TLS ChaCha20-Poly1305 cipher suites for TLS ======================================= A set of cipher suites used in Transport Layer Security (TLS) protocol, using ChaCha20 for symmetric encryption and Poly1305 for authentication. | | | | --- | --- | | Spec | <https://tools.ietf.org/html/rfc7905> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 (1) | | 31 | | | | 48 | 47 (1) | | 30 | | | | 47 | 46 (1) | | 29 | | | | 46 | 45 (1) | | 28 | | | | 45 | 44 (1) | | 27 | | | | 44 | 43 (1) | | 26 | | | | 43 | 42 (1) | | 25 | | | | 42 | 41 (1) | | 24 | | | | 41 | 40 (1) | | 23 | | | | 40 | 39 (1) | | 22 | | | | 39 | 38 (1) | | 21 | | | | 38 | 37 (1) | | 20 | | | | 37 | 36 (1) | | 19 | | | | 36 | 35 (1) | | 18 | | | | 35 | 34 (1) | | 17 | | | | 34 | 33 (1) | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Old versions of Chrome use non-standard code points for ChaCha20-Poly1305 cipher suites. Resources --------- * [Chrome article](https://security.googleblog.com/2014/04/speeding-up-and-strengthening-https.html) * [SSL/TLS Capabilities of Your Browser by Qualys SSL Labs](https://www.ssllabs.com/ssltest/viewMyClient.html) browser_support_tables :optional CSS pseudo-class :optional CSS pseudo-class ========================== The `:optional` pseudo-class matches form inputs (`<input>`, `<textarea>`, `<select>`) which are not `:required`. | | | | --- | --- | | Spec | <https://www.w3.org/TR/selectors-4/#optional-pseudo> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 (1) | | | | 31 | 30 | | 12 (1) | | | | 30 | 29 | | 11.6 (1) | | | | 29 | 28 | | 11.5 (1) | | | | 28 | 27 | | 11.1 (1) | | | | 27 | 26 | | 11 (1) | | | | 26 | 25 | | 10.6 (1) | | | | 25 | 24 | | 10.5 (1) | | | | 24 | 23 | | 10.0-10.1 (1) | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all (1) | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 (1) | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 (1) | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 (1) | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 (1) | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 (1) | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 (1) | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Does not match non-required `<select>`s Resources --------- * [HTML specification for `:optional`](https://html.spec.whatwg.org/multipage/scripting.html#selector-optional) * [MDN Web Docs - CSS :optional](https://developer.mozilla.org/en-US/docs/Web/CSS/:optional) * [JS Bin testcase](https://jsbin.com/fihudu/edit?html,css,output) browser_support_tables progress element progress element ================ Method of indicating a progress state. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/forms.html#the-progress-element> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 (1) | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. does not support "indeterminate" <progress> elements. Resources --------- * [CSS-Tricks article](https://css-tricks.com/html5-progress-element/) * [MDN Web Docs - Element progress](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress) * [Dev.Opera article](https://dev.opera.com/articles/new-form-features-in-html5/#newoutput) * [Examples of progress and meter elements](https://peter.sh/examples/?/html/meter-progress.html) browser_support_tables CSS Font Loading CSS Font Loading ================ This CSS module defines a scripting interface to font faces in CSS, allowing font faces to be easily created and loaded from script. It also provides methods to track the loading status of an individual font, or of all the fonts on an entire page. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css-font-loading-3/> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 (1) | 39 | | 22 | | | | 39 (1) | 38 | | 21 | | | | 38 (1) | 37 | | 20 | | | | 37 (1) | 36 | | 19 | | | | 36 (1) | 35 | | 18 | | | | 35 (1) | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled in Firefox using the `layout.css.font-loading-api.enabled` flag. Enabled by default in Firefox 41. See [this bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1149381) Bugs ---- * If \_none\_ of the specified fonts exist, `FontFaceSet.check()` should [return `true`](https://drafts.csswg.org/css-font-loading/#font-face-set-check) due to [the privacy concern](https://github.com/w3c/csswg-drafts/issues/5744) regarding fingerprinting. Chrome/Blink-based browsers return `false`. Resources --------- * [Optimizing with font load events](https://www.igvita.com/2014/01/31/optimizing-web-font-rendering-performance/#font-load-events)
programming_docs
browser_support_tables Date and time input types Date and time input types ========================= Form field widgets to easily allow users to enter a date, time or both, generally by using a calendar/time input widget. Refers to supporting the following input types: `date`, `time`, `datetime-local`, `month` & `week`. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/forms.html#date-state-(type=date)> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 (6) | 110 | TP (6) | | | | | 109 (6) | 109 | 16.3 (6) | | | 11 | 108 | 108 (6) | 108 | 16.2 (6) | 92 | | 10 | 107 | 107 (6) | 107 | 16.1 (6) | 91 | | 9 | 106 | 106 (6) | 106 | 16.0 (6) | 90 | | 8 | 105 | 105 (6) | 105 | 15.6 (6) | 89 | | [Show all](#) | | 7 | 104 | 104 (6) | 104 | 15.5 (6) | 88 | | 6 | 103 | 103 (6) | 103 | 15.4 (6) | 87 | | 5.5 | 102 | 102 (6) | 102 | 15.2-15.3 (6) | 86 | | | 101 | 101 (6) | 101 | 15.1 (6) | 85 | | | 100 | 100 (6) | 100 | 15 (6) | 84 | | | 99 | 99 (6) | 99 | 14.1 (6) | 83 | | | 98 | 98 (6) | 98 | 14 | 82 | | | 97 | 97 (6) | 97 | 13.1 | 81 | | | 96 | 96 (6) | 96 | 13 | 80 | | | 95 | 95 (6) | 95 | 12.1 | 79 | | | 94 | 94 (6) | 94 | 12 | 78 | | | 93 | 93 (6) | 93 | 11.1 | 77 | | | 92 | 92 (5) | 92 | 11 | 76 | | | 91 | 91 (5) | 91 | 10.1 | 75 | | | 90 | 90 (5) | 90 | 10 | 74 | | | 89 | 89 (5) | 89 | 9.1 | 73 | | | 88 | 88 (5) | 88 | 9 | 72 | | | 87 | 87 (5) | 87 | 8 | 71 | | | 86 | 86 (5) | 86 | 7.1 | 70 | | | 85 | 85 (5) | 85 | 7 | 69 | | | 84 | 84 (5) | 84 | 6.1 | 68 | | | 83 | 83 (5) | 83 | 6 | 67 | | | 81 | 82 (5) | 81 | 5.1 | 66 | | | 80 | 81 (5) | 80 | 5 | 65 | | | 79 | 80 (5) | 79 | 4 | 64 | | | 18 | 79 (5) | 78 | 3.2 | 63 | | | 17 | 78 (5) | 77 | 3.1 | 62 | | | 16 | 77 (5) | 76 | | 60 | | | 15 | 76 (5) | 75 | | 58 | | | 14 | 75 (5) | 74 | | 57 | | | 13 | 74 (5) | 73 | | 56 | | | 12 (1) | 73 (5) | 72 | | 55 | | | | 72 (5) | 71 | | 54 | | | | 71 (5) | 70 | | 53 | | | | 70 (5) | 69 | | 52 | | | | 69 (5) | 68 | | 51 | | | | 68 (5) | 67 | | 50 | | | | 67 (5) | 66 | | 49 | | | | 66 (5) | 65 | | 48 | | | | 65 (5) | 64 | | 47 | | | | 64 (5) | 63 | | 46 | | | | 63 (5) | 62 | | 45 | | | | 62 (5) | 61 | | 44 | | | | 61 (5) | 60 | | 43 | | | | 60 (5) | 59 | | 42 | | | | 59 (5) | 58 | | 41 | | | | 58 (5) | 57 | | 40 | | | | 57 (5) | 56 | | 39 | | | | 56 (4) | 55 | | 38 | | | | 55 (4) | 54 | | 37 | | | | 54 (4) | 53 | | 36 | | | | 53 (4) | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 (5) | | 10.5 | | | | 24 | 23 (5) | | 10.0-10.1 | | | | 23 | 22 (5) | | 9.5-9.6 | | | | 22 | 21 (5) | | 9 | | | | 21 | 20 (5) | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (2) | | | | | | | | | | | | | | 16.2 (2) | all | 108 | 10 | 72 | 108 | 107 (6) | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (5) | | 16.1 (2) | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 (2) | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 (2) | | 4.2-4.3 (3) | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 (2) | | 4.1 (3) | | 11.1 | | | | | 15.0 | | | | | 15.4 (2) | | 4 (3) | | 11 | | | | | 14.0 | | | | | 15.2-15.3 (2) | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 (2) | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 (2) | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (2) | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (2) | | | | | | | | | 9.2 | | | | | 13.3 (2) | | | | | | | | | 8.2 | | | | | 13.2 (2) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (2) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (2) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 (2) | | | | | | | | | 4 | | | | | 11.3-11.4 (2) | | | | | | | | | | | | | | 11.0-11.2 (2) | | | | | | | | | | | | | | 10.3 (2) | | | | | | | | | | | | | | 10.0-10.2 (2) | | | | | | | | | | | | | | 9.3 (2) | | | | | | | | | | | | | | 9.0-9.2 (2) | | | | | | | | | | | | | | 8.1-8.4 (2) | | | | | | | | | | | | | | 8 (2) | | | | | | | | | | | | | | 7.0-7.1 (2) | | | | | | | | | | | | | | 6.0-6.1 (2) | | | | | | | | | | | | | | 5.0-5.1 (2) | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- There used to also be a `datetime` type, but it was [dropped from the HTML spec](https://github.com/whatwg/html/issues/336). 1. Partial support in Microsoft Edge refers to supporting `date`, `week`, and `month` input types, and not `time` and `datetime-local`. 2. Partial support in iOS Safari refers to not supporting the `week` input type, nor the `min`, `max` or `step` attributes 3. Some modified versions of the Android 4.x browser do have support for date/time fields. 4. Can be enabled in Firefox using the `dom.forms.datetime` flag. 5. Partial support refers to supporting `date` and `time` input types, but not `datetime-local`, `month` or `week`. 6. Partial support refers to not supporting the `week` and `month` input type Resources --------- * [Datepicker tutorial w/polyfill](https://code.tutsplus.com/tutorials/quick-tip-create-cross-browser-datepickers-in-minutes--net-20236) * [Polyfill for HTML5 forms](https://github.com/zoltan-dulac/html5Forms.js) * [has.js test](https://raw.github.com/phiggins42/has.js/master/detect/form.js#input-type-datetime-local) * [WebPlatform Docs](https://webplatform.github.io/docs/html/elements/input/type/date) * [Bug on Firefox support](https://bugzilla.mozilla.org/show_bug.cgi?id=888320) * [Bug for WebKit/Safari](https://bugs.webkit.org/show_bug.cgi?id=119175) * [Bug for WebKit/Safari](https://bugs.webkit.org/show_bug.cgi?id=214946) browser_support_tables Channel messaging Channel messaging ================= Method for having two-way communication between browsing contexts (using MessageChannel) | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/comms.html#channel-messaging> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 (1) | 39 | | 22 | | | | 39 (1) | 38 | | 21 | | | | 38 (1) | 37 | | 20 | | | | 37 (1) | 36 | | 19 | | | | 36 (1) | 35 | | 18 | | | | 35 (1) | 34 | | 17 | | | | 34 (1) | 33 | | 16 | | | | 33 (1) | 32 | | 15 | | | | 32 (1) | 31 | | 12.1 | | | | 31 (1) | 30 | | 12 | | | | 30 (1) | 29 | | 11.6 | | | | 29 (1) | 28 | | 11.5 | | | | 28 (1) | 27 | | 11.1 | | | | 27 (1) | 26 | | 11 | | | | 26 (1) | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Supported in Firefox behind the `dom.messageChannel.enabled` flag. Reported to not work in web workers before version 41. Resources --------- * [An Introduction to HTML5 web messaging](https://dev.opera.com/articles/view/window-postmessage-messagechannel/#channel) * [MDN Web Docs - Channel Messaging API](https://developer.mozilla.org/en-US/docs/Web/API/Channel_Messaging_API) browser_support_tables display: flow-root display: flow-root ================== The element generates a block container box, and lays out its contents using flow layout. It always establishes a new block formatting context for its contents. It provides a better solution to the most use cases of the "clearfix" hack. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css-display-3/#valdef-display-flow-root> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Mozilla bug report](https://bugzilla.mozilla.org/show_bug.cgi?id=1322191) * [Chromium bug report](https://bugs.chromium.org/p/chromium/issues/detail?id=672508) * [WebKit bug report](https://bugs.webkit.org/show_bug.cgi?id=165603) * [Blog post: "The end of the clearfix hack?"](https://rachelandrew.co.uk/archives/2017/01/24/the-end-of-the-clearfix-hack/)
programming_docs
browser_support_tables Constraint Validation API Constraint Validation API ========================= API for better control over form field validation. Includes support for `checkValidity()`, `setCustomValidity()`, `reportValidity()` and validation states. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/dev/form-control-infrastructure.html#the-constraint-validation-api> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (1,2,3) | 108 | 108 | 108 | 16.2 | 92 | | 10 (1,2,3) | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 (1,2) | 73 | | | 88 | 88 | 88 | 9 (1,2) | 72 | | | 87 | 87 | 87 | 8 (1,2) | 71 | | | 86 | 86 | 86 | 7.1 (1,2) | 70 | | | 85 | 85 | 85 | 7 (1,2,3) | 69 | | | 84 | 84 | 84 | 6.1 (1,2,3) | 68 | | | 83 | 83 | 83 | 6 (1,2,3) | 67 | | | 81 | 82 | 81 | 5.1 (1,2,3) | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 (1,2) | 77 | 76 | | 60 | | | 15 (1,2) | 76 | 75 | | 58 | | | 14 (1,2) | 75 | 74 | | 57 | | | 13 (1,2,3) | 74 | 73 | | 56 | | | 12 (1,2,3) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 (2) | 49 | | 32 | | | | 49 (2) | 48 | | 31 | | | | 48 (1,2) | 47 | | 30 | | | | 47 (1,2) | 46 | | 29 | | | | 46 (1,2) | 45 | | 28 | | | | 45 (1,2) | 44 | | 27 | | | | 44 (1,2) | 43 | | 26 (1,2) | | | | 43 (1,2) | 42 | | 25 (1,2) | | | | 42 (1,2) | 41 | | 24 (1,2) | | | | 41 (1,2) | 40 | | 23 (1,2) | | | | 40 (1,2) | 39 (1,2) | | 22 (1,2) | | | | 39 (1,2) | 38 (1,2) | | 21 (1,2) | | | | 38 (1,2) | 37 (1,2) | | 20 (1,2) | | | | 37 (1,2) | 36 (1,2) | | 19 (1,2) | | | | 36 (1,2) | 35 (1,2) | | 18 (1,2) | | | | 35 (1,2) | 34 (1,2) | | 17 (1,2) | | | | 34 (1,2) | 33 (1,2) | | 16 (1,2) | | | | 33 (1,2) | 32 (1,2) | | 15 (1,2) | | | | 32 (1,2) | 31 (1,2) | | 12.1 (1,2,3) | | | | 31 (1,2) | 30 (1,2) | | 12 (1,2,3) | | | | 30 (1,2) | 29 (1,2) | | 11.6 (1,2,3) | | | | 29 (1,2) | 28 (1,2) | | 11.5 | | | | 28 (1,2,3) | 27 (1,2) | | 11.1 | | | | 27 (1,2,3) | 26 (1,2) | | 11 | | | | 26 (1,2,3) | 25 (1,2) | | 10.6 | | | | 25 (1,2,3) | 24 (1,2,3) | | 10.5 | | | | 24 (1,2,3) | 23 (1,2,3) | | 10.0-10.1 | | | | 23 (1,2,3) | 22 (1,2,3) | | 9.5-9.6 | | | | 22 (1,2,3) | 21 (1,2,3) | | 9 | | | | 21 (1,2,3) | 20 (1,2,3) | | | | | | 20 (1,2,3) | 19 (1,2,3) | | | | | | 19 (1,2,3) | 18 (1,2,3) | | | | | | 18 (1,2,3) | 17 (1,2,3) | | | | | | 17 (1,2,3) | 16 (1,2,3) | | | | | | 16 (1,2,3) | 15 (1,2,3) | | | | | | 15 (1,2,3) | 14 | | | | | | 14 (1,2,3) | 13 | | | | | | 13 (1,2,3) | 12 | | | | | | 12 (1,2,3) | 11 | | | | | | 11 (1,2,3) | 10 | | | | | | 10 (1,2,3) | 9 | | | | | | 9 (1,2,3) | 8 | | | | | | 8 (1,2,3) | 7 | | | | | | 7 (1,2,3) | 6 | | | | | | 6 (1,2,3) | 5 | | | | | | 5 (1,2,3) | 4 | | | | | | 4 (1,2,3) | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 (1,2) | 72 | 108 | 107 | 11 (1,2,3) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (1,2) | | 16.1 | | 4.4.3-4.4.4 (1,2) | 7 | 12.1 (1,2,3) | | | 10 (1,2,3) | | 18.0 | | | | | 16.0 | | 4.4 (1,2) | | 12 (1,2,3) | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 (1,2,3) | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 (1,2,3) | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 (1,2,3) | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 (1,2) | | | | | | | | | | | | | | 9.0-9.2 (1,2) | | | | | | | | | | | | | | 8.1-8.4 (1,2) | | | | | | | | | | | | | | 8 (1,2) | | | | | | | | | | | | | | 7.0-7.1 (1,2) | | | | | | | | | | | | | | 6.0-6.1 (1,2,3) | | | | | | | | | | | | | | 5.0-5.1 (1,2,3) | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Does not support `reportValidity` 2. Does not support `validity.tooShort`. See also [support for `minlength`.](https://caniuse.com/#feat=input-minlength) 3. Does not support `validity.badInput` Resources --------- * [MDN article on constraint validation](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation) * [`reportValidity()` ponyfill](https://github.com/jelmerdemaat/report-validity) browser_support_tables Blob constructing Blob constructing ================= Construct Blobs (binary large objects) either using the BlobBuilder API (deprecated) or the Blob constructor. | | | | --- | --- | | Spec | <https://www.w3.org/TR/FileAPI/#constructorBlob> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 (\*) | | | | | | 19 | 18 (\*) | | | | | | 18 | 17 (\*) | | | | | | 17 | 16 (\*) | | | | | | 16 | 15 (\*) | | | | | | 15 | 14 (\*) | | | | | | 14 | 13 (\*) | | | | | | 13 | 12 (\*) | | | | | | 12 (\*) | 11 (\*) | | | | | | 11 (\*) | 10 (\*) | | | | | | 10 (\*) | 9 (\*) | | | | | | 9 (\*) | 8 (\*) | | | | | | 8 (\*) | 7 | | | | | | 7 (\*) | 6 | | | | | | 6 (\*) | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 (\*) | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 (\*) | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 (\*) | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 (\*) | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 (\*) | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 (\*) | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Partial support refers to only supporting the now deprecated BlobBuilder to create blobs. \* Partial support with prefix. Resources --------- * [MDN Web Docs - BlobBuilder](https://developer.mozilla.org/en/DOM/BlobBuilder) * [MDN Web Docs - Blobs](https://developer.mozilla.org/en-US/docs/DOM/Blob) browser_support_tables Promises Promises ======== A promise represents the eventual result of an asynchronous operation. | | | | --- | --- | | Spec | <https://tc39.es/ecma262/#sec-promise-objects> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Promises/A+ spec](https://promisesaplus.com/) * [JavaScript Promises: There and back again - HTML5 Rocks](https://www.html5rocks.com/en/tutorials/es6/promises/) * [A polyfill for ES6-style Promises](https://github.com/jakearchibald/ES6-Promises) * [Polyfill for this feature is available in the core-js library](https://github.com/zloirock/core-js#ecmascript-promise) browser_support_tables AAC audio file format AAC audio file format ===================== Advanced Audio Coding format, designed to be the successor format to MP3, with generally better sound quality. | | | | --- | --- | | Spec | <http://www.digitalpreservation.gov/formats/fdd/fdd000114.shtml> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 (1) | 110 | TP | | | | | 109 (1) | 109 | 16.3 | | | 11 | 108 | 108 (1) | 108 | 16.2 | 92 | | 10 | 107 | 107 (1) | 107 | 16.1 | 91 | | 9 | 106 | 106 (1) | 106 | 16.0 | 90 | | 8 | 105 | 105 (1) | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 (1) | 104 | 15.5 | 88 | | 6 | 103 | 103 (1) | 103 | 15.4 | 87 | | 5.5 | 102 | 102 (1) | 102 | 15.2-15.3 | 86 | | | 101 | 101 (1) | 101 | 15.1 | 85 | | | 100 | 100 (1) | 100 | 15 | 84 | | | 99 | 99 (1) | 99 | 14.1 | 83 | | | 98 | 98 (1) | 98 | 14 | 82 | | | 97 | 97 (1) | 97 | 13.1 | 81 | | | 96 | 96 (1) | 96 | 13 | 80 | | | 95 | 95 (1) | 95 | 12.1 | 79 | | | 94 | 94 (1) | 94 | 12 | 78 | | | 93 | 93 (1) | 93 | 11.1 | 77 | | | 92 | 92 (1) | 92 | 11 | 76 | | | 91 | 91 (1) | 91 | 10.1 | 75 | | | 90 | 90 (1) | 90 | 10 | 74 | | | 89 | 89 (1) | 89 | 9.1 | 73 | | | 88 | 88 (1) | 88 | 9 | 72 | | | 87 | 87 (1) | 87 | 8 | 71 | | | 86 | 86 (1) | 86 | 7.1 | 70 | | | 85 | 85 (1) | 85 | 7 | 69 | | | 84 | 84 (1) | 84 | 6.1 | 68 | | | 83 | 83 (1) | 83 | 6 | 67 | | | 81 | 82 (1) | 81 | 5.1 | 66 | | | 80 | 81 (1) | 80 | 5 | 65 | | | 79 | 80 (1) | 79 | 4 | 64 | | | 18 | 79 (1) | 78 | 3.2 | 63 | | | 17 | 78 (1) | 77 | 3.1 | 62 | | | 16 | 77 (1) | 76 | | 60 | | | 15 | 76 (1) | 75 | | 58 | | | 14 | 75 (1) | 74 | | 57 | | | 13 | 74 (1) | 73 | | 56 | | | 12 | 73 (1) | 72 | | 55 | | | | 72 (1) | 71 | | 54 | | | | 71 (1) | 70 | | 53 | | | | 70 (1) | 69 | | 52 | | | | 69 (1) | 68 | | 51 | | | | 68 (1) | 67 | | 50 | | | | 67 (1) | 66 | | 49 | | | | 66 (1) | 65 | | 48 | | | | 65 (1) | 64 | | 47 | | | | 64 (1) | 63 | | 46 | | | | 63 (1) | 62 | | 45 | | | | 62 (1) | 61 | | 44 | | | | 61 (1) | 60 | | 43 | | | | 60 (1) | 59 | | 42 | | | | 59 (1) | 58 | | 41 | | | | 58 (1) | 57 | | 40 | | | | 57 (1) | 56 | | 39 | | | | 56 (1) | 55 | | 38 | | | | 55 (1) | 54 | | 37 | | | | 54 (1) | 53 | | 36 | | | | 53 (1) | 52 | | 35 | | | | 52 (1) | 51 | | 34 | | | | 51 (1) | 50 | | 33 | | | | 50 (1) | 49 | | 32 | | | | 49 (1) | 48 | | 31 | | | | 48 (1) | 47 | | 30 | | | | 47 (1) | 46 | | 29 | | | | 46 (1) | 45 | | 28 | | | | 45 (1) | 44 | | 27 | | | | 44 (1) | 43 | | 26 | | | | 43 (1) | 42 | | 25 | | | | 42 (1) | 41 | | 24 | | | | 41 (1) | 40 | | 23 | | | | 40 (1) | 39 | | 22 | | | | 39 (1) | 38 | | 21 | | | | 38 (1) | 37 | | 20 | | | | 37 (1) | 36 | | 19 | | | | 36 (1) | 35 | | 18 | | | | 35 (1) | 34 | | 17 | | | | 34 (1) | 33 | | 16 | | | | 33 (1) | 32 | | 15 | | | | 32 (1) | 31 | | 12.1 | | | | 31 (1) | 30 | | 12 | | | | 30 (1) | 29 | | 11.6 | | | | 29 (1) | 28 | | 11.5 | | | | 28 (1) | 27 | | 11.1 | | | | 27 (1) | 26 | | 11 | | | | 26 (1) | 25 | | 10.6 | | | | 25 (1) | 24 | | 10.5 | | | | 24 (1) | 23 | | 10.0-10.1 | | | | 23 (1) | 22 | | 9.5-9.6 | | | | 22 (1) | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 (1) | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (1) | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Support refers to this format's use in the `audio` element, not other conditions. 1. Partial support in Firefox refers to only supporting AAC in an MP4 container and only when the operating system already has the codecs installed. Resources --------- * [Wikipedia article](https://en.wikipedia.org/wiki/Advanced_Audio_Coding)
programming_docs
browser_support_tables AbortController & AbortSignal AbortController & AbortSignal ============================= Controller object that allows you to abort one or more DOM requests made with the Fetch API. | | | | --- | --- | | Spec | <https://dom.spec.whatwg.org/#abortsignal> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 (1) | 78 | | | 93 | 93 | 93 | 11.1 (1) | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Safari has window.AbortController defined in the DOM but it's just a stub, it does not abort requests at all. The same issue also affects Chrome on IOS and Firefox on IOS because they use the same WebKit rendering engine as Safari. Resources --------- * [Abortable Fetch - Google Developers article](https://developers.google.com/web/updates/2017/09/abortable-fetch) * [AbortController - MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) * [AbortSignal - MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) browser_support_tables SPDY protocol SPDY protocol ============= Networking protocol for low-latency transport of content over the web. Superseded by HTTP version 2. | | | | --- | --- | | Spec | <https://www.chromium.org/spdy/> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP (1) | | | | | 109 | 109 | 16.3 (1) | | | 11 | 108 | 108 | 108 | 16.2 (1) | 92 | | 10 | 107 | 107 | 107 | 16.1 (1) | 91 | | 9 | 106 | 106 | 106 | 16.0 (1) | 90 | | 8 | 105 | 105 | 105 | 15.6 (1) | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 (1) | 88 | | 6 | 103 | 103 | 103 | 15.4 (1) | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 (1) | 86 | | | 101 | 101 | 101 | 15.1 (1) | 85 | | | 100 | 100 | 100 | 15 (1) | 84 | | | 99 | 99 | 99 | 14.1 (1) | 83 | | | 98 | 98 | 98 | 14 (1) | 82 | | | 97 | 97 | 97 | 13.1 (1) | 81 | | | 96 | 96 | 96 | 13 (1) | 80 | | | 95 | 95 | 95 | 12.1 (1) | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (2) | | | | | | | | | | | | | | 16.2 (2) | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 (2) | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 (2) | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 (2) | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 (2) | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 (2) | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 (2) | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 (2) | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 (2) | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (2) | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (2) | | | | | | | | | 9.2 | | | | | 13.3 (2) | | | | | | | | | 8.2 | | | | | 13.2 (2) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (2) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (2) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- See also support for [HTTP2](https://caniuse.com/#feat=http2), successor of SPDY. 1. Deprecated as of macOS Mojave 10.4.4. To be completely removed in a future version of macOS. 2. Deprecated as of iOS 12.2. To be completely removed in a future version of iOS. Resources --------- * [Wikipedia](https://en.wikipedia.org/wiki/HTTP/2) * [SPDY whitepaper](https://dev.chromium.org/spdy/spdy-whitepaper) browser_support_tables Strict Transport Security Strict Transport Security ========================= Declare that a website is only accessible over a secure connection (HTTPS). | | | | --- | --- | | Spec | <https://tools.ietf.org/html/rfc6797> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (1) | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- The HTTP header is 'Strict-Transport-Security'. 1. IE 11 added support [in an update](https://blogs.windows.com/msedgedev/2015/06/09/http-strict-transport-security-comes-to-internet-explorer-11-on-windows-8-1-and-windows-7/) on June 9, 2015 Resources --------- * [Chromium article](https://www.chromium.org/hsts/) * [MDN Web Docs - Strict Transport Security](https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security) * [OWASP article](https://www.owasp.org/index.php/HTTP_Strict_Transport_Security) browser_support_tables String.prototype.includes String.prototype.includes ========================= The includes() method determines whether one string may be found within another string, returning true or false as appropriate. | | | | --- | --- | | Spec | <https://tc39.es/ecma262/#sec-string.prototype.includes> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Bugs ---- * String.prototype.contains: In Firefox 18 - 39, the name of this method was contains(). It was renamed to includes() in bug 1102219 Resources --------- * [MDN: String.prototype.includes()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) * [Polyfill for this feature is available in the core-js library](https://github.com/zloirock/core-js#ecmascript-string-and-regexp)
programming_docs
browser_support_tables SVG vector-effect: non-scaling-stroke SVG vector-effect: non-scaling-stroke ===================================== The `non-scaling-stroke` value for the `vector-effect` SVG attribute/CSS property makes strokes appear as the same width regardless of any transformations applied. | | | | --- | --- | | Spec | <https://www.w3.org/TR/SVG2/coords.html#VectorEffectProperty> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Other values for the `vector-effect` attribute/property are currently at risk of being removed from the specification as they are not being developed by browser vendors. Resources --------- * [MDN Docs article on vector-effect](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/vector-effect) * [Firefox implementation bug for other values](https://bugzilla.mozilla.org/show_bug.cgi?id=1318208) * [Chromium implementation bug for other values](https://bugs.chromium.org/p/chromium/issues/detail?id=691398) browser_support_tables Service Workers Service Workers =============== Method that enables applications to take advantage of persistent background processing, including hooks to enable bootstrapping of web applications while offline. | | | | --- | --- | | Spec | <https://w3c.github.io/ServiceWorker/> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 (2) | 77 | 76 | | 60 | | | 15 (2) | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 (3) | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 (3) | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 (3) | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 (3) | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 (1) | 42 | | 25 | | | | 42 (1) | 41 | | 24 | | | | 41 (1) | 40 | | 23 | | | | 40 (1) | 39 | | 22 | | | | 39 (1) | 38 | | 21 | | | | 38 (1) | 37 | | 20 | | | | 37 (1) | 36 | | 19 | | | | 36 (1) | 35 | | 18 | | | | 35 (1) | 34 | | 17 | | | | 34 (1) | 33 | | 16 | | | | 33 (1) | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Details on partial support can be found on [is ServiceWorker Ready?](https://jakearchibald.github.io/isserviceworkerready/) 1. Partial support can be enabled in Firefox with the `dom.serviceWorkers.enabled` flag. 2. Available behind the "Enable service workers" flag 3. Disabled on Firefox ESR, but can be re-enabled with the `dom.serviceWorkers.enabled` flag 4. Can be enabled via the "Experimental Features" developer menu Bugs ---- * Service Workers are currently [not supported](https://bugzilla.mozilla.org/show_bug.cgi?id=1320796) in Firefox's Private Browsing mode. Resources --------- * [HTML5Rocks article (introduction)](https://www.html5rocks.com/en/tutorials/service-worker/introduction/) * [MDN Web Docs - Service Workers](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker_API) * [List of various resources](https://jakearchibald.github.io/isserviceworkerready/resources.html) browser_support_tables Dynamic Adaptive Streaming over HTTP (MPEG-DASH) Dynamic Adaptive Streaming over HTTP (MPEG-DASH) ================================================ HTTP-based media streaming communications protocol, an alternative to HTTP Live Streaming (HLS). | | | | --- | --- | | Spec | <https://www.iso.org/standard/65274.html> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 (1,2) | 21 | | 9 | | | | 21 (1,2) | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- DASH can be used with a JavaScript library in browsers that doesn't support it natively as long as they support [Media Source Extensions](/mediasource). 1. Can be enabled via the `media.dash.enabled` flag. 2. Only WebM video is supported. Resources --------- * [Wikipedia article](https://en.wikipedia.org/wiki/Dynamic_Adaptive_Streaming_over_HTTP) * [JavaScript implementation](https://github.com/Dash-Industry-Forum/dash.js/) browser_support_tables CSS @when / @else conditional rules CSS @when / @else conditional rules =================================== Syntax allowing CSS conditions (like media and support queries) to be written more simply, as well as making it possibly to write mutually exclusive rules using `@else` statements. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css-conditional-5/#when-rule> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Blog post: Extending CSS when/else chains: A first look](https://blog.logrocket.com/extending-css-when-else-chains-first-look/) * [Chrome support bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1282896) * [Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1747727) * [WebKit support bug](https://bugs.webkit.org/show_bug.cgi?id=234701)
programming_docs
browser_support_tables Feature Policy Feature Policy ============== This specification defines a mechanism that allows developers to selectively enable and disable use of various browser features and APIs. Feature Policy is deprecated and has been replaced with [Permissions Policy](/permissions-policy) and [Document Policy](/document-policy). | | | | --- | --- | | Spec | <https://www.w3.org/TR/2019/WD-feature-policy-1-20190416/> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (4) | | | | | | 110 (2) | 110 (4) | TP (2,3) | | | | | 109 (2) | 109 (4) | 16.3 (2,3) | | | 11 | 108 (4) | 108 (2) | 108 (4) | 16.2 (2,3) | 92 (4) | | 10 | 107 (4) | 107 (2) | 107 (4) | 16.1 (2,3) | 91 (4) | | 9 | 106 (4) | 106 (2) | 106 (4) | 16.0 (2,3) | 90 (4) | | 8 | 105 (4) | 105 (2) | 105 (4) | 15.6 (2,3) | 89 (4) | | [Show all](#) | | 7 | 104 (4) | 104 (2) | 104 (4) | 15.5 (2,3) | 88 (4) | | 6 | 103 (4) | 103 (2) | 103 (4) | 15.4 (2,3) | 87 (4) | | 5.5 | 102 (4) | 102 (2) | 102 (4) | 15.2-15.3 (2,3) | 86 (4) | | | 101 (4) | 101 (2) | 101 (4) | 15.1 (2,3) | 85 (4) | | | 100 (4) | 100 (2) | 100 (4) | 15 (2,3) | 84 (4) | | | 99 (4) | 99 (2) | 99 (4) | 14.1 (2,3) | 83 (4) | | | 98 (4) | 98 (2) | 98 (4) | 14 (2,3) | 82 (4) | | | 97 (4) | 97 (2) | 97 (4) | 13.1 (2,3) | 81 (4) | | | 96 (4) | 96 (2) | 96 (4) | 13 (2,3) | 80 (4) | | | 95 (4) | 95 (2) | 95 (4) | 12.1 (2,3) | 79 (4) | | | 94 (4) | 94 (2) | 94 (4) | 12 (2,3) | 78 (4) | | | 93 (4) | 93 (2) | 93 (4) | 11.1 (2,3) | 77 (4) | | | 92 (4) | 92 (2) | 92 (4) | 11 | 76 (4) | | | 91 (4) | 91 (2) | 91 (4) | 10.1 | 75 (4) | | | 90 (4) | 90 (2) | 90 (4) | 10 | 74 | | | 89 (4) | 89 (2) | 89 (4) | 9.1 | 73 | | | 88 (4) | 88 (2) | 88 (4) | 9 | 72 | | | 87 | 87 (2) | 87 | 8 | 71 | | | 86 | 86 (2) | 86 | 7.1 | 70 | | | 85 | 85 (2) | 85 | 7 | 69 | | | 84 | 84 (2) | 84 | 6.1 | 68 | | | 83 | 83 (2) | 83 | 6 | 67 | | | 81 | 82 (2) | 81 | 5.1 | 66 | | | 80 | 81 (2) | 80 | 5 | 65 | | | 79 | 80 (2) | 79 | 4 | 64 | | | 18 | 79 (2) | 78 | 3.2 | 63 | | | 17 | 78 (2) | 77 | 3.1 | 62 | | | 16 | 77 (2) | 76 | | 60 (1) | | | 15 | 76 (2) | 75 | | 58 (1) | | | 14 | 75 (2) | 74 | | 57 (1) | | | 13 | 74 (2) | 73 (1) | | 56 (1) | | | 12 | 73 | 72 (1) | | 55 (1) | | | | 72 | 71 (1) | | 54 (1) | | | | 71 | 70 (1) | | 53 (1) | | | | 70 | 69 (1) | | 52 (1) | | | | 69 | 68 (1) | | 51 (1) | | | | 68 | 67 (1) | | 50 (1) | | | | 67 | 66 (1) | | 49 (1) | | | | 66 | 65 (1) | | 48 (1) | | | | 65 | 64 (1) | | 47 (1) | | | | 64 | 63 (1) | | 46 | | | | 63 | 62 (1) | | 45 | | | | 62 | 61 (1) | | 44 | | | | 61 | 60 (1) | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (2,3) | | | | | | | | | | | | | | 16.2 (2,3) | all | 108 | 10 | 72 (4) | 108 (4) | 107 (2) | 11 | 13.4 | 19.0 | 13.1 (1) | 13.18 (4) | 2.5 | | 16.1 (2,3) | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 (2,3) | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 (2,3) | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 (2,3) | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 (2,3) | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 (2,3) | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 (2,3) | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 (2,3) | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (2,3) | | 2.1 | | | | | | | 10.1 (1) | | | | | 13.4-13.7 (2,3) | | | | | | | | | 9.2 (1) | | | | | 13.3 (2,3) | | | | | | | | | 8.2 (1) | | | | | 13.2 (2,3) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (2,3) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (2,3) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 (2,3) | | | | | | | | | 4 | | | | | 11.3-11.4 (2,3) | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Standard support includes the HTTP `Feature-Policy` header, `allow` attribute on iframes and the `document.featurePolicy` JS API. 1. Older Chromium browsers did not support the JS API. 2. Safari and Firefox only supports the `allow` attribute on iframes. 3. Safari doesn't support a [list of origins](https://bugs.webkit.org/show_bug.cgi?id=189901) or a [wildcard](https://bugs.webkit.org/show_bug.cgi?id=187816). 4. At least partially supports [Permissions Policy](/permissions-policy), the main replacement for this spec. Resources --------- * [Feature Policy Kitchen Sink Demos](https://feature-policy-demos.appspot.com/) * [Introduction to Feature Policy](https://developers.google.com/web/updates/2018/06/feature-policy) * [Firefox implemention ticket](https://bugzilla.mozilla.org/show_bug.cgi?id=1390801) * [Feature Policy Tester (Chrome DevTools Extension)](https://chrome.google.com/webstore/detail/feature-policy-tester-dev/pchamnkhkeokbpahnocjaeednpbpacop) * [featurepolicy.info (Feature-Policy Playground)](https://featurepolicy.info/) * [List of known features](https://github.com/w3c/webappsec-permissions-policy/blob/main/features.md) browser_support_tables CSS Initial Letter CSS Initial Letter ================== Method of creating an enlarged cap, including a drop or raised cap, in a robust way. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css-inline/#initial-letter-styling> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (2) | | | | | | 110 | 110 (2) | TP (1,\*) | | | | | 109 | 109 | 16.3 (1,\*) | | | 11 | 108 | 108 | 108 | 16.2 (1,\*) | 92 | | 10 | 107 | 107 | 107 | 16.1 (1,\*) | 91 | | 9 | 106 | 106 | 106 | 16.0 (1,\*) | 90 | | 8 | 105 | 105 | 105 | 15.6 (1,\*) | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 (1,\*) | 88 | | 6 | 103 | 103 | 103 | 15.4 (1,\*) | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 (1,\*) | 86 | | | 101 | 101 | 101 | 15.1 (1,\*) | 85 | | | 100 | 100 | 100 | 15 (1,\*) | 84 | | | 99 | 99 | 99 | 14.1 (1,\*) | 83 | | | 98 | 98 | 98 | 14 (1,\*) | 82 | | | 97 | 97 | 97 | 13.1 (1,\*) | 81 | | | 96 | 96 | 96 | 13 (1,\*) | 80 | | | 95 | 95 | 95 | 12.1 (1,\*) | 79 | | | 94 | 94 | 94 | 12 (1,\*) | 78 | | | 93 | 93 | 93 | 11.1 (1,\*) | 77 | | | 92 | 92 | 92 | 11 (1,\*) | 76 | | | 91 | 91 | 91 | 10.1 (1,\*) | 75 | | | 90 | 90 | 90 | 10 (1,\*) | 74 | | | 89 | 89 | 89 | 9.1 (1,\*) | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (1,\*) | | | | | | | | | | | | | | 16.2 (1,\*) | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 (1,\*) | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 (1,\*) | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 (1,\*) | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 (1,\*) | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 (1,\*) | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 (1,\*) | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 (1,\*) | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 (1,\*) | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (1,\*) | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (1,\*) | | | | | | | | | 9.2 | | | | | 13.3 (1,\*) | | | | | | | | | 8.2 | | | | | 13.2 (1,\*) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (1,\*) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (1,\*) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 (1,\*) | | | | | | | | | 4 | | | | | 11.3-11.4 (1,\*) | | | | | | | | | | | | | | 11.0-11.2 (1,\*) | | | | | | | | | | | | | | 10.3 (1,\*) | | | | | | | | | | | | | | 10.0-10.2 (1,\*) | | | | | | | | | | | | | | 9.3 (1,\*) | | | | | | | | | | | | | | 9.0-9.2 (1,\*) | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Safari implementation is incomplete. Does not allow applying web fonts to the initial letter. 2. Partial support refers to only supporting `initial-letter` \* Partial support with prefix. Bugs ---- * Safari 9 doesn't properly shorten the first line of text. Applying `margin-top: 1em` to the letter fixes this problem. Resources --------- * [Firefox Implementation Ticket](https://bugzilla.mozilla.org/show_bug.cgi?id=1273019) * [MDN Web Docs - CSS initial-letter](https://developer.mozilla.org/en-US/docs/Web/CSS/initial-letter) * [Blog post on Envato Tuts+, "Better CSS Drop Caps With initial-letter"](https://webdesign.tutsplus.com/tutorials/better-css-drop-caps-with-initial-letter--cms-26350) * [Demos at Jen Simmons Labs](https://labs.jensimmons.com/#initialletter) * [WebKit bug to unprefix -webkit-initial-letter](https://bugs.webkit.org/show_bug.cgi?id=229090) browser_support_tables CSS3 font-kerning CSS3 font-kerning ================= Controls the usage of the kerning information (spacing between letters) stored in the font. Note that this only affects OpenType fonts with kerning information, it has no effect on other fonts. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css3-fonts/#font-kerning-prop> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 (\*) | 72 | | | 87 | 87 | 87 | 8 (\*) | 71 | | | 86 | 86 | 86 | 7.1 (\*) | 70 | | | 85 | 85 | 85 | 7 (\*) | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 (\*) | | | | 36 | 35 | | 18 (\*) | | | | 35 | 34 | | 17 (\*) | | | | 34 | 33 | | 16 (\*) | | | | 33 (1) | 32 (\*) | | 15 | | | | 32 (1) | 31 (\*) | | 12.1 | | | | 31 (1) | 30 (\*) | | 12 | | | | 30 (1) | 29 (\*) | | 11.6 | | | | 29 (1) | 28 | | 11.5 | | | | 28 (1) | 27 | | 11.1 | | | | 27 (1) | 26 | | 11 | | | | 26 (1) | 25 | | 10.6 | | | | 25 (1) | 24 | | 10.5 | | | | 24 (1) | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 (\*) | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 (\*) | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 (\*) | | | | | | | | | | | | | | 11.0-11.2 (\*) | | | | | | | | | | | | | | 10.3 (\*) | | | | | | | | | | | | | | 10.0-10.2 (\*) | | | | | | | | | | | | | | 9.3 (\*) | | | | | | | | | | | | | | 9.0-9.2 (\*) | | | | | | | | | | | | | | 8.1-8.4 (\*) | | | | | | | | | | | | | | 8 (\*) | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Browsers with support for [font feature settings](https://caniuse.com/#feat=font-feature) can also set kerning value. 1. Disabled by default, can be enabled using preference layout.css.font-features.enabled - defaulting to true on Nightly and Aurora only. \* Partial support with prefix. Resources --------- * [MDN Web Docs - CSS font-kerning](https://developer.mozilla.org/en-US/docs/Web/CSS/font-kerning)
programming_docs
browser_support_tables Screen Wake Lock API Screen Wake Lock API ==================== API to prevent devices from dimming, locking or turning off the screen when the application needs to keep running. | | | | --- | --- | | Spec | <https://www.w3.org/TR/wake-lock/> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 (1) | 89 | 89 | 9.1 | 73 | | | 88 (1) | 88 | 88 | 9 | 72 (1) | | | 87 (1) | 87 | 87 | 8 | 71 (1) | | | 86 (1) | 86 | 86 | 7.1 | 70 (1) | | | 85 (1) | 85 | 85 | 7 | 69 (1) | | | 84 (1) | 84 | 84 (1) | 6.1 | 68 (1) | | | 83 (1) | 83 | 83 (1) | 6 | 67 (1) | | | 81 (1) | 82 | 81 (1) | 5.1 | 66 (1) | | | 80 (1) | 81 | 80 (1) | 5 | 65 (1) | | | 79 (1) | 80 | 79 (1) | 4 | 64 (1) | | | 18 | 79 | 78 (1) | 3.2 | 63 (1) | | | 17 | 78 | 77 (1) | 3.1 | 62 (1) | | | 16 | 77 | 76 (1) | | 60 (1) | | | 15 | 76 | 75 (1) | | 58 (1) | | | 14 | 75 | 74 (1) | | 57 | | | 13 | 74 | 73 (1) | | 56 | | | 12 | 73 | 72 (1) | | 55 | | | | 72 | 71 (1) | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Available behind the #experimental-web-platform-features feature flag Resources --------- * [Stay awake with the Screen Wake Lock API](https://web.dev/wakelock/) * [Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1589554) * [WebKit support bug](https://bugs.webkit.org/show_bug.cgi?id=205104) * [MDN article about the Screen Wake Lock API](https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API) browser_support_tables Audio Tracks Audio Tracks ============ Method of specifying and selecting between multiple audio tracks. Useful for providing audio descriptions, director's commentary, additional languages, alternative takes, etc. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/embedded-content.html#audiotracklist-and-videotracklist-objects> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (2) | | | | | | 110 (1) | 110 (2) | TP | | | | | 109 (1) | 109 (2) | 16.3 | | | 11 | 108 (2) | 108 (1) | 108 (2) | 16.2 | 92 (2) | | 10 | 107 (2) | 107 (1) | 107 (2) | 16.1 | 91 (2) | | 9 | 106 (2) | 106 (1) | 106 (2) | 16.0 | 90 (2) | | 8 | 105 (2) | 105 (1) | 105 (2) | 15.6 | 89 (2) | | [Show all](#) | | 7 | 104 (2) | 104 (1) | 104 (2) | 15.5 | 88 (2) | | 6 | 103 (2) | 103 (1) | 103 (2) | 15.4 | 87 (2) | | 5.5 | 102 (2) | 102 (1) | 102 (2) | 15.2-15.3 | 86 (2) | | | 101 (2) | 101 (1) | 101 (2) | 15.1 | 85 (2) | | | 100 (2) | 100 (1) | 100 (2) | 15 | 84 (2) | | | 99 (2) | 99 (1) | 99 (2) | 14.1 | 83 (2) | | | 98 (2) | 98 (1) | 98 (2) | 14 | 82 (2) | | | 97 (2) | 97 (1) | 97 (2) | 13.1 | 81 (2) | | | 96 (2) | 96 (1) | 96 (2) | 13 | 80 (2) | | | 95 (2) | 95 (1) | 95 (2) | 12.1 | 79 (2) | | | 94 (2) | 94 (1) | 94 (2) | 12 | 78 (2) | | | 93 (2) | 93 (1) | 93 (2) | 11.1 | 77 (2) | | | 92 (2) | 92 (1) | 92 (2) | 11 | 76 (2) | | | 91 (2) | 91 (1) | 91 (2) | 10.1 | 75 (2) | | | 90 (2) | 90 (1) | 90 (2) | 10 | 74 (2) | | | 89 (2) | 89 (1) | 89 (2) | 9.1 | 73 (2) | | | 88 (2) | 88 (1) | 88 (2) | 9 | 72 (2) | | | 87 (2) | 87 (1) | 87 (2) | 8 | 71 (2) | | | 86 (2) | 86 (1) | 86 (2) | 7.1 | 70 (2) | | | 85 (2) | 85 (1) | 85 (2) | 7 | 69 (2) | | | 84 (2) | 84 (1) | 84 (2) | 6.1 | 68 (2) | | | 83 (2) | 83 (1) | 83 (2) | 6 | 67 (2) | | | 81 (2) | 82 (1) | 81 (2) | 5.1 | 66 (2) | | | 80 (2) | 81 (1) | 80 (2) | 5 | 65 (2) | | | 79 (2) | 80 (1) | 79 (2) | 4 | 64 (2) | | | 18 | 79 (1) | 78 (2) | 3.2 | 63 (2) | | | 17 | 78 (1) | 77 (2) | 3.1 | 62 (2) | | | 16 | 77 (1) | 76 (2) | | 60 (2) | | | 15 | 76 (1) | 75 (2) | | 58 (2) | | | 14 | 75 (1) | 74 (2) | | 57 (2) | | | 13 | 74 (1) | 73 (2) | | 56 (2) | | | 12 | 73 (1) | 72 (2) | | 55 (2) | | | | 72 (1) | 71 (2) | | 54 (2) | | | | 71 (1) | 70 (2) | | 53 (2) | | | | 70 (1) | 69 (2) | | 52 (2) | | | | 69 (1) | 68 (2) | | 51 (2) | | | | 68 (1) | 67 (2) | | 50 (2) | | | | 67 (1) | 66 (2) | | 49 (2) | | | | 66 (1) | 65 (2) | | 48 (2) | | | | 65 (1) | 64 (2) | | 47 (2) | | | | 64 (1) | 63 (2) | | 46 (2) | | | | 63 (1) | 62 (2) | | 45 (2) | | | | 62 (1) | 61 (2) | | 44 (2) | | | | 61 (1) | 60 (2) | | 43 (2) | | | | 60 (1) | 59 (2) | | 42 (2) | | | | 59 (1) | 58 (2) | | 41 (2) | | | | 58 (1) | 57 (2) | | 40 (2) | | | | 57 (1) | 56 (2) | | 39 (2) | | | | 56 (1) | 55 (2) | | 38 (2) | | | | 55 (1) | 54 (2) | | 37 (2) | | | | 54 (1) | 53 (2) | | 36 (2) | | | | 53 (1) | 52 (2) | | 35 (2) | | | | 52 (1) | 51 (2) | | 34 (2) | | | | 51 (1) | 50 (2) | | 33 (2) | | | | 50 (1) | 49 (2) | | 32 (2) | | | | 49 (1) | 48 (2) | | 31 | | | | 48 (1) | 47 (2) | | 30 | | | | 47 (1) | 46 (2) | | 29 | | | | 46 (1) | 45 (2) | | 28 | | | | 45 (1) | 44 | | 27 | | | | 44 (1) | 43 | | 26 | | | | 43 (1) | 42 | | 25 | | | | 42 (1) | 41 | | 24 | | | | 41 (1) | 40 | | 23 | | | | 40 (1) | 39 | | 22 | | | | 39 (1) | 38 | | 21 | | | | 38 (1) | 37 | | 20 | | | | 37 (1) | 36 | | 19 | | | | 36 (1) | 35 | | 18 | | | | 35 (1) | 34 | | 17 | | | | 34 (1) | 33 | | 16 | | | | 33 (1) | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 (2) | 108 (2) | 107 | 11 | 13.4 (2) | 19.0 | 13.1 (2) | 13.18 (2) | 2.5 (1) | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Supported in Firefox by enabling "media.track.enabled" in about:config 2. Supported in Chrome and Opera by enabling "enable-experimental-web-platform-features" in chrome:flags Resources --------- * [MDN Web Docs - HTMLMediaElement.audioTracks](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/audioTracks) browser_support_tables :is() CSS pseudo-class :is() CSS pseudo-class ====================== The `:is()` (formerly `:matches()`, formerly `:any()`) pseudo-class checks whether the element at its position in the outer selector matches any of the selectors in its selector list. It's useful syntactic sugar that allows you to avoid writing out all the combinations manually as separate selectors. The effect is similar to nesting in Sass and most other CSS preprocessors. | | | | --- | --- | | Spec | <https://www.w3.org/TR/selectors4/#matches> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 (2) | 81 | | | 96 | 96 | 96 | 13 (2) | 80 | | | 95 | 95 | 95 | 12.1 (2) | 79 | | | 94 | 94 | 94 | 12 (2) | 78 | | | 93 | 93 | 93 | 11.1 (2) | 77 | | | 92 | 92 | 92 | 11 (2) | 76 | | | 91 | 91 | 91 | 10.1 (2) | 75 | | | 90 | 90 | 90 | 10 (2) | 74 (1,4) | | | 89 | 89 | 89 | 9.1 (2) | 73 (1,4) | | | 88 | 88 | 88 | 9 (2) | 72 (1,4) | | | 87 (1,4) | 87 | 87 (1,4) | 8 (1,\*) | 71 (1,4) | | | 86 (1,4) | 86 | 86 (1,4) | 7.1 (1,\*) | 70 (1,4) | | | 85 (1,4) | 85 | 85 (1,4) | 7 (1,\*) | 69 (1,4) | | | 84 (1,4) | 84 | 84 (1,4) | 6.1 (1,\*) | 68 (1,4) | | | 83 (1,4) | 83 | 83 (1,4) | 6 (1,\*) | 67 (1,4) | | | 81 (1,4) | 82 | 81 (1,4) | 5.1 (1,\*) | 66 (1,4) | | | 80 (1,4) | 81 | 80 (1,4) | 5 | 65 (1,4) | | | 79 (1,4) | 80 | 79 (1,4) | 4 | 64 (1,4) | | | 18 | 79 | 78 (1,4) | 3.2 | 63 (1,4) | | | 17 | 78 | 77 (1,4) | 3.1 | 62 (1,4) | | | 16 | 77 (3,\*) | 76 (1,4) | | 60 (1,4) | | | 15 | 76 (3,\*) | 75 (1,4) | | 58 (1,4) | | | 14 | 75 (3,\*) | 74 (1,4) | | 57 (1,4) | | | 13 | 74 (3,\*) | 73 (1,4) | | 56 (1,4) | | | 12 | 73 (3,\*) | 72 (1,4) | | 55 (1,4) | | | | 72 (3,\*) | 71 (1,4) | | 54 (1) | | | | 71 (3,\*) | 70 (1,4) | | 53 (1) | | | | 70 (3,\*) | 69 (1,4) | | 52 (1) | | | | 69 (3,\*) | 68 (1,4) | | 51 (1,\*) | | | | 68 (3,\*) | 67 (1) | | 50 (1,\*) | | | | 67 (3,\*) | 66 (1) | | 49 (1,\*) | | | | 66 (3,\*) | 65 (1) | | 48 (1,\*) | | | | 65 (3,\*) | 64 (1,\*) | | 47 (1,\*) | | | | 64 (3,\*) | 63 (1,\*) | | 46 (1,\*) | | | | 63 (3,\*) | 62 (1,\*) | | 45 (1,\*) | | | | 62 (3,\*) | 61 (1,\*) | | 44 (1,\*) | | | | 61 (3,\*) | 60 (1,\*) | | 43 (1,\*) | | | | 60 (3,\*) | 59 (1,\*) | | 42 (1,\*) | | | | 59 (3,\*) | 58 (1,\*) | | 41 (1,\*) | | | | 58 (3,\*) | 57 (1,\*) | | 40 (1,\*) | | | | 57 (3,\*) | 56 (1,\*) | | 39 (1,\*) | | | | 56 (3,\*) | 55 (1,\*) | | 38 (1,\*) | | | | 55 (3,\*) | 54 (1,\*) | | 37 (1,\*) | | | | 54 (3,\*) | 53 (1,\*) | | 36 (1,\*) | | | | 53 (3,\*) | 52 (1,\*) | | 35 (1,\*) | | | | 52 (3,\*) | 51 (1,\*) | | 34 (1,\*) | | | | 51 (3,\*) | 50 (1,\*) | | 33 (1,\*) | | | | 50 (3,\*) | 49 (1,\*) | | 32 (1,\*) | | | | 49 (3,\*) | 48 (1,\*) | | 31 (1,\*) | | | | 48 (3,\*) | 47 (1,\*) | | 30 (1,\*) | | | | 47 (3,\*) | 46 (1,\*) | | 29 (1,\*) | | | | 46 (3,\*) | 45 (1,\*) | | 28 (1,\*) | | | | 45 (3,\*) | 44 (1,\*) | | 27 (1,\*) | | | | 44 (3,\*) | 43 (1,\*) | | 26 (1,\*) | | | | 43 (3,\*) | 42 (1,\*) | | 25 (1,\*) | | | | 42 (3,\*) | 41 (1,\*) | | 24 (1,\*) | | | | 41 (3,\*) | 40 (1,\*) | | 23 (1,\*) | | | | 40 (3,\*) | 39 (1,\*) | | 22 (1,\*) | | | | 39 (3,\*) | 38 (1,\*) | | 21 (1,\*) | | | | 38 (3,\*) | 37 (1,\*) | | 20 (1,\*) | | | | 37 (3,\*) | 36 (1,\*) | | 19 (1,\*) | | | | 36 (3,\*) | 35 (1,\*) | | 18 (1,\*) | | | | 35 (3,\*) | 34 (1,\*) | | 17 (1,\*) | | | | 34 (3,\*) | 33 (1,\*) | | 16 (1,\*) | | | | 33 (3,\*) | 32 (1,\*) | | 15 (1,\*) | | | | 32 (3,\*) | 31 (1,\*) | | 12.1 | | | | 31 (3,\*) | 30 (1,\*) | | 12 | | | | 30 (3,\*) | 29 (1,\*) | | 11.6 | | | | 29 (3,\*) | 28 (1,\*) | | 11.5 | | | | 28 (3,\*) | 27 (1,\*) | | 11.1 | | | | 27 (3,\*) | 26 (1,\*) | | 11 | | | | 26 (3,\*) | 25 (1,\*) | | 10.6 | | | | 25 (3,\*) | 24 (1,\*) | | 10.5 | | | | 24 (3,\*) | 23 (1,\*) | | 10.0-10.1 | | | | 23 (3,\*) | 22 (1,\*) | | 9.5-9.6 | | | | 22 (3,\*) | 21 (1,\*) | | 9 | | | | 21 (3,\*) | 20 (1,\*) | | | | | | 20 (3,\*) | 19 (1,\*) | | | | | | 19 (3,\*) | 18 (1,\*) | | | | | | 18 (3,\*) | 17 (1,\*) | | | | | | 17 (3,\*) | 16 (1,\*) | | | | | | 16 (3,\*) | 15 (1,\*) | | | | | | 15 (3,\*) | 14 | | | | | | 14 (3,\*) | 13 | | | | | | 13 (3,\*) | 12 | | | | | | 12 (3,\*) | 11 | | | | | | 11 (3,\*) | 10 | | | | | | 10 (3,\*) | 9 | | | | | | 9 (3,\*) | 8 | | | | | | 8 (3,\*) | 7 | | | | | | 7 (3,\*) | 6 | | | | | | 6 (3,\*) | 5 | | | | | | 5 (3,\*) | 4 | | | | | | 4 (3,\*) | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 (1,\*) | 72 | 108 | 107 | 11 | 13.4 (1,\*) | 19.0 | 13.1 (1,4) | 13.18 | 2.5 (3,\*) | | 16.1 | | 4.4.3-4.4.4 (1,\*) | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 (1,\*) | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 (1,\*) | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 (1,\*) | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 (1,\*) | | 11 | | | | | 14.0 (1,\*) | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 (1,\*) | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 (1,\*) | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 (1,\*) | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 (1,\*) | | | | | 13.4-13.7 (2) | | | | | | | | | 9.2 (1,\*) | | | | | 13.3 (2) | | | | | | | | | 8.2 (1,\*) | | | | | 13.2 (2) | | | | | | | | | 7.2-7.4 (1,\*) | | | | | 13.0-13.1 (2) | | | | | | | | | 6.2-6.4 (1,\*) | | | | | 12.2-12.5 (2) | | | | | | | | | 5.0-5.4 (1,\*) | | | | | 12.0-12.1 (2) | | | | | | | | | 4 (1,\*) | | | | | 11.3-11.4 (2) | | | | | | | | | | | | | | 11.0-11.2 (2) | | | | | | | | | | | | | | 10.3 (2) | | | | | | | | | | | | | | 10.0-10.2 (2) | | | | | | | | | | | | | | 9.3 (2) | | | | | | | | | | | | | | 9.0-9.2 (2) | | | | | | | | | | | | | | 8.1-8.4 (1,\*) | | | | | | | | | | | | | | 8 (1,\*) | | | | | | | | | | | | | | 7.0-7.1 (1,\*) | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Only supports the deprecated `:-webkit-any()` pseudo-class 2. Only supports the deprecated `:-webkit-any()` and `:matches()` pseudo-classes 3. Only supports the deprecated `:-moz-any()` pseudo-class. 4. Support for `:is()` can be enabled with the `Experimental Web Platform features` flag \* Partial support with prefix. Resources --------- * [WebKit blog post about adding `:matches()` and other Selectors Level 4 features](https://webkit.org/blog/3615/css-selectors-inside-selectors-discover-matches-not-and-nth-child/) * [Chrome support bug for :is()](https://bugs.chromium.org/p/chromium/issues/detail?id=568705) * [MDN Web Docs - CSS :is()](https://developer.mozilla.org/en-US/docs/Web/CSS/:is) * [Codepen - Modern tests](https://codepen.io/atjn/full/MWKErBe) * [JS Bin - Legacy tests](https://output.jsbin.com/lehina)
programming_docs
browser_support_tables matches() DOM method matches() DOM method ==================== Method of testing whether or not a DOM element matches a given selector. Formerly known (and largely supported with prefix) as matchesSelector. | | | | --- | --- | | Spec | <https://dom.spec.whatwg.org/#dom-element-matches> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (\*) | 108 | 108 | 108 | 16.2 | 92 | | 10 (\*) | 107 | 107 | 107 | 16.1 | 91 | | 9 (\*) | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 (\*) | 69 | | | 84 | 84 | 84 | 6.1 (\*) | 68 | | | 83 | 83 | 83 | 6 (\*) | 67 | | | 81 | 82 | 81 | 5.1 (\*) | 66 | | | 80 | 81 | 80 | 5 (\*) | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 (\*) | 75 | 74 | | 57 | | | 13 (\*) | 74 | 73 | | 56 | | | 12 (\*) | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 (\*) | | | | 37 | 36 | | 19 (\*) | | | | 36 | 35 | | 18 (\*) | | | | 35 | 34 | | 17 (\*) | | | | 34 | 33 (\*) | | 16 (\*) | | | | 33 (\*) | 32 (\*) | | 15 (\*) | | | | 32 (\*) | 31 (\*) | | 12.1 (\*) | | | | 31 (\*) | 30 (\*) | | 12 (\*) | | | | 30 (\*) | 29 (\*) | | 11.6 (\*) | | | | 29 (\*) | 28 (\*) | | 11.5 (\*) | | | | 28 (\*) | 27 (\*) | | 11.1 | | | | 27 (\*) | 26 (\*) | | 11 | | | | 26 (\*) | 25 (\*) | | 10.6 | | | | 25 (\*) | 24 (\*) | | 10.5 | | | | 24 (\*) | 23 (\*) | | 10.0-10.1 | | | | 23 (\*) | 22 (\*) | | 9.5-9.6 | | | | 22 (\*) | 21 (\*) | | 9 | | | | 21 (\*) | 20 (\*) | | | | | | 20 (\*) | 19 (\*) | | | | | | 19 (\*) | 18 (\*) | | | | | | 18 (\*) | 17 (\*) | | | | | | 17 (\*) | 16 (\*) | | | | | | 16 (\*) | 15 (\*) | | | | | | 15 (\*) | 14 (\*) | | | | | | 14 (\*) | 13 (\*) | | | | | | 13 (\*) | 12 (\*) | | | | | | 12 (\*) | 11 (\*) | | | | | | 11 (\*) | 10 (\*) | | | | | | 10 (\*) | 9 (\*) | | | | | | 9 (\*) | 8 (\*) | | | | | | 8 (\*) | 7 (\*) | | | | | | 7 (\*) | 6 (\*) | | | | | | 6 (\*) | 5 (\*) | | | | | | 5 (\*) | 4 (\*) | | | | | | 4 (\*) | | | | | | | 3.6 (\*) | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 (\*) | 72 | 108 | 107 | 11 (\*) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 (\*) | 7 (\*) | 12.1 (\*) | | | 10 (\*) | | 18.0 | | | | | 16.0 | | 4.4 (\*) | | 12 (\*) | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 (\*) | | 11.5 (\*) | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 (\*) | | 11.1 (\*) | | | | | 15.0 | | | | | 15.4 | | 4 (\*) | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 (\*) | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 (\*) | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 (\*) | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 (\*) | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 (\*) | | | | | | | | | | | | | | 6.0-6.1 (\*) | | | | | | | | | | | | | | 5.0-5.1 (\*) | | | | | | | | | | | | | | 4.2-4.3 (\*) | | | | | | | | | | | | | | 4.0-4.1 (\*) | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Partial support refers to supporting the older specification's "matchesSelector" name rather than just "matches". \* Partial support with prefix. Resources --------- * [MDN Web Docs - Element matches](https://developer.mozilla.org/en/docs/Web/API/Element/matches) * [WebPlatform Docs](https://webplatform.github.io/docs/dom/HTMLElement/matches) browser_support_tables Web Audio API Web Audio API ============= High-level JavaScript API for processing and synthesizing audio | | | | --- | --- | | Spec | <https://www.w3.org/TR/webaudio/> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 (\*) | 82 | | | 97 | 97 | 97 | 13.1 (\*) | 81 | | | 96 | 96 | 96 | 13 (\*) | 80 | | | 95 | 95 | 95 | 12.1 (\*) | 79 | | | 94 | 94 | 94 | 12 (\*) | 78 | | | 93 | 93 | 93 | 11.1 (\*) | 77 | | | 92 | 92 | 92 | 11 (\*) | 76 | | | 91 | 91 | 91 | 10.1 (\*) | 75 | | | 90 | 90 | 90 | 10 (\*) | 74 | | | 89 | 89 | 89 | 9.1 (\*) | 73 | | | 88 | 88 | 88 | 9 (\*) | 72 | | | 87 | 87 | 87 | 8 (\*) | 71 | | | 86 | 86 | 86 | 7.1 (\*) | 70 | | | 85 | 85 | 85 | 7 (\*) | 69 | | | 84 | 84 | 84 | 6.1 (\*) | 68 | | | 83 | 83 | 83 | 6 (\*) | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 (\*) | | | | 38 | 37 | | 20 (\*) | | | | 37 | 36 | | 19 (\*) | | | | 36 | 35 | | 18 (\*) | | | | 35 | 34 | | 17 (\*) | | | | 34 | 33 (\*) | | 16 (\*) | | | | 33 | 32 (\*) | | 15 (\*) | | | | 32 | 31 (\*) | | 12.1 | | | | 31 | 30 (\*) | | 12 | | | | 30 | 29 (\*) | | 11.6 | | | | 29 | 28 (\*) | | 11.5 | | | | 28 | 27 (\*) | | 11.1 | | | | 27 | 26 (\*) | | 11 | | | | 26 | 25 (\*) | | 10.6 | | | | 25 | 24 (\*) | | 10.5 | | | | 24 | 23 (\*) | | 10.0-10.1 | | | | 23 | 22 (\*) | | 9.5-9.6 | | | | 22 | 21 (\*) | | 9 | | | | 21 | 20 (\*) | | | | | | 20 | 19 (\*) | | | | | | 19 | 18 (\*) | | | | | | 18 | 17 (\*) | | | | | | 17 | 16 (\*) | | | | | | 16 | 15 (\*) | | | | | | 15 | 14 (\*) | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (\*) | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (\*) | | | | | | | | | 9.2 | | | | | 13.3 (\*) | | | | | | | | | 8.2 | | | | | 13.2 (\*) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (\*) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (\*) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 (\*) | | | | | | | | | 4 | | | | | 11.3-11.4 (\*) | | | | | | | | | | | | | | 11.0-11.2 (\*) | | | | | | | | | | | | | | 10.3 (\*) | | | | | | | | | | | | | | 10.0-10.2 (\*) | | | | | | | | | | | | | | 9.3 (\*) | | | | | | | | | | | | | | 9.0-9.2 (\*) | | | | | | | | | | | | | | 8.1-8.4 (\*) | | | | | | | | | | | | | | 8 (\*) | | | | | | | | | | | | | | 7.0-7.1 (\*) | | | | | | | | | | | | | | 6.0-6.1 (\*) | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Not all browsers with support for the Audio API also support media streams (e.g. microphone input). See the [getUserMedia/Streams API](/#feat=stream) data for support for that feature. Firefox versions < 25 support an alternative, deprecated audio API. Chrome support [went through some changes](https://developers.google.com/web/updates/2014/07/Web-Audio-Changes-in-m36) as of version 36. \* Partial support with prefix. Resources --------- * [Polyfill to support Web Audio API in Firefox](https://github.com/corbanbrook/audionode.js) * [WebPlatform Docs](https://webplatform.github.io/docs/apis/webaudio) * [Polyfill to enable Web Audio API through Firefox Audio Data api or flash](https://github.com/g200kg/WAAPISim) * [MDN Web Docs - Web Audio API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API) browser_support_tables WebXR Device API WebXR Device API ================ API for accessing virtual reality (VR) and augmented reality (AR) devices, including sensors and head-mounted displays. | | | | --- | --- | | Spec | <https://www.w3.org/TR/webxr/> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (1) | | | | | | 110 (2) | 110 (1) | TP (3) | | | | | 109 (2) | 109 (1) | 16.3 (3) | | | 11 | 108 (1) | 108 (2) | 108 (1) | 16.2 (3) | 92 (1) | | 10 | 107 (1) | 107 (2) | 107 (1) | 16.1 (3) | 91 (1) | | 9 | 106 (1) | 106 (2) | 106 (1) | 16.0 (3) | 90 (1) | | 8 | 105 (1) | 105 (2) | 105 (1) | 15.6 (3) | 89 (1) | | [Show all](#) | | 7 | 104 (1) | 104 (2) | 104 (1) | 15.5 (3) | 88 (1) | | 6 | 103 (1) | 103 (2) | 103 (1) | 15.4 (3) | 87 (1) | | 5.5 | 102 (1) | 102 (2) | 102 (1) | 15.2-15.3 (3) | 86 (1) | | | 101 (1) | 101 (2) | 101 (1) | 15.1 (3) | 85 (1) | | | 100 (1) | 100 (2) | 100 (1) | 15 (3) | 84 (1) | | | 99 (1) | 99 (2) | 99 (1) | 14.1 (3) | 83 (1) | | | 98 (1) | 98 (2) | 98 (1) | 14 (3) | 82 (1) | | | 97 (1) | 97 (2) | 97 (1) | 13.1 (3) | 81 (1) | | | 96 (1) | 96 (2) | 96 (1) | 13 (3) | 80 (1) | | | 95 (1) | 95 (2) | 95 (1) | 12.1 | 79 (1) | | | 94 (1) | 94 (2) | 94 (1) | 12 | 78 (1) | | | 93 (1) | 93 (2) | 93 (1) | 11.1 | 77 (1) | | | 92 (1) | 92 (2) | 92 (1) | 11 | 76 (1) | | | 91 (1) | 91 (2) | 91 (1) | 10.1 | 75 (1) | | | 90 (1) | 90 (2) | 90 (1) | 10 | 74 (1) | | | 89 (1) | 89 (2) | 89 (1) | 9.1 | 73 (1) | | | 88 (1) | 88 (2) | 88 (1) | 9 | 72 (1) | | | 87 (1) | 87 (2) | 87 (1) | 8 | 71 (1) | | | 86 (1) | 86 (2) | 86 (1) | 7.1 | 70 (1) | | | 85 (1) | 85 (2) | 85 (1) | 7 | 69 (1) | | | 84 (1) | 84 (2) | 84 (1) | 6.1 | 68 (1) | | | 83 (1) | 83 (2) | 83 (1) | 6 | 67 (1) | | | 81 (1) | 82 (2) | 81 (1) | 5.1 | 66 (1) | | | 80 (1) | 81 (2) | 80 (1) | 5 | 65 | | | 79 (1) | 80 (2) | 79 (1) | 4 | 64 | | | 18 | 79 (2) | 78 | 3.2 | 63 | | | 17 | 78 (2) | 77 | 3.1 | 62 | | | 16 | 77 (2) | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 (1) | 108 (1) | 107 (2) | 11 | 13.4 | 19.0 (1) | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 (1) | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 (1) | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 (1) | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 (1) | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 (1) | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 (1) | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 (1) | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. This API is very extensive. Many of its features are still in development and/or don't have finalised specs yet. 2. Can be enabled in Firefox behind the `dom.vr.webxr.enabled` flag. 3. Can be enabled in Safari with the `WebXR Device API` experimental feature. Resources --------- * [MDN Web Docs - WebXR Device API](https://developer.mozilla.org/docs/Web/API/WebXR_Device_API) * [Immersive Web - WebXR samples](https://immersive-web.github.io/webxr-samples/) * [Safari implementation bug](https://bugs.webkit.org/show_bug.cgi?id=208988)
programming_docs
browser_support_tables Ogg/Theora video format Ogg/Theora video format ======================= Free lossy video compression format. | | | | --- | --- | | Spec | <https://theora.org/doc/> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Wikipedia article](https://en.wikipedia.org/wiki/Theora) browser_support_tables Web Notifications Web Notifications ================= Method of alerting the user outside of a web page by displaying notifications (that do not require interaction by the user). | | | | --- | --- | | Spec | <https://notifications.spec.whatwg.org/> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 (\*) | | 9 | | | | 21 | 20 (\*) | | | | | | 20 | 19 (\*) | | | | | | 19 | 18 (\*) | | | | | | 18 | 17 (\*) | | | | | | 17 | 16 (\*) | | | | | | 16 | 15 (\*) | | | | | | 15 | 14 (\*) | | | | | | 14 | 13 (\*) | | | | | | 13 | 12 (\*) | | | | | | 12 | 11 (\*) | | | | | | 11 | 10 (\*) | | | | | | 10 | 9 (\*) | | | | | | 9 | 8 (\*) | | | | | | 8 | 7 (\*) | | | | | | 7 | 6 (\*) | | | | | | 6 | 5 (\*) | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 (\*) | 10 | 72 (\*) | 108 (3) | 107 | 11 | 13.4 | 19.0 (2) | 13.1 | 13.18 (2) | 2.5 | | 16.1 | | 4.4.3-4.4.4 (\*) | 7 | 12.1 | | | 10 | | 18.0 (2) | | | | | 16.0 | | 4.4 (\*) | | 12 | | | | | 17.0 (2) | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 (2) | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 (2) | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 (2) | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 (2) | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 (2) | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 (2) | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 (2) | | | | | 13.4-13.7 | | | | | | | | | 9.2 (2) | | | | | 13.3 | | | | | | | | | 8.2 (2) | | | | | 13.2 | | | | | | | | | 7.2-7.4 (2) | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 (2) | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 (2) | | | | | 12.0-12.1 | | | | | | | | | 4 (\*) | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled in `about:flags` 2. Supports notifications via the [Push API](https://caniuse.com/#feat=push-api) but not the Web Notifications API. 3. Chrome for Android requires the call to be made with a [service worker registration](https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API#Service_worker_additions) \* Partial support with prefix. Bugs ---- * Partial support in older Chrome versions refers to using an [older version of the spec](http://www.chromium.org/developers/design-documents/desktop-notifications/api-specification). Support in Safari 6 is limited to Mac OSX 10.8+. * Firefox notifications disappear [after a few seconds](https://bugzilla.mozilla.org/show_bug.cgi?id=875114) * Firefox does not support notifications [sent immediately after one another](https://bugzilla.mozilla.org/show_bug.cgi?id=1007344). Resources --------- * [HTML5 Rocks tutorial](https://www.html5rocks.com/tutorials/notifications/quick/) * [Chromium API](https://www.chromium.org/developers/design-documents/desktop-notifications/api-specification/) * [Add-on](https://addons.mozilla.org/en-us/firefox/addon/221523/) * [MDN Web Docs - Notification](https://developer.mozilla.org/en-US/docs/Web/API/notification) * [SitePoint article](https://www.sitepoint.com/introduction-web-notifications-api/) * [Demo](https://audero.it/demo/web-notifications-api-demo.html) * [Plug-in for support in IE](https://ie-web-notifications.github.io/) browser_support_tables Form attribute Form attribute ============== Attribute for associating input and submit buttons with a form. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/forms.html#attr-fae-form> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Input attribute specification](https://www.w3.org/TR/html5/forms.html#attr-fae-form) * [Article on usage](https://www.impressivewebs.com/html5-form-attribute/) browser_support_tables CSS Container Queries (Size) CSS Container Queries (Size) ============================ Size queries in Container Queries provide a way to query the size of a container, and conditionally apply CSS to the content of that container. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css-contain-3/> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 (3) | | 10 | 107 | 107 | 107 | 16.1 | 91 (3) | | 9 | 106 | 106 | 106 | 16.0 | 90 (1) | | 8 | 105 (3) | 105 | 105 (3) | 15.6 | 89 (1) | | [Show all](#) | | 7 | 104 | 104 | 104 (1) | 15.5 | 88 (1) | | 6 | 103 | 103 | 103 (1) | 15.4 | 87 (1) | | 5.5 | 102 | 102 | 102 (1) | 15.2-15.3 | 86 (1) | | | 101 | 101 | 101 (1) | 15.1 | 85 (1) | | | 100 | 100 | 100 (1) | 15 | 84 (1) | | | 99 | 99 | 99 (1) | 14.1 | 83 (1) | | | 98 | 98 | 98 (1) | 14 | 82 (1) | | | 97 | 97 | 97 (1) | 13.1 | 81 (1) | | | 96 | 96 | 96 (1) | 13 | 80 (1) | | | 95 | 95 | 95 (1) | 12.1 | 79 (1) | | | 94 | 94 | 94 (1) | 12 | 78 | | | 93 | 93 | 93 (1) | 11.1 | 77 | | | 92 | 92 | 92 (1,2) | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled with the "Enable CSS Container Queries" feature flag under `chrome://flags` 2. The initial Chrome prototype used an earlier draft syntax based on the `contain` property 3. Combining size container queries and table layout inside a multicolumn layout doesn't work Resources --------- * [Container Queries: a Quick Start Guide](https://www.oddbird.net/2021/04/05/containerqueries/) * [MDN article](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Container_Queries) * [Chromium support bug](https://crbug.com/1145970) * [Collection of demos](https://codepen.io/collection/XQrgJo) * [WebKit support bug](https://bugs.webkit.org/show_bug.cgi?id=229659) * [Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1744221) * [Container Query Polyfill](https://github.com/GoogleChromeLabs/container-query-polyfill)
programming_docs
browser_support_tables Range input type Range input type ================ Form field type that allows the user to select a value using a slider widget. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/forms.html#range-state-(type=range)> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Currently all Android browsers with partial support hide the slider input field by default. However, the element [can be styled](https://tiffanybbrown.com/2012/02/input-typerange-and-androids-stock-browser/) to be made visible and usable. Bugs ---- * IE10 & 11 have [some bugs related to the `step` value](https://stackoverflow.com/questions/20241415/html5-number-input-field-step-attribute-broken-in-internet-explorer-10-and-inter). * IE10 & 11 [fire the "change" event instead of "input" on mousemove](http://hparra.github.io/html5-input-range/). Resources --------- * [Polyfill for Firefox](https://github.com/fryn/html5slider) * [Cross-browser polyfill](https://github.com/freqdec/fd-slider) * [Tutorial](http://tutorialzine.com/2011/12/what-you-need-to-know-html5-range-input/) * [has.js test](https://raw.github.com/phiggins42/has.js/master/detect/form.js#input-type-range) * [WebPlatform Docs](https://webplatform.github.io/docs/html/elements/input/type/range) * [rangeslider.js polyfill](https://github.com/andreruffert/rangeslider.js) * [MDN web docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range) * [Tutorial](https://tutorialzine.com/2011/12/what-you-need-to-know-html5-range-input) browser_support_tables CSS element() function CSS element() function ====================== This function renders a live image generated from an arbitrary HTML element | | | | --- | --- | | Spec | <https://www.w3.org/TR/css4-images/#element-notation> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 (\*) | 110 | TP | | | | | 109 (\*) | 109 | 16.3 | | | 11 | 108 | 108 (\*) | 108 | 16.2 | 92 | | 10 | 107 | 107 (\*) | 107 | 16.1 | 91 | | 9 | 106 | 106 (\*) | 106 | 16.0 | 90 | | 8 | 105 | 105 (\*) | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 (\*) | 104 | 15.5 | 88 | | 6 | 103 | 103 (\*) | 103 | 15.4 | 87 | | 5.5 | 102 | 102 (\*) | 102 | 15.2-15.3 | 86 | | | 101 | 101 (\*) | 101 | 15.1 | 85 | | | 100 | 100 (\*) | 100 | 15 | 84 | | | 99 | 99 (\*) | 99 | 14.1 | 83 | | | 98 | 98 (\*) | 98 | 14 | 82 | | | 97 | 97 (\*) | 97 | 13.1 | 81 | | | 96 | 96 (\*) | 96 | 13 | 80 | | | 95 | 95 (\*) | 95 | 12.1 | 79 | | | 94 | 94 (\*) | 94 | 12 | 78 | | | 93 | 93 (\*) | 93 | 11.1 | 77 | | | 92 | 92 (\*) | 92 | 11 | 76 | | | 91 | 91 (\*) | 91 | 10.1 | 75 | | | 90 | 90 (\*) | 90 | 10 | 74 | | | 89 | 89 (\*) | 89 | 9.1 | 73 | | | 88 | 88 (\*) | 88 | 9 | 72 | | | 87 | 87 (\*) | 87 | 8 | 71 | | | 86 | 86 (\*) | 86 | 7.1 | 70 | | | 85 | 85 (\*) | 85 | 7 | 69 | | | 84 | 84 (\*) | 84 | 6.1 | 68 | | | 83 | 83 (\*) | 83 | 6 | 67 | | | 81 | 82 (\*) | 81 | 5.1 | 66 | | | 80 | 81 (\*) | 80 | 5 | 65 | | | 79 | 80 (\*) | 79 | 4 | 64 | | | 18 | 79 (\*) | 78 | 3.2 | 63 | | | 17 | 78 (\*) | 77 | 3.1 | 62 | | | 16 | 77 (\*) | 76 | | 60 | | | 15 | 76 (\*) | 75 | | 58 | | | 14 | 75 (\*) | 74 | | 57 | | | 13 | 74 (\*) | 73 | | 56 | | | 12 | 73 (\*) | 72 | | 55 | | | | 72 (\*) | 71 | | 54 | | | | 71 (\*) | 70 | | 53 | | | | 70 (\*) | 69 | | 52 | | | | 69 (\*) | 68 | | 51 | | | | 68 (\*) | 67 | | 50 | | | | 67 (\*) | 66 | | 49 | | | | 66 (\*) | 65 | | 48 | | | | 65 (\*) | 64 | | 47 | | | | 64 (\*) | 63 | | 46 | | | | 63 (\*) | 62 | | 45 | | | | 62 (\*) | 61 | | 44 | | | | 61 (\*) | 60 | | 43 | | | | 60 (\*) | 59 | | 42 | | | | 59 (\*) | 58 | | 41 | | | | 58 (\*) | 57 | | 40 | | | | 57 (\*) | 56 | | 39 | | | | 56 (\*) | 55 | | 38 | | | | 55 (\*) | 54 | | 37 | | | | 54 (\*) | 53 | | 36 | | | | 53 (\*) | 52 | | 35 | | | | 52 (\*) | 51 | | 34 | | | | 51 (\*) | 50 | | 33 | | | | 50 (\*) | 49 | | 32 | | | | 49 (\*) | 48 | | 31 | | | | 48 (\*) | 47 | | 30 | | | | 47 (\*) | 46 | | 29 | | | | 46 (\*) | 45 | | 28 | | | | 45 (\*) | 44 | | 27 | | | | 44 (\*) | 43 | | 26 | | | | 43 (\*) | 42 | | 25 | | | | 42 (\*) | 41 | | 24 | | | | 41 (\*) | 40 | | 23 | | | | 40 (\*) | 39 | | 22 | | | | 39 (\*) | 38 | | 21 | | | | 38 (\*) | 37 | | 20 | | | | 37 (\*) | 36 | | 19 | | | | 36 (\*) | 35 | | 18 | | | | 35 (\*) | 34 | | 17 | | | | 34 (\*) | 33 | | 16 | | | | 33 (\*) | 32 | | 15 | | | | 32 (\*) | 31 | | 12.1 | | | | 31 (\*) | 30 | | 12 | | | | 30 (\*) | 29 | | 11.6 | | | | 29 (\*) | 28 | | 11.5 | | | | 28 (\*) | 27 | | 11.1 | | | | 27 (\*) | 26 | | 11 | | | | 26 (\*) | 25 | | 10.6 | | | | 25 (\*) | 24 | | 10.5 | | | | 24 (\*) | 23 | | 10.0-10.1 | | | | 23 (\*) | 22 | | 9.5-9.6 | | | | 22 (\*) | 21 | | 9 | | | | 21 (\*) | 20 | | | | | | 20 (\*) | 19 | | | | | | 19 (\*) | 18 | | | | | | 18 (\*) | 17 | | | | | | 17 (\*) | 16 | | | | | | 16 (\*) | 15 | | | | | | 15 (\*) | 14 | | | | | | 14 (\*) | 13 | | | | | | 13 (\*) | 12 | | | | | | 12 (\*) | 11 | | | | | | 11 (\*) | 10 | | | | | | 10 (\*) | 9 | | | | | | 9 (\*) | 8 | | | | | | 8 (\*) | 7 | | | | | | 7 (\*) | 6 | | | | | | 6 (\*) | 5 | | | | | | 5 (\*) | 4 | | | | | | 4 (\*) | | | | | | | 3.6 (1,\*) | | | | | | | 3.5 (1,\*) | | | | | | | 3 (1,\*) | | | | | | | 2 (1,\*) | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 (\*) | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 (\*) | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. In Firefox < 4, usage limited to the background and background-image CSS properties \* Partial support with prefix. Bugs ---- * Chromium [bug #108972](https://code.google.com/p/chromium/issues/detail?id=108972) * WebKit [bug #44650](https://bugs.webkit.org/show_bug.cgi?id=44650) Resources --------- * [MDN Web Docs - CSS element](https://developer.mozilla.org/en-US/docs/Web/CSS/element) browser_support_tables CSS widows & orphans CSS widows & orphans ==================== CSS properties to control when lines break across pages or columns by defining the amount of lines that must be left before or after the break. | | | | --- | --- | | Spec | <https://w3c.github.io/csswg-drafts/css-break-3/#widows-orphans> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 (1) | 106 | 106 | 106 | 16.0 | 90 | | 8 (1) | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 (1) | | | | 29 | 28 | | 11.5 (1) | | | | 28 | 27 | | 11.1 (1) | | | | 27 | 26 | | 11 (1) | | | | 26 | 25 | | 10.6 (1) | | | | 25 | 24 | | 10.5 (1) | | | | 24 | 23 | | 10.0-10.1 (1) | | | | 23 | 22 | | 9.5-9.6 (1) | | | | 22 | 21 | | 9 (1) | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Some older WebKit-based browsers recognize the properties, but do not appear to have actual support 1. Supports widows & orphans properties, but due to not supporting CSS multi-columns the support is only for page breaks (for print) Resources --------- * [CSS last-line: Controlling Widows & Orphans](https://thenewcode.com/946/CSS-last-line-Controlling-Widows-amp-Orphans) * [Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=137367) * [codrops article on orphans](https://tympanus.net/codrops/css_reference/orphans/) * [codrops article on widows](https://tympanus.net/codrops/css_reference/widows/)
programming_docs
browser_support_tables Pattern attribute for input fields Pattern attribute for input fields ================================== Allows validation of an input field based on a given regular expression pattern. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/forms.html#the-pattern-attribute> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 (1,2) | 74 | | | 89 | 89 | 89 | 9.1 (1,2) | 73 | | | 88 | 88 | 88 | 9 (1,2) | 72 | | | 87 | 87 | 87 | 8 (1,2) | 71 | | | 86 | 86 | 86 | 7.1 (1,2) | 70 | | | 85 | 85 | 85 | 7 (1,2) | 69 | | | 84 | 84 | 84 | 6.1 (1,2) | 68 | | | 83 | 83 | 83 | 6 (1,2) | 67 | | | 81 | 82 | 81 | 5.1 (1,2) | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 (1) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 (1) | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 (1,2) | | | | | | | | | | | | | | 9.3 (1,2) | | | | | | | | | | | | | | 9.0-9.2 (1,2) | | | | | | | | | | | | | | 8.1-8.4 (1,2) | | | | | | | | | | | | | | 8 (1,2) | | | | | | | | | | | | | | 7.0-7.1 (1,2) | | | | | | | | | | | | | | 6.0-6.1 (1,2) | | | | | | | | | | | | | | 5.0-5.1 (1,2) | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Partial support refers to not displaying a message for invalid patterns 2. Safari browsers support the `pattern` attribute but will still allow forms to be submitted if the pattern is incorrect. See the [form validation data](https://caniuse.com/#feat=form-validation) for details. Resources --------- * [Site with common sample patterns](https://www.html5pattern.com/) * [MDN Web Docs - input element: pattern attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-pattern) browser_support_tables Custom protocol handling Custom protocol handling ======================== Method of allowing a webpage to handle a given protocol using `navigator.registerProtocolHandler`. This allows certain URLs to be opened by a given web application, for example `mailto:` addresses can be opened by a webmail client. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/webappapis.html#custom-handlers> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (1) | | | | | | 110 | 110 (1) | TP | | | | | 109 | 109 (1) | 16.3 | | | 11 | 108 (1) | 108 | 108 (1) | 16.2 | 92 (1) | | 10 | 107 (1) | 107 | 107 (1) | 16.1 | 91 (1) | | 9 | 106 (1) | 106 | 106 (1) | 16.0 | 90 (1) | | 8 | 105 (1) | 105 | 105 (1) | 15.6 | 89 (1) | | [Show all](#) | | 7 | 104 (1) | 104 | 104 (1) | 15.5 | 88 (1) | | 6 | 103 (1) | 103 | 103 (1) | 15.4 | 87 (1) | | 5.5 | 102 (1) | 102 | 102 (1) | 15.2-15.3 | 86 (1) | | | 101 (1) | 101 | 101 (1) | 15.1 | 85 (1) | | | 100 (1) | 100 | 100 (1) | 15 | 84 (1) | | | 99 (1) | 99 | 99 (1) | 14.1 | 83 (1) | | | 98 (1) | 98 | 98 (1) | 14 | 82 (1) | | | 97 (1) | 97 | 97 (1) | 13.1 | 81 (1) | | | 96 (1) | 96 | 96 (1) | 13 | 80 (1) | | | 95 (1) | 95 | 95 (1) | 12.1 | 79 (1) | | | 94 (1) | 94 | 94 (1) | 12 | 78 (1) | | | 93 (1) | 93 | 93 (1) | 11.1 | 77 (1) | | | 92 (1) | 92 | 92 (1) | 11 | 76 (1) | | | 91 (1) | 91 | 91 (1) | 10.1 | 75 (1) | | | 90 (1) | 90 | 90 (1) | 10 | 74 (1) | | | 89 (1) | 89 | 89 (1) | 9.1 | 73 (1) | | | 88 (1) | 88 | 88 (1) | 9 | 72 (1) | | | 87 (1) | 87 | 87 (1) | 8 | 71 (1) | | | 86 (1) | 86 | 86 (1) | 7.1 | 70 (1) | | | 85 (1) | 85 | 85 (1) | 7 | 69 (1) | | | 84 (1) | 84 | 84 (1) | 6.1 | 68 (1) | | | 83 (1) | 83 | 83 (1) | 6 | 67 (1) | | | 81 (1) | 82 | 81 (1) | 5.1 | 66 (1) | | | 80 (1) | 81 | 80 (1) | 5 | 65 (1) | | | 79 (1) | 80 | 79 (1) | 4 | 64 (1) | | | 18 | 79 | 78 (1) | 3.2 | 63 (1) | | | 17 | 78 | 77 (1) | 3.1 | 62 (1) | | | 16 | 77 | 76 (1) | | 60 (1) | | | 15 | 76 | 75 (1) | | 58 (1) | | | 14 | 75 | 74 (1) | | 57 (1) | | | 13 | 74 | 73 (1) | | 56 (1) | | | 12 | 73 | 72 (1) | | 55 (1) | | | | 72 | 71 (1) | | 54 (1) | | | | 71 | 70 (1) | | 53 (1) | | | | 70 | 69 (1) | | 52 (1) | | | | 69 | 68 (1) | | 51 (1) | | | | 68 | 67 (1) | | 50 (1) | | | | 67 | 66 (1) | | 49 (1) | | | | 66 | 65 (1) | | 48 (1) | | | | 65 | 64 (1) | | 47 (1) | | | | 64 | 63 (1) | | 46 (1) | | | | 63 | 62 (1) | | 45 (1) | | | | 62 | 61 (1) | | 44 (1) | | | | 61 | 60 (1) | | 43 (1) | | | | 60 | 59 (1) | | 42 (1) | | | | 59 | 58 (1) | | 41 (1) | | | | 58 | 57 (1) | | 40 (1) | | | | 57 | 56 (1) | | 39 (1) | | | | 56 | 55 (1) | | 38 (1) | | | | 55 | 54 (1) | | 37 (1) | | | | 54 | 53 (1) | | 36 (1) | | | | 53 | 52 (1) | | 35 (1) | | | | 52 | 51 (1) | | 34 (1) | | | | 51 | 50 (1) | | 33 (1) | | | | 50 | 49 (1) | | 32 (1) | | | | 49 | 48 (1) | | 31 (1) | | | | 48 | 47 (1) | | 30 (1) | | | | 47 | 46 (1) | | 29 (1) | | | | 46 | 45 (1) | | 28 (1) | | | | 45 | 44 (1) | | 27 (1) | | | | 44 | 43 (1) | | 26 (1) | | | | 43 | 42 (1) | | 25 (1) | | | | 42 | 41 (1) | | 24 (1) | | | | 41 | 40 (1) | | 23 (1) | | | | 40 | 39 (1) | | 22 (1) | | | | 39 | 38 (1) | | 21 (1) | | | | 38 | 37 (1) | | 20 (1) | | | | 37 | 36 (1) | | 19 (1) | | | | 36 | 35 (1) | | 18 (1) | | | | 35 | 34 (1) | | 17 (1) | | | | 34 | 33 (1) | | 16 (1) | | | | 33 | 32 (1) | | 15 (1) | | | | 32 | 31 (1) | | 12.1 (1) | | | | 31 | 30 (1) | | 12 (1) | | | | 30 | 29 (1) | | 11.6 (1) | | | | 29 | 28 (1) | | 11.5 | | | | 28 | 27 (1) | | 11.1 | | | | 27 | 26 (1) | | 11 | | | | 26 | 25 (1) | | 10.6 | | | | 25 | 24 (1) | | 10.5 | | | | 24 | 23 (1) | | 10.0-10.1 | | | | 23 | 22 (1) | | 9.5-9.6 | | | | 22 | 21 (1) | | 9 | | | | 21 | 20 (1) | | | | | | 20 | 19 (1) | | | | | | 19 | 18 (1) | | | | | | 18 | 17 (1) | | | | | | 17 | 16 (1) | | | | | | 16 | 15 (1) | | | | | | 15 | 14 (1) | | | | | | 14 | 13 (1) | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 (1) | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Supports protocols `mailto`, `mms`, `nntp`, `rtsp`, and `webcal` but requires custom protocols to start with `web+` Resources --------- * [MDN Web Docs - Register protocol handler](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/registerProtocolHandler) browser_support_tables document.head document.head ============= Convenience property for accessing the `<head>` element | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/#dom-document-head> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [MDN Web Docs - head](https://developer.mozilla.org/en-US/docs/Web/API/Document/head) browser_support_tables URLSearchParams URLSearchParams =============== The URLSearchParams interface defines utility methods to work with the query string of a URL. | | | | --- | --- | | Spec | <https://url.spec.whatwg.org/#urlsearchparams> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 (1) | 42 | | 25 | | | | 42 (1) | 41 | | 24 | | | | 41 (1) | 40 | | 23 | | | | 40 (1) | 39 | | 22 | | | | 39 (1) | 38 | | 21 | | | | 38 (1) | 37 | | 20 | | | | 37 (1) | 36 | | 19 | | | | 36 (1) | 35 | | 18 | | | | 35 (1) | 34 | | 17 | | | | 34 (1) | 33 | | 16 | | | | 33 (1) | 32 | | 15 | | | | 32 (1) | 31 | | 12.1 | | | | 31 (1) | 30 | | 12 | | | | 30 (1) | 29 | | 11.6 | | | | 29 (1) | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Partial support refers to only supporting `entries()`, `keys()`, `values()`, and `for...of`. Resources --------- * [Easy URL manipulation with URLSearchParams](https://developers.google.com/web/updates/2016/01/urlsearchparams?hl=en) * [MDN Web Docs - URLSearchParams](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) * [Polyfill for this feature is available in the core-js library](https://github.com/zloirock/core-js#url-and-urlsearchparams) * [EdgeHTML implementation bug](https://web.archive.org/web/20190624214230/https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8993198/)
programming_docs
browser_support_tables HTTP Live Streaming (HLS) HTTP Live Streaming (HLS) ========================= HTTP-based media streaming communications protocol | | | | --- | --- | | Spec | <https://tools.ietf.org/html/rfc8216> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- HLS can be used with a JavaScript library in browsers that doesn't support it natively as long as they support [Media Source Extensions](/mediasource). Resources --------- * [Wikipedia article](https://en.wikipedia.org/wiki/HTTP_Live_Streaming) * [Apple developer article](https://developer.apple.com/streaming/) browser_support_tables Object.observe data binding Object.observe data binding =========================== Method for data binding, a now-withdrawn ECMAScript 7 proposal | | | | --- | --- | | Spec | <http://wiki.ecmascript.org/doku.php?id=harmony:observe> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Support in Blink-based browsers is expected to be removed in future versions. Resources --------- * [Data-binding Revolutions with Object.observe()](https://www.html5rocks.com/en/tutorials/es7/observe/) * [Polyfill](https://github.com/MaxArt2501/object-observe) * [Firefox tracking bug](https://bugzilla.mozilla.org/show_bug.cgi?id=800355) * [An update on Object.observe](https://esdiscuss.org/topic/an-update-on-object-observe) browser_support_tables CSS Table display CSS Table display ================= Method of displaying elements as tables, rows, and cells. Includes support for all `display: table-*` properties as well as `display: inline-table` | | | | --- | --- | | Spec | <https://www.w3.org/TR/CSS21/tables.html> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 (1) | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Firefox 2 does not support `inline-table` Bugs ---- * Safari 5.1.17 has a bug in when using an element with display:table, with padding and width. It seems to force the use of the border-box model instead of the content-box model. Chrome 21.0 however works correctly, making it difficult to resolve with CSS alone. * Firefox has had a bug with `position: relative` in table cells, which was fixed in version 37. Resources --------- * [Blog post on usage](https://www.onenaught.com/posts/201/use-css-displaytable-for-layout) browser_support_tables CSS min/max-width/height CSS min/max-width/height ======================== Method of setting a minimum or maximum width or height to an element. | | | | --- | --- | | Spec | <https://www.w3.org/TR/CSS21/visudet.html#min-max-widths> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 (2) | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 (1) | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. IE7 does not support `inherit` as a value on any of these properties. 2. IE8 has some bugs with `max-width`/`height` combined with `overflow: auto`/`scroll`. Bugs ---- * `max-width` doesn't work with images in table cells in IE. * IE7 doesn't support `min-width` on input button/submit button/reset button. * Safari on iOS 5.1 does not support `min-width` on table elements. * Firefox does not support `min-height` on table elements or elements with `display: table` * IE10 and IE11 do not appear to support overriding `min-width` or `max-width` values using the `initial` value. Resources --------- * [JS library with support](https://code.google.com/archive/p/ie7-js/) * [WebPlatform Docs](https://webplatform.github.io/docs/css/properties/min-width) * [CSS Basics post](https://www.impressivewebs.com/min-max-width-height-css/)
programming_docs
browser_support_tables localeCompare() localeCompare() =============== The `localeCompare()` method returns a number indicating whether a reference string comes before or after or is the same as the given string in sort order. | | | | --- | --- | | Spec | <https://tc39.es/ecma402/#sup-String.prototype.localeCompare> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 (1) | 107 | 107 | 107 | 16.1 | 91 | | 9 (1) | 106 | 106 | 106 | 16.0 | 90 | | 8 (1) | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 (1) | 104 | 104 | 104 | 15.5 | 88 | | 6 (1) | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 (1) | 73 | | | 88 | 88 | 88 | 9 (1) | 72 | | | 87 | 87 | 87 | 8 (1) | 71 | | | 86 | 86 | 86 | 7.1 (1) | 70 | | | 85 | 85 | 85 | 7 (1) | 69 | | | 84 | 84 | 84 | 6.1 (1) | 68 | | | 83 | 83 | 83 | 6 (1) | 67 | | | 81 | 82 | 81 | 5.1 (1) | 66 | | | 80 | 81 | 80 | 5 (1) | 65 | | | 79 | 80 | 79 | 4 (1) | 64 | | | 18 | 79 | 78 | 3.2 (1) | 63 | | | 17 | 78 | 77 | 3.1 (1) | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 (1) | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 (1) | 27 | | 11.1 | | | | 27 (1) | 26 | | 11 | | | | 26 (1) | 25 | | 10.6 | | | | 25 (1) | 24 | | 10.5 | | | | 24 (1) | 23 (1) | | 10.0-10.1 | | | | 23 (1) | 22 (1) | | 9.5-9.6 | | | | 22 (1) | 21 (1) | | 9 | | | | 21 (1) | 20 (1) | | | | | | 20 (1) | 19 (1) | | | | | | 19 (1) | 18 (1) | | | | | | 18 (1) | 17 (1) | | | | | | 17 (1) | 16 (1) | | | | | | 16 (1) | 15 (1) | | | | | | 15 (1) | 14 (1) | | | | | | 14 (1) | 13 (1) | | | | | | 13 (1) | 12 (1) | | | | | | 12 (1) | 11 (1) | | | | | | 11 (1) | 10 (1) | | | | | | 10 (1) | 9 (1) | | | | | | 9 (1) | 8 (1) | | | | | | 8 (1) | 7 (1) | | | | | | 7 (1) | 6 (1) | | | | | | 6 (1) | 5 (1) | | | | | | 5 (1) | 4 (1) | | | | | | 4 (1) | | | | | | | 3.6 (1) | | | | | | | 3.5 (1) | | | | | | | 3 (1) | | | | | | | 2 (1) | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all (1) | 108 | 10 (1) | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 (1) | 12.1 (1) | | | 10 (1) | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 (1) | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 (1) | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 (1) | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 (1) | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 (1) | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 (1) | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 (1) | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 (1) | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 (1) | | | | | | | | | | | | | | 9.0-9.2 (1) | | | | | | | | | | | | | | 8.1-8.4 (1) | | | | | | | | | | | | | | 8 (1) | | | | | | | | | | | | | | 7.0-7.1 (1) | | | | | | | | | | | | | | 6.0-6.1 (1) | | | | | | | | | | | | | | 5.0-5.1 (1) | | | | | | | | | | | | | | 4.2-4.3 (1) | | | | | | | | | | | | | | 4.0-4.1 (1) | | | | | | | | | | | | | | 3.2 (1) | | | | | | | | | | | | | Notes ----- 1. Only supports basic support without locale & options parameters. Resources --------- * [MDN article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare) browser_support_tables Array.prototype.includes Array.prototype.includes ======================== Determines whether or not an array includes the given value, returning a boolean value (unlike `indexOf`). | | | | --- | --- | | Spec | <https://tc39.es/ecma262/#sec-array.prototype.includes> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes#Browser_compatibility) * [Polyfill for this feature is available in the core-js library](https://github.com/zloirock/core-js#ecmascript-array) browser_support_tables CSS Container Query Units CSS Container Query Units ========================= Container Query Units specify a length relative to the dimensions of a query container. The units include: `cqw`, `cqh`, `cqi`, `cqb`, `cqmin`, and `cqmax`. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css-contain-3/#container-lengths> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 (1) | | 8 | 105 | 105 | 105 | 15.6 | 89 (1) | | [Show all](#) | | 7 | 104 | 104 | 104 (1) | 15.5 | 88 (1) | | 6 | 103 | 103 | 103 (1) | 15.4 | 87 (1) | | 5.5 | 102 | 102 | 102 (1) | 15.2-15.3 | 86 (1) | | | 101 | 101 | 101 (1) | 15.1 | 85 (1) | | | 100 | 100 | 100 (1,2) | 15 | 84 (1) | | | 99 | 99 | 99 (1,2) | 14.1 | 83 (1) | | | 98 | 98 | 98 (1,2) | 14 | 82 (1) | | | 97 | 97 | 97 (1,2) | 13.1 | 81 (1) | | | 96 | 96 | 96 (1,2) | 13 | 80 (1) | | | 95 | 95 | 95 (1,2) | 12.1 | 79 (1) | | | 94 | 94 | 94 (1,2) | 12 | 78 | | | 93 | 93 | 93 (1,2) | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Can be enabled with the "Enable CSS Container Queries" feature flag under `chrome://flags` 2. The initial Chrome implementation used an earlier spec draft syntax: `q*` units Resources --------- * [Blog post: CSS Container Query Units](https://ishadeed.com/article/container-query-units/) * [CSS Tricks: Container Units Should Be Pretty Handy](https://css-tricks.com/container-units-should-be-pretty-handy/) * [Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1744231) browser_support_tables CSS Gradients CSS Gradients ============= Method of defining a linear or radial color gradient as a CSS image. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css3-images/> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 (2) | 86 | | | 101 | 101 | 101 | 15.1 (2) | 85 | | | 100 | 100 | 100 | 15 (2) | 84 | | | 99 | 99 | 99 | 14.1 (2) | 83 | | | 98 | 98 | 98 | 14 (2) | 82 | | | 97 | 97 | 97 | 13.1 (2) | 81 | | | 96 | 96 | 96 | 13 (2) | 80 | | | 95 | 95 | 95 | 12.1 (2) | 79 | | | 94 | 94 | 94 | 12 (2) | 78 | | | 93 | 93 | 93 | 11.1 (2) | 77 | | | 92 | 92 | 92 | 11 (2) | 76 | | | 91 | 91 | 91 | 10.1 (2) | 75 | | | 90 | 90 | 90 | 10 (2) | 74 | | | 89 | 89 | 89 | 9.1 (2) | 73 | | | 88 | 88 | 88 | 9 (2) | 72 | | | 87 | 87 | 87 | 8 (2) | 71 | | | 86 | 86 | 86 | 7.1 (2) | 70 | | | 85 | 85 | 85 | 7 (2) | 69 | | | 84 | 84 | 84 | 6.1 (2) | 68 | | | 83 | 83 | 83 | 6 (2,\*) | 67 | | | 81 | 82 | 81 | 5.1 (2,\*) | 66 | | | 80 | 81 | 80 | 5 (2,3,\*) | 65 | | | 79 | 80 | 79 | 4 (2,3,\*) | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 (2) | 34 | | 17 | | | | 34 (2) | 33 | | 16 | | | | 33 (2) | 32 | | 15 | | | | 32 (2) | 31 | | 12.1 | | | | 31 (2) | 30 | | 12 (\*) | | | | 30 (2) | 29 | | 11.6 (\*) | | | | 29 (2) | 28 | | 11.5 (1,\*) | | | | 28 (2) | 27 | | 11.1 (1,\*) | | | | 27 (2) | 26 | | 11 | | | | 26 (2) | 25 (\*) | | 10.6 | | | | 25 (2) | 24 (\*) | | 10.5 | | | | 24 (2) | 23 (\*) | | 10.0-10.1 | | | | 23 (2) | 22 (\*) | | 9.5-9.6 | | | | 22 (2) | 21 (\*) | | 9 | | | | 21 (2) | 20 (\*) | | | | | | 20 (2) | 19 (\*) | | | | | | 19 (2) | 18 (\*) | | | | | | 18 (2) | 17 (\*) | | | | | | 17 (2) | 16 (\*) | | | | | | 16 (2) | 15 (\*) | | | | | | 15 (2,\*) | 14 (\*) | | | | | | 14 (2,\*) | 13 (\*) | | | | | | 13 (2,\*) | 12 (\*) | | | | | | 12 (2,\*) | 11 (\*) | | | | | | 11 (2,\*) | 10 (\*) | | | | | | 10 (2,\*) | 9 (3,\*) | | | | | | 9 (2,\*) | 8 (3,\*) | | | | | | 8 (2,\*) | 7 (3,\*) | | | | | | 7 (2,\*) | 6 (3,\*) | | | | | | 6 (2,\*) | 5 (3,\*) | | | | | | 5 (2,\*) | 4 (3,\*) | | | | | | 4 (2,\*) | | | | | | | 3.6 (2,\*) | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 (3,\*) | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 (\*) | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 (\*) | | 11.5 (1,\*) | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 (\*) | | 11.1 (1,\*) | | | | | 15.0 | | | | | 15.4 | | 4 (\*) | | 11 | | | | | 14.0 | | | | | 15.2-15.3 (2) | | 3 (3,\*) | | 10 | | | | | 13.0 | | | | | 15.0-15.1 (2) | | 2.3 (3,\*) | | | | | | | 12.0 | | | | | 14.5-14.8 (2) | | 2.2 (3,\*) | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (2) | | 2.1 (3,\*) | | | | | | | 10.1 | | | | | 13.4-13.7 (2) | | | | | | | | | 9.2 | | | | | 13.3 (2) | | | | | | | | | 8.2 | | | | | 13.2 (2) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (2) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (2) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 (2) | | | | | | | | | 4 | | | | | 11.3-11.4 (2) | | | | | | | | | | | | | | 11.0-11.2 (2) | | | | | | | | | | | | | | 10.3 (2) | | | | | | | | | | | | | | 10.0-10.2 (2) | | | | | | | | | | | | | | 9.3 (2) | | | | | | | | | | | | | | 9.0-9.2 (2) | | | | | | | | | | | | | | 8.1-8.4 (2) | | | | | | | | | | | | | | 8 (2) | | | | | | | | | | | | | | 7.0-7.1 (2) | | | | | | | | | | | | | | 6.0-6.1 (2,\*) | | | | | | | | | | | | | | 5.0-5.1 (2,\*) | | | | | | | | | | | | | | 4.2-4.3 (2,3,\*) | | | | | | | | | | | | | | 4.0-4.1 (2,3,\*) | | | | | | | | | | | | | | 3.2 (2,3,\*) | | | | | | | | | | | | | Notes ----- Syntax used by browsers with prefixed support may be incompatible with that for proper support. Support can be somewhat emulated in older IE versions using the non-standard "gradient" filter. Firefox 10+, Opera 11.6+, Chrome 26+ and IE10+ also support the new "to (side)" syntax. 1. Partial support in Opera 11.10 and 11.50 also refers to only having support for linear gradients. 2. Partial support in Safari and Older Firefox versions refers to not using premultiplied colors which results in unexpected behavior when using the transparent keyword as advised by the [spec](https://www.w3.org/TR/2012/CR-css3-images-20120417/#color-stop-syntax). 3. Implements an earlier prefixed syntax as `-webkit-gradient` \* Partial support with prefix. Resources --------- * [Cross-browser editor](https://www.colorzilla.com/gradient-editor/) * [Tool to emulate support in IE](http://css3pie.com/) * [WebPlatform Docs](https://webplatform.github.io/docs/css/functions/linear-gradient)
programming_docs
browser_support_tables text-emphasis styling text-emphasis styling ===================== Method of using small symbols next to each glyph to emphasize a run of text, commonly used in East Asian languages. The `text-emphasis` shorthand, and its `text-emphasis-style` and `text-emphasis-color` longhands, can be used to apply marks to the text. The `text-emphasis-position` property, which inherits separately, allows setting the emphasis marks' position with respect to the text. | | | | --- | --- | | Spec | <https://w3c.github.io/csswg-drafts/css-text-decor-3/#text-emphasis-property> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 (1,\*) | | | 100 | 100 | 100 | 15 | 84 (1,\*) | | | 99 | 99 | 99 | 14.1 | 83 (1,\*) | | | 98 (1,\*) | 98 | 98 (1,\*) | 14 | 82 (1,\*) | | | 97 (1,\*) | 97 | 97 (1,\*) | 13.1 | 81 (1,\*) | | | 96 (1,\*) | 96 | 96 (1,\*) | 13 | 80 (1,\*) | | | 95 (1,\*) | 95 | 95 (1,\*) | 12.1 | 79 (1,\*) | | | 94 (1,\*) | 94 | 94 (1,\*) | 12 | 78 (1,\*) | | | 93 (1,\*) | 93 | 93 (1,\*) | 11.1 | 77 (1,\*) | | | 92 (1,\*) | 92 | 92 (1,\*) | 11 | 76 (1,\*) | | | 91 (1,\*) | 91 | 91 (1,\*) | 10.1 | 75 (1,\*) | | | 90 (1,\*) | 90 | 90 (1,\*) | 10 | 74 (1,\*) | | | 89 (1,\*) | 89 | 89 (1,\*) | 9.1 | 73 (1,\*) | | | 88 (1,\*) | 88 | 88 (1,\*) | 9 | 72 (1,\*) | | | 87 (1,\*) | 87 | 87 (1,\*) | 8 | 71 (1,\*) | | | 86 (1,\*) | 86 | 86 (1,\*) | 7.1 | 70 (1,\*) | | | 85 (1,\*) | 85 | 85 (1,\*) | 7 (1,\*) | 69 (1,\*) | | | 84 (1,\*) | 84 | 84 (1,\*) | 6.1 (1,\*) | 68 (1,\*) | | | 83 (1,\*) | 83 | 83 (1,\*) | 6 | 67 (1,\*) | | | 81 (1,\*) | 82 | 81 (1,\*) | 5.1 | 66 (1,\*) | | | 80 (1,\*) | 81 | 80 (1,\*) | 5 | 65 (1,\*) | | | 79 (1,\*) | 80 | 79 (1,\*) | 4 | 64 (1,\*) | | | 18 | 79 | 78 (1,\*) | 3.2 | 63 (1,\*) | | | 17 | 78 | 77 (1,\*) | 3.1 | 62 (1,\*) | | | 16 | 77 | 76 (1,\*) | | 60 (1,\*) | | | 15 | 76 | 75 (1,\*) | | 58 (1,\*) | | | 14 | 75 | 74 (1,\*) | | 57 (1,\*) | | | 13 | 74 | 73 (1,\*) | | 56 (1,\*) | | | 12 | 73 | 72 (1,\*) | | 55 (1,\*) | | | | 72 | 71 (1,\*) | | 54 (1,\*) | | | | 71 | 70 (1,\*) | | 53 (1,\*) | | | | 70 | 69 (1,\*) | | 52 (1,\*) | | | | 69 | 68 (1,\*) | | 51 (1,\*) | | | | 68 | 67 (1,\*) | | 50 (1,\*) | | | | 67 | 66 (1,\*) | | 49 (1,\*) | | | | 66 | 65 (1,\*) | | 48 (1,\*) | | | | 65 | 64 (1,\*) | | 47 (1,\*) | | | | 64 | 63 (1,\*) | | 46 (1,\*) | | | | 63 | 62 (1,\*) | | 45 (1,\*) | | | | 62 | 61 (1,\*) | | 44 (1,\*) | | | | 61 | 60 (1,\*) | | 43 (1,\*) | | | | 60 | 59 (1,\*) | | 42 (1,\*) | | | | 59 | 58 (1,\*) | | 41 (1,\*) | | | | 58 | 57 (1,\*) | | 40 (1,\*) | | | | 57 | 56 (1,\*) | | 39 (1,\*) | | | | 56 | 55 (1,\*) | | 38 (1,\*) | | | | 55 | 54 (1,\*) | | 37 (1,\*) | | | | 54 | 53 (1,\*) | | 36 (1,\*) | | | | 53 | 52 (1,\*) | | 35 (1,\*) | | | | 52 | 51 (1,\*) | | 34 (1,\*) | | | | 51 | 50 (1,\*) | | 33 (1,\*) | | | | 50 | 49 (1,\*) | | 32 (1,\*) | | | | 49 | 48 (1,\*) | | 31 (1,\*) | | | | 48 | 47 (1,\*) | | 30 (1,\*) | | | | 47 | 46 (1,\*) | | 29 (1,\*) | | | | 46 | 45 (1,\*) | | 28 (1,\*) | | | | 45 (2) | 44 (1,\*) | | 27 (1,\*) | | | | 44 | 43 (1,\*) | | 26 (1,\*) | | | | 43 | 42 (1,\*) | | 25 (1,\*) | | | | 42 | 41 (1,\*) | | 24 (1,\*) | | | | 41 | 40 (1,\*) | | 23 (1,\*) | | | | 40 | 39 (1,\*) | | 22 (1,\*) | | | | 39 | 38 (1,\*) | | 21 (1,\*) | | | | 38 | 37 (1,\*) | | 20 (1,\*) | | | | 37 | 36 (1,\*) | | 19 (1,\*) | | | | 36 | 35 (1,\*) | | 18 (1,\*) | | | | 35 | 34 (1,\*) | | 17 (1,\*) | | | | 34 | 33 (1,\*) | | 16 (1,\*) | | | | 33 | 32 (1,\*) | | 15 (1,\*) | | | | 32 | 31 (1,\*) | | 12.1 | | | | 31 | 30 (1,\*) | | 12 | | | | 30 | 29 (1,\*) | | 11.6 | | | | 29 | 28 (1,\*) | | 11.5 | | | | 28 | 27 (1,\*) | | 11.1 | | | | 27 | 26 (1,\*) | | 11 | | | | 26 | 25 (1,\*) | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 (1,\*) | 72 | 108 | 107 | 11 | 13.4 (1,\*) | 19.0 | 13.1 (1,\*) | 13.18 (1,\*) | 2.5 | | 16.1 | | 4.4.3-4.4.4 (1,\*) | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 (1,\*) | | 12 | | | | | 17.0 (1,\*) | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 (1,\*) | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 (1,\*) | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 (1,\*) | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 (1,\*) | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 (1,\*) | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 (1,\*) | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 (1,\*) | | | | | 13.4-13.7 | | | | | | | | | 9.2 (1,\*) | | | | | 13.3 | | | | | | | | | 8.2 (1,\*) | | | | | 13.2 | | | | | | | | | 7.2-7.4 (1,\*) | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 (1,\*) | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 (1,\*) | | | | | 12.0-12.1 | | | | | | | | | 4 (1,\*) | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Some old WebKit browsers (like Chrome 24) support `-webkit-text-emphasis`, but does not support CJK languages and is therefore considered unsupported. 1. Partial support refers to incorrect support for `-webkit-text-emphasis-position`. These browsers support `over` and `under` as values, but not the added `left` and `right` values required by the spec. 2. Can be enabled in Firefox using the `layout.css.text-emphasis.enabled` flag \* Partial support with prefix. Bugs ---- * Chrome on Android occasionally has issues rendering emphasis glyphs correctly. Resources --------- * [A javascript fallback for CSS3 emphasis mark.](https://github.com/zmmbreeze/jquery.emphasis/) * [MDN Web Docs - text-emphasis](https://developer.mozilla.org/en-US/docs/Web/CSS/text-emphasis) * [Chromium bug to unprefix `-webkit-text-emphasis`](https://bugs.chromium.org/p/chromium/issues/detail?id=666433) browser_support_tables Auxclick Auxclick ======== The click event for non-primary buttons of input devices | | | | --- | --- | | Spec | <https://w3c.github.io/uievents/#event-type-auxclick> | | Status | W3C Working Draft | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 (1) | 110 | TP | | | | | 109 (1) | 109 | 16.3 | | | 11 | 108 | 108 (1) | 108 | 16.2 | 92 | | 10 | 107 | 107 (1) | 107 | 16.1 | 91 | | 9 | 106 | 106 (1) | 106 | 16.0 | 90 | | 8 | 105 | 105 (1) | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 (1) | 104 | 15.5 | 88 | | 6 | 103 | 103 (1) | 103 | 15.4 | 87 | | 5.5 | 102 | 102 (1) | 102 | 15.2-15.3 | 86 | | | 101 | 101 (1) | 101 | 15.1 | 85 | | | 100 | 100 (1) | 100 | 15 | 84 | | | 99 | 99 (1) | 99 | 14.1 | 83 | | | 98 | 98 (1) | 98 | 14 | 82 | | | 97 | 97 (1) | 97 | 13.1 | 81 | | | 96 | 96 (1) | 96 | 13 | 80 | | | 95 | 95 (1) | 95 | 12.1 | 79 | | | 94 | 94 (1) | 94 | 12 | 78 | | | 93 | 93 (1) | 93 | 11.1 | 77 | | | 92 | 92 (1) | 92 | 11 | 76 | | | 91 | 91 (1) | 91 | 10.1 | 75 | | | 90 | 90 (1) | 90 | 10 | 74 | | | 89 | 89 (1) | 89 | 9.1 | 73 | | | 88 | 88 (1) | 88 | 9 | 72 | | | 87 | 87 (1) | 87 | 8 | 71 | | | 86 | 86 (1) | 86 | 7.1 | 70 | | | 85 | 85 (1) | 85 | 7 | 69 | | | 84 | 84 (1) | 84 | 6.1 | 68 | | | 83 | 83 (1) | 83 | 6 | 67 | | | 81 | 82 (1) | 81 | 5.1 | 66 | | | 80 | 81 (1) | 80 | 5 | 65 | | | 79 | 80 (1) | 79 | 4 | 64 | | | 18 | 79 (1) | 78 | 3.2 | 63 | | | 17 | 78 (1) | 77 | 3.1 | 62 | | | 16 | 77 (1) | 76 | | 60 | | | 15 | 76 (1) | 75 | | 58 | | | 14 | 75 (1) | 74 | | 57 | | | 13 | 74 (1) | 73 | | 56 | | | 12 | 73 (1) | 72 | | 55 | | | | 72 (1) | 71 | | 54 | | | | 71 (1) | 70 | | 53 | | | | 70 (1) | 69 | | 52 | | | | 69 (1) | 68 | | 51 | | | | 68 (1) | 67 | | 50 | | | | 67 (1) | 66 | | 49 | | | | 66 (1) | 65 | | 48 | | | | 65 (1) | 64 | | 47 | | | | 64 (1) | 63 | | 46 | | | | 63 (1) | 62 | | 45 | | | | 62 (1) | 61 | | 44 | | | | 61 (1) | 60 | | 43 | | | | 60 (1) | 59 | | 42 | | | | 59 (1) | 58 | | 41 | | | | 58 (1) | 57 | | 40 | | | | 57 (1) | 56 | | 39 | | | | 56 (1) | 55 | | 38 | | | | 55 (1) | 54 | | 37 | | | | 54 (1) | 53 | | 36 | | | | 53 (1) | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- With introduction of this feature there will be no longer click event fired for non-primary buttons 1. As a compatibility measure, Firefox continues to fire the click event for document and window level event handlers. Resources --------- * [MDN Web Docs - auxclick](https://developer.mozilla.org/en-US/docs/Web/Events/auxclick) * [Firefox implementation](https://bugzilla.mozilla.org/show_bug.cgi?id=1304044) * [WebKit bug](https://bugs.webkit.org/show_bug.cgi?id=22382) * [Original Proposal](https://wicg.github.io/auxclick/) browser_support_tables CSS Shapes Level 1 CSS Shapes Level 1 ================== Allows geometric shapes to be set in CSS to define an area for text to flow around. Includes properties `shape-outside`, `shape-margin` and `shape-image-threshold` | | | | --- | --- | | Spec | <https://www.w3.org/TR/css-shapes/> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 (\*) | 74 | | | 89 | 89 | 89 | 9.1 (\*) | 73 | | | 88 | 88 | 88 | 9 (\*) | 72 | | | 87 | 87 | 87 | 8 (\*) | 71 | | | 86 | 86 | 86 | 7.1 (\*) | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 (2) | 60 | | 43 | | | | 60 (2) | 59 | | 42 | | | | 59 (2) | 58 | | 41 | | | | 58 (2) | 57 | | 40 | | | | 57 (2) | 56 | | 39 | | | | 56 (2) | 55 | | 38 | | | | 55 (2) | 54 | | 37 | | | | 54 (2) | 53 | | 36 | | | | 53 (2) | 52 | | 35 | | | | 52 (2) | 51 | | 34 | | | | 51 (2) | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 (1) | | 19 | | | | 36 | 35 (1) | | 18 | | | | 35 | 34 (1) | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 (\*) | | | | | | | | | | | | | | 9.3 (\*) | | | | | | | | | | | | | | 9.0-9.2 (\*) | | | | | | | | | | | | | | 8.1-8.4 (\*) | | | | | | | | | | | | | | 8 (\*) | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Enabled in Chrome through the "experimental Web Platform features" flag in chrome://flags 2. Partially supported in Firefox by enabling "layout.css.shape-outside.enabled" in about:config \* Partial support with prefix. Resources --------- * [A List Apart article](https://alistapart.com/article/css-shapes-101/) * [Firefox tracking bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1040714)
programming_docs
browser_support_tables Background-clip: text Background-clip: text ===================== Non-standard method of clipping a background image to the foreground text. | | | | --- | --- | | Spec | <https://compat.spec.whatwg.org/#the-webkit-background-clip-property> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (\*) | | | | | | 110 | 110 (\*) | TP | | | | | 109 | 109 (\*) | 16.3 | | | 11 | 108 (\*) | 108 | 108 (\*) | 16.2 | 92 (\*) | | 10 | 107 (\*) | 107 | 107 (\*) | 16.1 | 91 (\*) | | 9 | 106 (\*) | 106 | 106 (\*) | 16.0 | 90 (\*) | | 8 | 105 (\*) | 105 | 105 (\*) | 15.6 | 89 (\*) | | [Show all](#) | | 7 | 104 (\*) | 104 | 104 (\*) | 15.5 | 88 (\*) | | 6 | 103 (\*) | 103 | 103 (\*) | 15.4 | 87 (\*) | | 5.5 | 102 (\*) | 102 | 102 (\*) | 15.2-15.3 | 86 (\*) | | | 101 (\*) | 101 | 101 (\*) | 15.1 | 85 (\*) | | | 100 (\*) | 100 | 100 (\*) | 15 | 84 (\*) | | | 99 (\*) | 99 | 99 (\*) | 14.1 | 83 (\*) | | | 98 (\*) | 98 | 98 (\*) | 14 | 82 (\*) | | | 97 (\*) | 97 | 97 (\*) | 13.1 (\*) | 81 (\*) | | | 96 (\*) | 96 | 96 (\*) | 13 (\*) | 80 (\*) | | | 95 (\*) | 95 | 95 (\*) | 12.1 (\*) | 79 (\*) | | | 94 (\*) | 94 | 94 (\*) | 12 (\*) | 78 (\*) | | | 93 (\*) | 93 | 93 (\*) | 11.1 (\*) | 77 (\*) | | | 92 (\*) | 92 | 92 (\*) | 11 (\*) | 76 (\*) | | | 91 (\*) | 91 | 91 (\*) | 10.1 (\*) | 75 (\*) | | | 90 (\*) | 90 | 90 (\*) | 10 (\*) | 74 (\*) | | | 89 (\*) | 89 | 89 (\*) | 9.1 (\*) | 73 (\*) | | | 88 (\*) | 88 | 88 (\*) | 9 (\*) | 72 (\*) | | | 87 (\*) | 87 | 87 (\*) | 8 (\*) | 71 (\*) | | | 86 (\*) | 86 | 86 (\*) | 7.1 (\*) | 70 (\*) | | | 85 (\*) | 85 | 85 (\*) | 7 (\*) | 69 (\*) | | | 84 (\*) | 84 | 84 (\*) | 6.1 (\*) | 68 (\*) | | | 83 (\*) | 83 | 83 (\*) | 6 (\*) | 67 (\*) | | | 81 (\*) | 82 | 81 (\*) | 5.1 (\*) | 66 (\*) | | | 80 (\*) | 81 | 80 (\*) | 5 (\*) | 65 (\*) | | | 79 (\*) | 80 | 79 (\*) | 4 (\*) | 64 (\*) | | | 18 | 79 | 78 (\*) | 3.2 | 63 (\*) | | | 17 | 78 | 77 (\*) | 3.1 | 62 (\*) | | | 16 | 77 | 76 (\*) | | 60 (\*) | | | 15 | 76 | 75 (\*) | | 58 (\*) | | | 14 (\*) | 75 | 74 (\*) | | 57 (\*) | | | 13 (\*) | 74 | 73 (\*) | | 56 (\*) | | | 12 (\*) | 73 | 72 (\*) | | 55 (\*) | | | | 72 | 71 (\*) | | 54 (\*) | | | | 71 | 70 (\*) | | 53 (\*) | | | | 70 | 69 (\*) | | 52 (\*) | | | | 69 | 68 (\*) | | 51 (\*) | | | | 68 | 67 (\*) | | 50 (\*) | | | | 67 | 66 (\*) | | 49 (\*) | | | | 66 | 65 (\*) | | 48 (\*) | | | | 65 | 64 (\*) | | 47 (\*) | | | | 64 | 63 (\*) | | 46 (\*) | | | | 63 | 62 (\*) | | 45 (\*) | | | | 62 | 61 (\*) | | 44 (\*) | | | | 61 | 60 (\*) | | 43 (\*) | | | | 60 | 59 (\*) | | 42 (\*) | | | | 59 | 58 (\*) | | 41 (\*) | | | | 58 | 57 (\*) | | 40 (\*) | | | | 57 | 56 (\*) | | 39 (\*) | | | | 56 | 55 (\*) | | 38 (\*) | | | | 55 | 54 (\*) | | 37 (\*) | | | | 54 | 53 (\*) | | 36 (\*) | | | | 53 | 52 (\*) | | 35 (\*) | | | | 52 | 51 (\*) | | 34 (\*) | | | | 51 | 50 (\*) | | 33 (\*) | | | | 50 | 49 (\*) | | 32 (\*) | | | | 49 | 48 (\*) | | 31 (\*) | | | | 48 | 47 (\*) | | 30 (\*) | | | | 47 | 46 (\*) | | 29 (\*) | | | | 46 | 45 (\*) | | 28 (\*) | | | | 45 | 44 (\*) | | 27 (\*) | | | | 44 | 43 (\*) | | 26 (\*) | | | | 43 | 42 (\*) | | 25 (\*) | | | | 42 | 41 (\*) | | 24 (\*) | | | | 41 | 40 (\*) | | 23 (\*) | | | | 40 | 39 (\*) | | 22 (\*) | | | | 39 | 38 (\*) | | 21 (\*) | | | | 38 | 37 (\*) | | 20 (\*) | | | | 37 | 36 (\*) | | 19 (\*) | | | | 36 | 35 (\*) | | 18 (\*) | | | | 35 | 34 (\*) | | 17 (\*) | | | | 34 | 33 (\*) | | 16 (\*) | | | | 33 | 32 (\*) | | 15 (\*) | | | | 32 | 31 (\*) | | 12.1 | | | | 31 | 30 (\*) | | 12 | | | | 30 | 29 (\*) | | 11.6 | | | | 29 | 28 (\*) | | 11.5 | | | | 28 | 27 (\*) | | 11.1 | | | | 27 | 26 (\*) | | 11 | | | | 26 | 25 (\*) | | 10.6 | | | | 25 | 24 (\*) | | 10.5 | | | | 24 | 23 (\*) | | 10.0-10.1 | | | | 23 | 22 (\*) | | 9.5-9.6 | | | | 22 | 21 (\*) | | 9 | | | | 21 | 20 (\*) | | | | | | 20 | 19 (\*) | | | | | | 19 | 18 (\*) | | | | | | 18 | 17 (\*) | | | | | | 17 | 16 (\*) | | | | | | 16 | 15 (\*) | | | | | | 15 | 14 (\*) | | | | | | 14 | 13 (\*) | | | | | | 13 | 12 (\*) | | | | | | 12 | 11 (\*) | | | | | | 11 | 10 (\*) | | | | | | 10 | 9 (\*) | | | | | | 9 | 8 (\*) | | | | | | 8 | 7 (\*) | | | | | | 7 | 6 (\*) | | | | | | 6 | 5 (\*) | | | | | | 5 | 4 (\*) | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 (\*) | 10 (\*) | 72 (\*) | 108 (\*) | 107 | 11 | 13.4 (\*) | 19.0 (\*) | 13.1 (\*) | 13.18 (\*) | 2.5 | | 16.1 | | 4.4.3-4.4.4 (\*) | 7 (\*) | 12.1 | | | 10 | | 18.0 (\*) | | | | | 16.0 | | 4.4 (\*) | | 12 | | | | | 17.0 (\*) | | | | | 15.6 | | 4.2-4.3 (\*) | | 11.5 | | | | | 16.0 (\*) | | | | | [Show all](#) | | 15.5 | | 4.1 (\*) | | 11.1 | | | | | 15.0 (\*) | | | | | 15.4 | | 4 (\*) | | 11 | | | | | 14.0 (\*) | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 (\*) | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 (\*) | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 (\*) | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 (\*) | | | | | 13.4-13.7 (\*) | | | | | | | | | 9.2 (\*) | | | | | 13.3 (\*) | | | | | | | | | 8.2 (\*) | | | | | 13.2 (\*) | | | | | | | | | 7.2-7.4 (\*) | | | | | 13.0-13.1 (\*) | | | | | | | | | 6.2-6.4 (\*) | | | | | 12.2-12.5 (\*) | | | | | | | | | 5.0-5.4 (\*) | | | | | 12.0-12.1 (\*) | | | | | | | | | 4 (\*) | | | | | 11.3-11.4 (\*) | | | | | | | | | | | | | | 11.0-11.2 (\*) | | | | | | | | | | | | | | 10.3 (\*) | | | | | | | | | | | | | | 10.0-10.2 (\*) | | | | | | | | | | | | | | 9.3 (\*) | | | | | | | | | | | | | | 9.0-9.2 (\*) | | | | | | | | | | | | | | 8.1-8.4 (\*) | | | | | | | | | | | | | | 8 (\*) | | | | | | | | | | | | | | 7.0-7.1 (\*) | | | | | | | | | | | | | | 6.0-6.1 (\*) | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Firefox and legacy Edge also support this property with the `-webkit-` prefix. \* Partial support with prefix. Resources --------- * [[css-backgrounds] Standardize 'background-clip: text'](https://lists.w3.org/Archives/Public/www-style/2016Mar/0283.html) * [CSS Backgrounds and Borders Module Level 4](https://drafts.csswg.org/css-backgrounds-4/#background-clip) * [MDN Web Docs - background-clip](https://developer.mozilla.org/en-US/docs/Web/CSS/background-clip) browser_support_tables Multiple file selection Multiple file selection ======================= Allows users to select multiple files in the file picker. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/forms.html#attr-input-multiple> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all (1) | 108 (1) | 10 | 72 (1) | 108 (1) | 107 | 11 | 13.4 (1) | 19.0 (1) | 13.1 (1) | 13.18 (1) | 2.5 | | 16.1 | | 4.4.3-4.4.4 (1) | 7 | 12.1 (1) | | | 10 | | 18.0 (1) | | | | | 16.0 | | 4.4 (1) | | 12 (1) | | | | | 17.0 (1) | | | | | 15.6 | | 4.2-4.3 (1) | | 11.5 (1) | | | | | 16.0 (1) | | | | | [Show all](#) | | 15.5 | | 4.1 (1) | | 11.1 (1) | | | | | 15.0 (1) | | | | | 15.4 | | 4 (1) | | 11 (1) | | | | | 14.0 (1) | | | | | 15.2-15.3 | | 3 (1) | | 10 (1) | | | | | 13.0 (1) | | | | | 15.0-15.1 | | 2.3 (1) | | | | | | | 12.0 (1) | | | | | 14.5-14.8 | | 2.2 (1) | | | | | | | 11.1-11.2 (1) | | | | | 14.0-14.4 | | 2.1 (1) | | | | | | | 10.1 (1) | | | | | 13.4-13.7 | | | | | | | | | 9.2 (1) | | | | | 13.3 | | | | | | | | | 8.2 (1) | | | | | 13.2 | | | | | | | | | 7.2-7.4 (1) | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 (1) | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 (1) | | | | | 12.0-12.1 | | | | | | | | | 4 (1) | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Not supported on Android 4.x and below, presumably an OS limitation. Only seems to work in Android 5.x for the Chrome browser. Resources --------- * [Chrome bug (for Android)](https://code.google.com/p/chromium/issues/detail?id=348912) * [Article](https://www.raymondcamden.com/2012/02/28/Working-with-HTML5s-multiple-file-upload-support) browser_support_tables MathML MathML ====== Special tags that allow mathematical formulas and notations to be written on web pages. | | | | --- | --- | | Spec | <https://www.w3.org/TR/MathML/> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (3) | | | | | | 110 | 110 (3) | TP | | | | | 109 | 109 (3) | 16.3 | | | 11 | 108 (3) | 108 | 108 (3) | 16.2 | 92 (3) | | 10 | 107 (3) | 107 | 107 (3) | 16.1 | 91 (3) | | 9 | 106 (3) | 106 | 106 (3) | 16.0 | 90 (3) | | 8 | 105 (3) | 105 | 105 (3) | 15.6 | 89 (3) | | [Show all](#) | | 7 | 104 (3) | 104 | 104 (3) | 15.5 | 88 (3) | | 6 | 103 (3) | 103 | 103 (3) | 15.4 | 87 (3) | | 5.5 | 102 (3) | 102 | 102 (3) | 15.2-15.3 | 86 (3) | | | 101 (3) | 101 | 101 (3) | 15.1 | 85 (3) | | | 100 (3) | 100 | 100 (3) | 15 | 84 (3) | | | 99 (3) | 99 | 99 (3) | 14.1 | 83 (3) | | | 98 (3) | 98 | 98 (3) | 14 | 82 | | | 97 (3) | 97 | 97 (3) | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 (2) | 73 | | | 88 | 88 | 88 | 9 (2) | 72 | | | 87 | 87 | 87 | 8 (2) | 71 | | | 86 | 86 | 86 | 7.1 (2) | 70 | | | 85 | 85 | 85 | 7 (2) | 69 | | | 84 | 84 | 84 | 6.1 (2) | 68 | | | 83 | 83 | 83 | 6 (2) | 67 | | | 81 | 82 | 81 | 5.1 (2) | 66 | | | 80 | 81 | 80 | 5 (2) | 65 | | | 79 | 80 | 79 | 4 (2) | 64 | | | 18 | 79 | 78 | 3.2 (2) | 63 | | | 17 | 78 | 77 | 3.1 (2) | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 (5) | | | | 31 | 30 | | 12 (5) | | | | 30 | 29 | | 11.6 (5) | | | | 29 | 28 | | 11.5 (5) | | | | 28 | 27 | | 11.1 (5) | | | | 27 | 26 | | 11 (5) | | | | 26 | 25 | | 10.6 (5) | | | | 25 | 24 | | 10.5 (5) | | | | 24 | 23 | | 10.0-10.1 (5) | | | | 23 | 22 | | 9.5-9.6 (5) | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 (1) | | | | | | | 3.5 (1) | | | | | | | 3 (1) | | | | | | | 2 (1) | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Support was added in Chrome 24, but temporarily removed afterwards due to instability. 1. Before version 4, Firefox only supports the XHTML notation 2. Before version 10, Safari had issues rendering significant portions of the MathML torture test 3. Can be enabled via the `#enable-experimental-web-platform-features` flag in `chrome://flags` 4. Browsers based on Chromium 108+ specifically support [MathML Core](https://www.w3.org/TR/mathml-core/). While there is significant support overlap with other MathML implementations there are some differences ([see details](https://groups.google.com/a/chromium.org/g/blink-dev/c/n4zf_3FWmAA/m/oait3tsMAQAJ)). 5. Opera's support is limited to a CSS profile of MathML Resources --------- * [Wikipedia](https://en.wikipedia.org/wiki/MathML) * [Cross-browser support script](https://www.mathjax.org) * [MDN Web Docs - MathML](https://developer.mozilla.org/en-US/docs/Web/MathML) * [MathML torture test](https://fred-wang.github.io/MathFonts/mozilla_mathml_test/) * [MathML in Chromium Project Roadmap](https://mathml.igalia.com/project/)
programming_docs
browser_support_tables HTML Media Capture HTML Media Capture ================== Facilitates user access to a device's media capture mechanism, such as a camera, or microphone, from within a file upload control. | | | | --- | --- | | Spec | <https://w3c.github.io/html-media-capture/> | | Status | W3C Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 (1) | | | | | | | | | | | | | | 16.2 (1) | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 (3) | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 (1) | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 (1) | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 (1) | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 (1) | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 (1) | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 (1) | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 (1) | | 2.3 (2) | | | | | | | 12.0 | | | | | 14.5-14.8 (1) | | 2.2 (2) | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 (1) | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (1) | | | | | | | | | 9.2 | | | | | 13.3 (1) | | | | | | | | | 8.2 | | | | | 13.2 (1) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (1) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (1) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 (1) | | | | | | | | | 4 | | | | | 11.3-11.4 (1) | | | | | | | | | | | | | | 11.0-11.2 (1) | | | | | | | | | | | | | | 10.3 (1) | | | | | | | | | | | | | | 10.0-10.2 (1) | | | | | | | | | | | | | | 9.3 (1) | | | | | | | | | | | | | | 9.0-9.2 (1) | | | | | | | | | | | | | | 8.1-8.4 (1) | | | | | | | | | | | | | | 8 (1) | | | | | | | | | | | | | | 7.0-7.1 (1) | | | | | | | | | | | | | | 6.0-6.1 (1) | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Does not support the capture attribute used to force capture straight from the device's camera or microphone. Also note that default video dimensions are 480x320 (4:3). 2. Android 2.2-2.3 do not support the capture attribute 3. Supports a "capture" button for any `<input type="file"> field, regardless of the whether the capture attribute is used. Resources --------- * [Correct Syntax for HTML Media Capture](https://addpipe.com/blog/correct-syntax-html-media-capture/) * [Programming the Mobile Web: File upload compatibility table](https://books.google.com.au/books?id=gswdarRZVUoC&pg=PA263&dq=%22file+upload+compatibility+table%22) * [HTML Media Capture Test Bench](https://addpipe.com/html-media-capture-demo/) browser_support_tables calc() as CSS unit value calc() as CSS unit value ======================== Method of allowing calculated values for length units, i.e. `width: calc(100% - 3em)` | | | | --- | --- | | Spec | <https://w3c.github.io/csswg-drafts/css-values-3/#calc-notation> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 (3) | 108 | 108 | 108 | 16.2 | 92 | | 10 (3) | 107 | 107 | 107 | 16.1 | 91 | | 9 (2) | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 (\*) | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 (\*) | | 10.6 | | | | 25 | 24 (\*) | | 10.5 | | | | 24 | 23 (\*) | | 10.0-10.1 | | | | 23 | 22 (\*) | | 9.5-9.6 | | | | 22 | 21 (\*) | | 9 | | | | 21 | 20 (\*) | | | | | | 20 | 19 (\*) | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 (\*) | 14 | | | | | | 14 (\*) | 13 | | | | | | 13 (\*) | 12 | | | | | | 12 (\*) | 11 | | | | | | 11 (\*) | 10 | | | | | | 10 (\*) | 9 | | | | | | 9 (\*) | 8 | | | | | | 8 (\*) | 7 | | | | | | 7 (\*) | 6 | | | | | | 6 (\*) | 5 | | | | | | 5 (\*) | 4 | | | | | | 4 (\*) | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 (1) | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 (1) | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 (\*) | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Support can be somewhat emulated in older versions of IE using the non-standard `expression()` syntax. Due to the way browsers handle [sub-pixel rounding](https://johnresig.com/blog/sub-pixel-problems-in-css/) differently, layouts using `calc()` expressions may have unexpected results. 1. Partial support in Android Browser 4.4 refers to the browser lacking the ability to multiply and divide values. 2. Partial support in IE9 refers to the browser crashing when used as a `background-position` value. 3. Partial support in IE10/IE11 refers to calc not working properly with various use cases mentioned in known issues \* Partial support with prefix. Bugs ---- * IE 9 - 11 and Edge do not support `width: calc()` on table cells. [Bug Report](https://web.archive.org/web/20171123043312/https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10982196/) * IE 9 - 11 don't render `box-shadow` when `calc()` is used for any of the values * IE10 crashes when a div with a property using `calc()` has a child with [same property with inherit](https://stackoverflow.com/questions/19423384/css-less-calc-method-is-crashing-my-ie10). * IE10, IE11, and Edge < 14 don't support using `calc()` inside a `transform`. [Bug report](https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/104773/) * IE11 is reported to have trouble with `calc()` with nested expressions, e.g. `width: calc((100% - 10px) / 3);` (i.e. it rounds differently) * IE11 is reported to not support `calc()` correctly in [generated content](https://stackoverflow.com/questions/31323915/internet-explorer-incorrectly-calculates-percentage-height-for-generated-content) * IE11 does not support transitioning values set with `calc()` * Safari & iOS Safari (both 6 and 7) does not support viewport units (`vw`, `vh`, etc) in `calc()`. * IE & Edge are reported to not support calc inside a 'flex'. (Not tested on older versions) This example does not work: `flex: 1 1 calc(50% - 20px);` * IE does not support `calc()` on color functions. Example: `color: hsl(calc(60 * 2), 100%, 50%)`. * Firefox <48 does not support `calc()` inside the `line-height`, `stroke-width`, `stroke-dashoffset`, and `stroke-dasharray` properties. [Bug report](https://bugzilla.mozilla.org/show_bug.cgi?id=594933) * Firefox <59 does not support `calc()` on color functions. Example: `color: hsl(calc(60 * 2), 100%, 50%)`. [Bug Report](https://bugzilla.mozilla.org/show_bug.cgi?id=984021) * Firefox <66 does not support `width: calc()` on table cells. [Bug Report](https://bugzilla.mozilla.org/show_bug.cgi?id=957915) Resources --------- * [Mozilla Hacks article](https://hacks.mozilla.org/2010/06/css3-calc/) * [MDN Web Docs - calc](https://developer.mozilla.org/en/docs/Web/CSS/calc) * [WebPlatform Docs](https://webplatform.github.io/docs/css/functions/calc) browser_support_tables Resource Hints: Lazyload Resource Hints: Lazyload ======================== Gives a hint to the browser to lower the loading priority of a resource. Please note that this is a legacy attribute, see the [`loading`](/loading-lazy-attr) attribute for the new standardized API. | | | | --- | --- | | Spec | <https://w3c.github.io/web-performance/specs/ResourcePriorities/Overview.html> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [lazyload attribute | lazyload property](https://msdn.microsoft.com/en-us/ie/dn369270(v=vs.94)) * [Discussion on standardization](https://github.com/whatwg/html/issues/2806)
programming_docs
browser_support_tables LCH and Lab color values LCH and Lab color values ======================== The `lch()` and `lab()` color functions are based on the CIE LAB color space, representing colors in a way that closely matches human perception and provides access to a wider spectrum of colors than offered by the usual RGB color space. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css-color-4/#specifying-lab-lch> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Chrome support bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1026287) * [Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1352757) * [LCH colors in CSS: what, why, and how?](https://lea.verou.me/2020/04/lch-colors-in-css-what-why-and-how/) * [LCH color picker](https://css.land/lch/) * [MDN article on lch()](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/lch()) * [MDN article on lab()](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/lab()) browser_support_tables ES6 classes ES6 classes =========== ES6 classes are syntactical sugar to provide a much simpler and clearer syntax to create objects and deal with inheritance. | | | | --- | --- | | Spec | <https://tc39.es/ecma262/#sec-class-definitions> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 (1) | | | | 52 | 51 | | 34 (1) | | | | 51 | 50 | | 33 (1) | | | | 50 | 49 | | 32 (1) | | | | 49 | 48 (1) | | 31 (1) | | | | 48 | 47 (1) | | 30 (1) | | | | 47 | 46 (1) | | 29 (1) | | | | 46 | 45 (1) | | 28 | | | | 45 | 44 (1) | | 27 | | | | 44 | 43 (1) | | 26 | | | | 43 | 42 (1) | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Requires strict mode. Non-strict mode support is behind the flag 'Enable Experimental JavaScript', disabled by default. Resources --------- * [MDN Web Docs - ES6 classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) * [Sitepoint deep dive on ES6 classes](https://www.sitepoint.com/object-oriented-javascript-deep-dive-es6-classes/) * [List of resources critical of ES6 classes](https://github.com/joshburgess/not-awesome-es6-classes) browser_support_tables naturalWidth & naturalHeight image properties naturalWidth & naturalHeight image properties ============================================= Properties defining the intrinsic width and height of the image, rather than the displayed width & height. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-naturalwidth> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Bugs ---- * Firefox returns `0` for svg images without explicit dimensions. [See bug](https://bugzilla.mozilla.org/show_bug.cgi?id=700533) Resources --------- * [Blog post on support in IE](https://www.jacklmoore.com/notes/naturalwidth-and-naturalheight-in-ie/) * [gist on getting natural width & height in older IE](https://gist.github.com/jalbertbowden/5273983) browser_support_tables Details & Summary elements Details & Summary elements ========================== The <details> element generates a simple no-JavaScript widget to show/hide element contents, optionally by clicking on its child <summary> element. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/forms.html#the-details-element> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 (4) | 77 | | | 92 | 92 | 92 | 11 (4) | 76 | | | 91 | 91 | 91 | 10.1 (4) | 75 | | | 90 | 90 | 90 | 10 (2) | 74 | | | 89 | 89 | 89 | 9.1 (2) | 73 | | | 88 | 88 | 88 | 9 (2) | 72 | | | 87 | 87 | 87 | 8 (2) | 71 | | | 86 | 86 | 86 | 7.1 (2) | 70 | | | 85 | 85 | 85 | 7 (2) | 69 | | | 84 | 84 | 84 | 6.1 (2) | 68 | | | 83 | 83 | 83 | 6 (2) | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 (1) | 47 | | 30 | | | | 47 (1) | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 (2) | | 18 | | | | 35 | 34 (2) | | 17 | | | | 34 | 33 (2) | | 16 | | | | 33 | 32 (2) | | 15 | | | | 32 | 31 (2) | | 12.1 | | | | 31 | 30 (2) | | 12 | | | | 30 | 29 (2) | | 11.6 | | | | 29 | 28 (2) | | 11.5 | | | | 28 | 27 (2) | | 11.1 | | | | 27 | 26 (2) | | 11 | | | | 26 | 25 (2) | | 10.6 | | | | 25 | 24 (2) | | 10.5 | | | | 24 | 23 (2) | | 10.0-10.1 | | | | 23 | 22 (2) | | 9.5-9.6 | | | | 22 | 21 (2) | | 9 | | | | 21 | 20 (2) | | | | | | 20 | 19 (2) | | | | | | 19 | 18 (2,3) | | | | | | 18 | 17 (2,3) | | | | | | 17 | 16 (2,3) | | | | | | 16 | 15 (2,3) | | | | | | 15 | 14 (2,3) | | | | | | 14 | 13 (2,3) | | | | | | 13 | 12 (2,3) | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 (4) | | | | | | | | | | | | | | 10.3 (4) | | | | | | | | | | | | | | 10.0-10.2 (4) | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Enabled in Firefox through the `dom.details_element.enabled` flag 2. 'toggle' event is not supported 3. <summary> is not keyboard accessible 4. Some versions of Safari display smaller font-size than intended when using `rem` units with system fonts. (See: https://colloq.io/blog/safaris-detailssummary-rem-font-size-issue) Bugs ---- * `<select>` within `<details>` elements won't have their value changed on the Android browser shipped with most of Samsung's devices (i.e. Note 3, Galaxy 5) The picker will appear, but attempting to select any option won't update the `<select>` or trigger any event. * In Chrome, when using the common inherit box-sizing fix (https://www.paulirish.com/2012/box-sizing-border-box-ftw/) in combination with a `<details>` element, the children of the `<details>` element get rendered as if they were `box-sizing: content-box;`. See: https://codepen.io/jochemnabuurs/pen/yYzYqM Resources --------- * [jQuery fallback script](https://mathiasbynens.be/notes/html5-details-jquery) * [Fallback script](https://gist.github.com/370590) * [HTML5 Doctor article](https://html5doctor.com/summary-figcaption-element/) * [has.js test](https://raw.github.com/phiggins42/has.js/master/detect/features.js#native-details) * [WebPlatform Docs](https://webplatform.github.io/docs/html/elements/details) * [Bug on Firefox support](https://bugzilla.mozilla.org/show_bug.cgi?id=591737) * [Details Element Polyfill](https://github.com/javan/details-element-polyfill)
programming_docs
browser_support_tables TLS 1.1 TLS 1.1 ======= Version 1.1 of the Transport Layer Security (TLS) protocol. | | | | --- | --- | | Spec | <https://tools.ietf.org/html/rfc4346> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (3,4) | | | | | | 110 (1,2) | 110 (3,4) | TP (3) | | | | | 109 (1,2) | 109 (3,4) | 16.3 (3) | | | 11 | 108 | 108 (1,2) | 108 (3,4) | 16.2 (3) | 92 (3,4) | | 10 | 107 | 107 (1,2) | 107 (3,4) | 16.1 (3) | 91 (3,4) | | 9 | 106 | 106 (1,2) | 106 (3,4) | 16.0 (3) | 90 (3,4) | | 8 | 105 | 105 (1,2) | 105 (3,4) | 15.6 (3) | 89 (3,4) | | [Show all](#) | | 7 | 104 | 104 (1,2) | 104 (3,4) | 15.5 (3) | 88 (3,4) | | 6 | 103 | 103 (1,2) | 103 (3,4) | 15.4 (3) | 87 (3,4) | | 5.5 | 102 | 102 (1,2) | 102 (3,4) | 15.2-15.3 (3) | 86 (3,4) | | | 101 | 101 (1,2) | 101 (3,4) | 15.1 (3) | 85 (3,4) | | | 100 | 100 (1,2) | 100 (3,4) | 15 (3) | 84 (3,4) | | | 99 | 99 (1,2) | 99 (3,4) | 14.1 (3) | 83 (3,4) | | | 98 | 98 (1,2) | 98 (3,4) | 14 (3) | 82 (3,4) | | | 97 | 97 (1,2) | 97 (3,4) | 13.1 (3) | 81 (3,4) | | | 96 | 96 (1,2) | 96 (3,4) | 13 | 80 (3,4) | | | 95 | 95 (1,2) | 95 (3,4) | 12.1 | 79 (3,4) | | | 94 | 94 (1,2) | 94 (3,4) | 12 | 78 (3,4) | | | 93 | 93 (1,2) | 93 (3,4) | 11.1 | 77 (3,4) | | | 92 | 92 (1,2) | 92 (3,4) | 11 | 76 (3,4) | | | 91 | 91 (1,2) | 91 (3,4) | 10.1 | 75 (3,4) | | | 90 | 90 (1,2) | 90 (3,4) | 10 | 74 (3,4) | | | 89 | 89 (1,2) | 89 (3,4) | 9.1 | 73 (3,4) | | | 88 | 88 (1,2) | 88 (3,4) | 9 | 72 | | | 87 | 87 (1,2) | 87 (3,4) | 8 | 71 | | | 86 | 86 (1,2) | 86 (3,4) | 7.1 | 70 | | | 85 | 85 (1,2) | 85 (3,4) | 7 | 69 | | | 84 | 84 (1,2) | 84 | 6.1 | 68 | | | 83 | 83 (1,2) | 83 | 6 | 67 | | | 81 | 82 (1,2) | 81 | 5.1 | 66 | | | 80 | 81 (1,2) | 80 | 5 | 65 | | | 79 | 80 (1,2) | 79 | 4 | 64 | | | 18 | 79 (1,2) | 78 | 3.2 | 63 | | | 17 | 78 (1,2) | 77 | 3.1 | 62 | | | 16 | 77 (1) | 76 | | 60 | | | 15 | 76 (1) | 75 | | 58 | | | 14 | 75 (1) | 74 | | 57 | | | 13 | 74 (1) | 73 | | 56 | | | 12 | 73 (1) | 72 | | 55 | | | | 72 (1) | 71 | | 54 | | | | 71 (1) | 70 | | 53 | | | | 70 (1) | 69 | | 52 | | | | 69 (1) | 68 | | 51 | | | | 68 (1) | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 (1) | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- TLS 1.0 & 1.1 are deprecated in Chrome, Edge, Firefox, Internet Explorer 11, & Safari. 1. Firefox 68+ displays a small warning icon in the address bar when connecting over TLS 1.1 2. Firefox 78+ displays a full page dismissable warning the first time it connects over TLS 1.1 3. Chrome 85+ and Safari for MacOS 13.1+ displays `Not secure` in the address bar when connecting over TLS 1.1 4. Chrome 85+ displays a full page dismissable warning every time a new site connects over TLS 1.1 Resources --------- * [Wikipedia article about TLS 1.1](https://en.wikipedia.org/wiki/Transport_Layer_Security#TLS_1.1) * [Modernizing Transport Security - Google Security Blog](https://security.googleblog.com/2018/10/modernizing-transport-security.html) * [Modernizing TLS connections in Microsoft Edge and Internet Explorer 11 - Microsoft Windows Blog](https://blogs.windows.com/msedgedev/2018/10/15/modernizing-tls-edge-ie11/) * [Removing Old Versions of TLS - Mozilla Security Blog](https://blog.mozilla.org/security/2018/10/15/removing-old-versions-of-tls/) * [Deprecation of Legacy TLS 1.0 and 1.1 Versions - WebKit Blog](https://webkit.org/blog/8462/deprecation-of-legacy-tls-1-0-and-1-1-versions/) browser_support_tables readonly attribute of input and textarea elements readonly attribute of input and textarea elements ================================================= Makes the form control non-editable. Unlike the `disabled` attribute, `readonly` form controls are still included in form submissions and the user can still select (but not edit) their value text. | | | | --- | --- | | Spec | <https://html.spec.whatwg.org/multipage/input.html#the-readonly-attribute> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 (1) | | | | 31 | 30 | | 12 (1) | | | | 30 | 29 | | 11.6 (1) | | | | 29 | 28 | | 11.5 (1) | | | | 28 | 27 | | 11.1 (1) | | | | 27 | 26 | | 11 (1) | | | | 26 | 25 | | 10.6 (1) | | | | 25 | 24 | | 10.5 (1) | | | | 24 | 23 | | 10.0-10.1 (1) | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 (2) | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 (1) | | | 10 (2) | | 18.0 | | | | | 16.0 | | 4.4 | | 12 (1) | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 (1) | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 (1) | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 (1) | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 (1) | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Readonly inputs of type `datetime-local`, `date`, `month`, and `week` can still be edited by pressing the Up or Down arrow keys on the keyboard while the input is focused. 2. Text cannot be selected directly, but is possible by first selecting any text around the field. Resources --------- * [WHATWG HTML specification for the readonly attribute of the `` element](https://html.spec.whatwg.org/multipage/forms.html#attr-textarea-readonly) * [MDN Web Docs - readonly attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#attr-readonly) browser_support_tables URL API URL API ======= API to retrieve the various parts that make up a given URL from a given URL string. | | | | --- | --- | | Spec | <https://url.spec.whatwg.org/#api> | | Status | WHATWG Living Standard | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 (1) | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 (1) | | | | 35 | 34 | | 17 (1) | | | | 34 | 33 | | 16 (1) | | | | 33 | 32 | | 15 (1) | | | | 32 | 31 (1) | | 12.1 | | | | 31 | 30 (1) | | 12 | | | | 30 | 29 (1) | | 11.6 | | | | 29 | 28 (1) | | 11.5 | | | | 28 | 27 (1) | | 11.1 | | | | 27 | 26 (1) | | 11 | | | | 26 | 25 (1) | | 10.6 | | | | 25 | 24 (1) | | 10.5 | | | | 24 | 23 (1) | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 (1) | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 (1) | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 (1) | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- See also [URLSearchParams](#feat=urlsearchparams). 1. Allows objects to be created via `URL` constructor, but instances do not have the expected url properties. Bugs ---- * Safari 14 and below [throw an error](https://bugs.webkit.org/show_bug.cgi?id=216841) when the base parameter is `undefined` Resources --------- * [MDN Web Docs - URL interface](https://developer.mozilla.org/en-US/docs/Web/API/URL) * [MDN Web Docs - URL constructor](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) * [Polyfill for this feature is available in the core-js library](https://github.com/zloirock/core-js#url-and-urlsearchparams)
programming_docs
browser_support_tables Media Queries: Range Syntax Media Queries: Range Syntax =========================== Syntax improvements to make media queries using features that have a "range" type (like width or height) less verbose. Can be used with ordinary mathematical comparison operators: `>`, `<`, `>=`, or `<=`. For example: `@media (100px <= width <= 1900px)` is the equivalent of `@media (min-width: 100px) and (max-width: 1900px`)` | | | | --- | --- | | Spec | <https://www.w3.org/TR/mediaqueries-4/#mq-range-context> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [Syntax improvements in Level 4](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries) * [Firefox support bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1422225#c55) * [PostCSS Polyfill](https://github.com/postcss/postcss-media-minmax) * [WebKit bug](https://bugs.webkit.org/show_bug.cgi?id=180234) * [Media Queries Level 4: Media Query Range Contexts (Media Query Ranges)](https://www.bram.us/2021/10/26/media-queries-level-4-media-query-range-contexts/) * [New syntax for range media queries in Chrome 104](https://developer.chrome.com/blog/media-query-range-syntax/) browser_support_tables Context menu item (menuitem element) Context menu item (menuitem element) ==================================== Method of defining a context menu item, now deprecated and [removed from the HTML specification](https://github.com/whatwg/html/issues/2730). | | | | --- | --- | | Spec | <https://www.w3.org/TR/2016/REC-html51-20161101/interactive-elements.html#context-menus> | | Status | Unofficial / Note | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 (1,2) | 110 | TP | | | | | 109 (1,2) | 109 | 16.3 | | | 11 | 108 | 108 (1,2) | 108 | 16.2 | 92 | | 10 | 107 | 107 (1,2) | 107 | 16.1 | 91 | | 9 | 106 | 106 (1,2) | 106 | 16.0 | 90 | | 8 | 105 | 105 (1,2) | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 (1,2) | 104 | 15.5 | 88 | | 6 | 103 | 103 (1,2) | 103 | 15.4 | 87 | | 5.5 | 102 | 102 (1,2) | 102 | 15.2-15.3 | 86 | | | 101 | 101 (1,2) | 101 | 15.1 | 85 | | | 100 | 100 (1,2) | 100 | 15 | 84 | | | 99 | 99 (1,2) | 99 | 14.1 | 83 | | | 98 | 98 (1,2) | 98 | 14 | 82 | | | 97 | 97 (1,2) | 97 | 13.1 | 81 | | | 96 | 96 (1,2) | 96 | 13 | 80 | | | 95 | 95 (1,2) | 95 | 12.1 | 79 | | | 94 | 94 (1,2) | 94 | 12 | 78 | | | 93 | 93 (1,2) | 93 | 11.1 | 77 | | | 92 | 92 (1,2) | 92 | 11 | 76 | | | 91 | 91 (1,2) | 91 | 10.1 | 75 | | | 90 | 90 (1,2) | 90 | 10 | 74 | | | 89 | 89 (1,2) | 89 | 9.1 | 73 | | | 88 | 88 (1,2) | 88 | 9 | 72 | | | 87 | 87 (1,2) | 87 | 8 | 71 | | | 86 | 86 (1,2) | 86 | 7.1 | 70 | | | 85 | 85 (1,2) | 85 | 7 | 69 | | | 84 | 84 (1) | 84 | 6.1 | 68 | | | 83 | 83 (1) | 83 | 6 | 67 | | | 81 | 82 (1) | 81 | 5.1 | 66 | | | 80 | 81 (1) | 80 | 5 | 65 | | | 79 | 80 (1) | 79 | 4 | 64 | | | 18 | 79 (1) | 78 | 3.2 | 63 | | | 17 | 78 (1) | 77 | 3.1 | 62 | | | 16 | 77 (1) | 76 | | 60 | | | 15 | 76 (1) | 75 | | 58 | | | 14 | 75 (1) | 74 | | 57 | | | 13 | 74 (1) | 73 | | 56 | | | 12 | 73 (1) | 72 | | 55 | | | | 72 (1) | 71 | | 54 | | | | 71 (1) | 70 | | 53 | | | | 70 (1) | 69 | | 52 | | | | 69 (1) | 68 | | 51 | | | | 68 (1) | 67 | | 50 | | | | 67 (1) | 66 | | 49 | | | | 66 (1) | 65 | | 48 | | | | 65 (1) | 64 | | 47 | | | | 64 (1) | 63 | | 46 | | | | 63 (1) | 62 | | 45 | | | | 62 (1) | 61 | | 44 | | | | 61 (1) | 60 | | 43 | | | | 60 (1) | 59 | | 42 | | | | 59 (1) | 58 | | 41 | | | | 58 (1) | 57 | | 40 | | | | 57 (1) | 56 | | 39 | | | | 56 (1) | 55 | | 38 | | | | 55 (1) | 54 | | 37 | | | | 54 (1) | 53 | | 36 | | | | 53 (1) | 52 | | 35 | | | | 52 (1) | 51 | | 34 | | | | 51 (1) | 50 | | 33 | | | | 50 (1) | 49 | | 32 | | | | 49 (1) | 48 | | 31 | | | | 48 (1) | 47 | | 30 | | | | 47 (1) | 46 | | 29 | | | | 46 (1) | 45 | | 28 | | | | 45 (1) | 44 | | 27 | | | | 44 (1) | 43 | | 26 | | | | 43 (1) | 42 | | 25 | | | | 42 (1) | 41 | | 24 | | | | 41 (1) | 40 | | 23 | | | | 40 (1) | 39 | | 22 | | | | 39 (1) | 38 | | 21 | | | | 38 (1) | 37 | | 20 | | | | 37 (1) | 36 | | 19 | | | | 36 (1) | 35 | | 18 | | | | 35 (1) | 34 | | 17 | | | | 34 (1) | 33 | | 16 | | | | 33 (1) | 32 | | 15 | | | | 32 (1) | 31 | | 12.1 | | | | 31 (1) | 30 | | 12 | | | | 30 (1) | 29 | | 11.6 | | | | 29 (1) | 28 | | 11.5 | | | | 28 (1) | 27 | | 11.1 | | | | 27 (1) | 26 | | 11 | | | | 26 (1) | 25 | | 10.6 | | | | 25 (1) | 24 | | 10.5 | | | | 24 (1) | 23 | | 10.0-10.1 | | | | 23 (1) | 22 | | 9.5-9.6 | | | | 22 (1) | 21 | | 9 | | | | 21 (1) | 20 | | | | | | 20 (1) | 19 | | | | | | 19 (1) | 18 | | | | | | 18 (1) | 17 | | | | | | 17 (1) | 16 | | | | | | 16 (1) | 15 | | | | | | 15 (1) | 14 | | | | | | 14 (1) | 13 | | | | | | 13 (1) | 12 | | | | | | 12 (1) | 11 | | | | | | 11 (1) | 10 | | | | | | 10 (1) | 9 | | | | | | 9 (1) | 8 | | | | | | 8 (1) | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 (1,2) | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. Partial support in Firefox refers to being limited to context menus, not toolbar menus. 2. Can be enabled with the `dom.menuitem.enabled` preference in `about:config`. Resources --------- * [Demo](https://bug617528.bugzilla.mozilla.org/attachment.cgi?id=554309) * [jQuery polyfill](https://github.com/swisnl/jQuery-contextMenu) * [has.js test](https://raw.github.com/phiggins42/has.js/master/detect/events.js#event-contextmenu) * [Bug on Firefox support](https://bugzilla.mozilla.org/show_bug.cgi?id=746087) * [Chromium support bug](https://bugs.chromium.org/p/chromium/issues/detail?id=87553) browser_support_tables rem (root em) units rem (root em) units =================== Type of unit similar to `em`, but relative only to the root element, not any parent element. Thus compounding does not occur as it does with `em` units. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css3-values/#font-relative-lengths> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 (1) | 107 | 107 | 107 | 16.1 | 91 | | 9 (1) | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 (2) | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- 1. IE 9 & IE 10 do not support `rem` units when used in the `font` shorthand property (the entire declaration is ignored) or when used on pseudo elements. 2. iOS Safari 5.0-5.1 support `rem` but not in combination with media queries. Bugs ---- * IE 9, 10 and 11 do not support rem units when used in the "line-height" property when used on :before and :after pseudo elements (https://web.archive.org/web/20160801002559/https://connect.microsoft.com/IE/feedback/details/776744). * Borders sized in "rem" disappear when the page is zoomed out in Chrome. * Reportedly does not work on Android 4.3 browser for Samsung Note II or the Samsung Galaxy Tab 2 on Android 4.2. * Chrome 31-34 & Chrome-based Android versions (like 4.4) [have a font size bug](https://code.google.com/p/chromium/issues/detail?id=319623) that occurs when the root element has a percentage-based size. * Causes content display and scrolling issues on iPhone 4 which typically has Safari 5.1. Resources --------- * [Article on usage](https://snook.ca/archives/html_and_css/font-size-with-rem) * [REM Polyfill](https://github.com/chuckcarpenter/REM-unit-polyfill)
programming_docs
browser_support_tables Array.prototype.find Array.prototype.find ==================== The `find()` method returns the value of the first item in the array based on the result of the provided testing function. | | | | --- | --- | | Spec | <https://tc39.es/ecma262/#sec-array.prototype.find> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 | | | 91 | 91 | 91 | 10.1 | 75 | | | 90 | 90 | 90 | 10 | 74 | | | 89 | 89 | 89 | 9.1 | 73 | | | 88 | 88 | 88 | 9 | 72 | | | 87 | 87 | 87 | 8 | 71 | | | 86 | 86 | 86 | 7.1 | 70 | | | 85 | 85 | 85 | 7 | 69 | | | 84 | 84 | 84 | 6.1 | 68 | | | 83 | 83 | 83 | 6 | 67 | | | 81 | 82 | 81 | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 | | | | | | | | | 9.2 | | | | | 13.3 | | | | | | | | | 8.2 | | | | | 13.2 | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- Resources --------- * [MDN article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) * [Polyfill for this feature is available in the core-js library](https://github.com/zloirock/core-js#ecmascript-array) browser_support_tables CSS3 image-orientation CSS3 image-orientation ====================== CSS property used generally to fix the intended orientation of an image. This can be done using 90 degree increments or based on the image's EXIF data using the "from-image" value. | | | | --- | --- | | Spec | <https://www.w3.org/TR/css-images-3/#the-image-orientation> | | Status | W3C Candidate Recommendation | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 | | | | | | 110 | 110 | TP | | | | | 109 | 109 | 16.3 | | | 11 | 108 | 108 | 108 | 16.2 | 92 | | 10 | 107 | 107 | 107 | 16.1 | 91 | | 9 | 106 | 106 | 106 | 16.0 | 90 | | 8 | 105 | 105 | 105 | 15.6 | 89 | | [Show all](#) | | 7 | 104 | 104 | 104 | 15.5 | 88 | | 6 | 103 | 103 | 103 | 15.4 | 87 | | 5.5 | 102 | 102 | 102 | 15.2-15.3 | 86 | | | 101 | 101 | 101 | 15.1 | 85 | | | 100 | 100 | 100 | 15 | 84 | | | 99 | 99 | 99 | 14.1 | 83 | | | 98 | 98 | 98 | 14 | 82 | | | 97 | 97 | 97 | 13.1 | 81 | | | 96 | 96 | 96 | 13 | 80 | | | 95 | 95 | 95 | 12.1 | 79 | | | 94 | 94 | 94 | 12 | 78 | | | 93 | 93 | 93 | 11.1 | 77 | | | 92 | 92 | 92 | 11 | 76 (2) | | | 91 | 91 | 91 | 10.1 | 75 (2) | | | 90 | 90 | 90 | 10 | 74 (2) | | | 89 | 89 | 89 | 9.1 | 73 (2) | | | 88 (2) | 88 | 88 (2) | 9 | 72 (2) | | | 87 (2) | 87 | 87 (2) | 8 | 71 (2) | | | 86 (2) | 86 | 86 (2) | 7.1 | 70 (2) | | | 85 (2) | 85 | 85 (2) | 7 | 69 (2) | | | 84 (2) | 84 | 84 (2) | 6.1 | 68 (2) | | | 83 (2) | 83 | 83 (2) | 6 | 67 | | | 81 (2) | 82 | 81 (2) | 5.1 | 66 | | | 80 | 81 | 80 | 5 | 65 | | | 79 | 80 | 79 | 4 | 64 | | | 18 | 79 | 78 | 3.2 | 63 | | | 17 | 78 | 77 | 3.1 | 62 | | | 16 | 77 | 76 | | 60 | | | 15 | 76 | 75 | | 58 | | | 14 | 75 | 74 | | 57 | | | 13 | 74 | 73 | | 56 | | | 12 | 73 | 72 | | 55 | | | | 72 | 71 | | 54 | | | | 71 | 70 | | 53 | | | | 70 | 69 | | 52 | | | | 69 | 68 | | 51 | | | | 68 | 67 | | 50 | | | | 67 | 66 | | 49 | | | | 66 | 65 | | 48 | | | | 65 | 64 | | 47 | | | | 64 | 63 | | 46 | | | | 63 | 62 | | 45 | | | | 62 | 61 | | 44 | | | | 61 | 60 | | 43 | | | | 60 | 59 | | 42 | | | | 59 | 58 | | 41 | | | | 58 | 57 | | 40 | | | | 57 | 56 | | 39 | | | | 56 | 55 | | 38 | | | | 55 | 54 | | 37 | | | | 54 | 53 | | 36 | | | | 53 | 52 | | 35 | | | | 52 | 51 | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 | 10 | 72 | 108 | 107 | 11 | 13.4 | 19.0 | 13.1 | 13.18 | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 (2) | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 (2) | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 | | | | | 13.4-13.7 (1) | | | | | | | | | 9.2 | | | | | 13.3 (1) | | | | | | | | | 8.2 | | | | | 13.2 (1) | | | | | | | | | 7.2-7.4 | | | | | 13.0-13.1 (1) | | | | | | | | | 6.2-6.4 | | | | | 12.2-12.5 (1) | | | | | | | | | 5.0-5.4 | | | | | 12.0-12.1 (1) | | | | | | | | | 4 | | | | | 11.3-11.4 (1) | | | | | | | | | | | | | | 11.0-11.2 (1) | | | | | | | | | | | | | | 10.3 (1) | | | | | | | | | | | | | | 10.0-10.2 (1) | | | | | | | | | | | | | | 9.3 (1) | | | | | | | | | | | | | | 9.0-9.2 (1) | | | | | | | | | | | | | | 8.1-8.4 (1) | | | | | | | | | | | | | | 8 (1) | | | | | | | | | | | | | | 7.0-7.1 (1) | | | | | | | | | | | | | | 6.0-6.1 (1) | | | | | | | | | | | | | | 5.0-5.1 (1) | | | | | | | | | | | | | | 4.2-4.3 (1) | | | | | | | | | | | | | | 4.0-4.1 (1) | | | | | | | | | | | | | | 3.2 (1) | | | | | | | | | | | | | Notes ----- Opening the image in a new tab in Chrome results in the image shown in the orientation according to the EXIF data. 1. Partial support in iOS refers to the browser using EXIF data by default, though it does not actually support the property. 2. Has [a bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1082669) where the browser is not maintaining the image’s aspect ratio when `object-fit: cover` and `image-orientation: from-image` are used together. Bugs ---- * Negative values do not work in Firefox. Resources --------- * [MDN Web Docs - CSS image-orientation](https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation) * [Blog post](http://sethfowler.org/blog/2013/09/13/new-in-firefox-26-css-image-orientation/) * [Demo (Chinese)](https://jsbin.com/EXUTolo/4) * [Chromium bug #158753: Support for the CSS image-orientation CSS property](https://bugs.chromium.org/p/chromium/issues/detail?id=158753) browser_support_tables ECMAScript 2015 (ES6) ECMAScript 2015 (ES6) ===================== Support for the ECMAScript 2015 specification. Features include Promises, Modules, Classes, Template Literals, Arrow Functions, Let and Const, Default Parameters, Generators, Destructuring Assignment, Rest & Spread, Map/Set & WeakMap/WeakSet and many more. | | | | --- | --- | | Spec | <https://tc39.es/ecma262/> | | Status | Other | | IE | Edge | Firefox | Chrome | Safari | Opera | | --- | --- | --- | --- | --- | --- | | | | | 111 (2) | | | | | | 110 (2) | 110 (2) | TP | | | | | 109 (2) | 109 (2) | 16.3 | | | 11 (1,2) | 108 (2) | 108 (2) | 108 (2) | 16.2 | 92 (2) | | 10 | 107 (2) | 107 (2) | 107 (2) | 16.1 | 91 (2) | | 9 | 106 (2) | 106 (2) | 106 (2) | 16.0 | 90 (2) | | 8 | 105 (2) | 105 (2) | 105 (2) | 15.6 | 89 (2) | | [Show all](#) | | 7 | 104 (2) | 104 (2) | 104 (2) | 15.5 | 88 (2) | | 6 | 103 (2) | 103 (2) | 103 (2) | 15.4 | 87 (2) | | 5.5 | 102 (2) | 102 (2) | 102 (2) | 15.2-15.3 | 86 (2) | | | 101 (2) | 101 (2) | 101 (2) | 15.1 | 85 (2) | | | 100 (2) | 100 (2) | 100 (2) | 15 | 84 (2) | | | 99 (2) | 99 (2) | 99 (2) | 14.1 | 83 (2) | | | 98 (2) | 98 (2) | 98 (2) | 14 | 82 (2) | | | 97 (2) | 97 (2) | 97 (2) | 13.1 | 81 (2) | | | 96 (2) | 96 (2) | 96 (2) | 13 | 80 (2) | | | 95 (2) | 95 (2) | 95 (2) | 12.1 | 79 (2) | | | 94 (2) | 94 (2) | 94 (2) | 12 | 78 (2) | | | 93 (2) | 93 (2) | 93 (2) | 11.1 | 77 (2) | | | 92 (2) | 92 (2) | 92 (2) | 11 | 76 (2) | | | 91 (2) | 91 (2) | 91 (2) | 10.1 | 75 (2) | | | 90 (2) | 90 (2) | 90 (2) | 10 | 74 (2) | | | 89 (2) | 89 (2) | 89 (2) | 9.1 | 73 (2) | | | 88 (2) | 88 (2) | 88 (2) | 9 | 72 (2) | | | 87 (2) | 87 (2) | 87 (2) | 8 | 71 (2) | | | 86 (2) | 86 (2) | 86 (2) | 7.1 | 70 (2) | | | 85 (2) | 85 (2) | 85 (2) | 7 | 69 (2) | | | 84 (2) | 84 (2) | 84 (2) | 6.1 | 68 (2) | | | 83 (2) | 83 (2) | 83 (2) | 6 | 67 (2) | | | 81 (2) | 82 (2) | 81 (2) | 5.1 | 66 (2) | | | 80 (2) | 81 (2) | 80 (2) | 5 | 65 (2) | | | 79 (2) | 80 (2) | 79 (2) | 4 | 64 (2) | | | 18 (2,3) | 79 (2) | 78 (2) | 3.2 | 63 (2) | | | 17 (2,3) | 78 (2) | 77 (2) | 3.1 | 62 (2) | | | 16 (2,3) | 77 (2) | 76 (2) | | 60 (2) | | | 15 (2,3) | 76 (2) | 75 (2) | | 58 (2) | | | 14 (2) | 75 (2) | 74 (2) | | 57 (2) | | | 13 (2) | 74 (2) | 73 (2) | | 56 (2) | | | 12 (2) | 73 (2) | 72 (2) | | 55 (2) | | | | 72 (2) | 71 (2) | | 54 (2) | | | | 71 (2) | 70 (2) | | 53 (2) | | | | 70 (2) | 69 (2) | | 52 (2) | | | | 69 (2) | 68 (2) | | 51 (2) | | | | 68 (2) | 67 (2) | | 50 (2) | | | | 67 (2) | 66 (2) | | 49 (2) | | | | 66 (2) | 65 (2) | | 48 (2) | | | | 65 (2) | 64 (2) | | 47 (2) | | | | 64 (2) | 63 (2) | | 46 (2) | | | | 63 (2) | 62 (2) | | 45 (2) | | | | 62 (2) | 61 (2) | | 44 (2) | | | | 61 (2) | 60 (2) | | 43 (2) | | | | 60 (2) | 59 (2) | | 42 (2) | | | | 59 (2) | 58 (2) | | 41 (2) | | | | 58 (2) | 57 (2) | | 40 (2) | | | | 57 (2) | 56 (2) | | 39 (2) | | | | 56 (2) | 55 (2) | | 38 (2) | | | | 55 (2) | 54 (2) | | 37 | | | | 54 (2) | 53 (2) | | 36 | | | | 53 | 52 (2) | | 35 | | | | 52 | 51 (2) | | 34 | | | | 51 | 50 | | 33 | | | | 50 | 49 | | 32 | | | | 49 | 48 | | 31 | | | | 48 | 47 | | 30 | | | | 47 | 46 | | 29 | | | | 46 | 45 | | 28 | | | | 45 | 44 | | 27 | | | | 44 | 43 | | 26 | | | | 43 | 42 | | 25 | | | | 42 | 41 | | 24 | | | | 41 | 40 | | 23 | | | | 40 | 39 | | 22 | | | | 39 | 38 | | 21 | | | | 38 | 37 | | 20 | | | | 37 | 36 | | 19 | | | | 36 | 35 | | 18 | | | | 35 | 34 | | 17 | | | | 34 | 33 | | 16 | | | | 33 | 32 | | 15 | | | | 32 | 31 | | 12.1 | | | | 31 | 30 | | 12 | | | | 30 | 29 | | 11.6 | | | | 29 | 28 | | 11.5 | | | | 28 | 27 | | 11.1 | | | | 27 | 26 | | 11 | | | | 26 | 25 | | 10.6 | | | | 25 | 24 | | 10.5 | | | | 24 | 23 | | 10.0-10.1 | | | | 23 | 22 | | 9.5-9.6 | | | | 22 | 21 | | 9 | | | | 21 | 20 | | | | | | 20 | 19 | | | | | | 19 | 18 | | | | | | 18 | 17 | | | | | | 17 | 16 | | | | | | 16 | 15 | | | | | | 15 | 14 | | | | | | 14 | 13 | | | | | | 13 | 12 | | | | | | 12 | 11 | | | | | | 11 | 10 | | | | | | 10 | 9 | | | | | | 9 | 8 | | | | | | 8 | 7 | | | | | | 7 | 6 | | | | | | 6 | 5 | | | | | | 5 | 4 | | | | | | 4 | | | | | | | 3.6 | | | | | | | 3.5 | | | | | | | 3 | | | | | | | 2 | | | | | Safari on iOS | Opera Mini | Android Browser | Blackberry Browser | Opera Mobile | Android Chrome | Android Firefox | IE Mobile | Android UC Browser | Samsung Internet | QQ Browser | Baidu Browser | KaiOS Browser | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 16.3 | | | | | | | | | | | | | | 16.2 | all | 108 (2) | 10 | 72 (2) | 108 (2) | 107 (2) | 11 (1,2) | 13.4 (2) | 19.0 (2) | 13.1 (2) | 13.18 (2) | 2.5 | | 16.1 | | 4.4.3-4.4.4 | 7 | 12.1 | | | 10 | | 18.0 (2) | | | | | 16.0 | | 4.4 | | 12 | | | | | 17.0 (2) | | | | | 15.6 | | 4.2-4.3 | | 11.5 | | | | | 16.0 (2) | | | | | [Show all](#) | | 15.5 | | 4.1 | | 11.1 | | | | | 15.0 (2) | | | | | 15.4 | | 4 | | 11 | | | | | 14.0 (2) | | | | | 15.2-15.3 | | 3 | | 10 | | | | | 13.0 (2) | | | | | 15.0-15.1 | | 2.3 | | | | | | | 12.0 (2) | | | | | 14.5-14.8 | | 2.2 | | | | | | | 11.1-11.2 (2) | | | | | 14.0-14.4 | | 2.1 | | | | | | | 10.1 (2) | | | | | 13.4-13.7 | | | | | | | | | 9.2 (2) | | | | | 13.3 | | | | | | | | | 8.2 (2) | | | | | 13.2 | | | | | | | | | 7.2-7.4 (2) | | | | | 13.0-13.1 | | | | | | | | | 6.2-6.4 (2) | | | | | 12.2-12.5 | | | | | | | | | 5.0-5.4 (2) | | | | | 12.0-12.1 | | | | | | | | | 4 | | | | | 11.3-11.4 | | | | | | | | | | | | | | 11.0-11.2 | | | | | | | | | | | | | | 10.3 | | | | | | | | | | | | | | 10.0-10.2 | | | | | | | | | | | | | | 9.3 | | | | | | | | | | | | | | 9.0-9.2 | | | | | | | | | | | | | | 8.1-8.4 | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | 7.0-7.1 | | | | | | | | | | | | | | 6.0-6.1 | | | | | | | | | | | | | | 5.0-5.1 | | | | | | | | | | | | | | 4.2-4.3 | | | | | | | | | | | | | | 4.0-4.1 | | | | | | | | | | | | | | 3.2 | | | | | | | | | | | | | Notes ----- As ES6 refers to a huge specification and browsers have various levels of support, "Supported" means at least 95% of the spec is supported. "Partial support" refers to at least 10% of the spec being supported. For full details see the [Kangax ES6 support table](https://kangax.github.io/compat-table/es6/). 1. Notable partial support in IE11 includes (at least some) support for `const`, `let`, block-level function declaration, typed arrays, `Map`, `Set` and `WeakMap`. 2. Does not support [tail call optimization](https://kangax.github.io/compat-table/es6/#test-proper_tail_calls_%28tail_call_optimisation%29) 3. Only has partial Symbol support and partial support for `RegExp.prototype` properties Resources --------- * [ES6 New features: overview and comparisons](http://es6-features.org) * [Exploring ES6 (book)](https://exploringjs.com/es6/) * [Polyfill for all possible ES2015 features is available in the core-js library](https://github.com/zloirock/core-js#ecmascript)
programming_docs