|
33 | 33 | browser_create_params, |
34 | 34 | browser_update_params, |
35 | 35 | browser_retrieve_params, |
| 36 | + browser_save_profile_params, |
36 | 37 | browser_load_extensions_params, |
37 | 38 | ) |
38 | 39 | from .process import ( |
|
88 | 89 | AsyncWebmcpResourceWithStreamingResponse, |
89 | 90 | ) |
90 | 91 | from ..._base_client import AsyncPaginator, make_request_options |
| 92 | +from ...types.profile import Profile |
91 | 93 | from ...types.tags_param import TagsParam |
92 | 94 | from .playwright.playwright import ( |
93 | 95 | PlaywrightResource, |
@@ -897,6 +899,86 @@ def repl( |
897 | 899 | cast_to=BrowserReplResult, |
898 | 900 | ) |
899 | 901 |
|
| 902 | + def save_profile( |
| 903 | + self, |
| 904 | + id_or_name: str, |
| 905 | + *, |
| 906 | + id: str | Omit = omit, |
| 907 | + name: str | Omit = omit, |
| 908 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 909 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 910 | + extra_headers: Headers | None = None, |
| 911 | + extra_query: Query | None = None, |
| 912 | + extra_body: Body | None = None, |
| 913 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 914 | + idempotency_key: str | None = None, |
| 915 | + ) -> Profile: |
| 916 | + """ |
| 917 | + Saves the running browser's current user-data state to an existing or new |
| 918 | + profile without ending the browser session. |
| 919 | +
|
| 920 | + Saving restarts the browser. Active CDP and WebDriver connections are closed and |
| 921 | + must reconnect, and WebDriver clients must create a new session. Open tabs are |
| 922 | + restored, but pages reload and in-memory page state is lost. The browser is |
| 923 | + stopped only while its user data is copied; this request returns once the |
| 924 | + restarted browser accepts CDP connections again and the profile has been |
| 925 | + uploaded. Caches, Service Worker storage and Google Drive IndexedDB data are |
| 926 | + left out of the saved profile but kept in the running browser. |
| 927 | +
|
| 928 | + This does not attach the destination profile to the browser or change its |
| 929 | + save_changes setting. Active browsers that already loaded the destination |
| 930 | + profile keep their in-memory state. Pools with refresh_on_profile_update enabled |
| 931 | + flush idle sessions and replenish them from the new snapshot; other browsers |
| 932 | + receive it the next time they load the profile. When saves made with this |
| 933 | + endpoint to the same profile overlap, the save that started most recently wins, |
| 934 | + even if an earlier one finishes later. The automatic save at the end of a |
| 935 | + session whose profile has save_changes enabled is ordered against these saves by |
| 936 | + when each finishes. |
| 937 | +
|
| 938 | + A successful save restarts the browser's inactivity timeout (timeout_seconds). A |
| 939 | + failed save leaves it unchanged. |
| 940 | +
|
| 941 | + Returns 409 when the browser is no longer active, when a pooled browser was |
| 942 | + released or reacquired after the request was made (browser_lease_changed), or |
| 943 | + when the browser is briefly unable to accept a save (browser_busy), in which |
| 944 | + case the request can be retried. |
| 945 | +
|
| 946 | + Args: |
| 947 | + id: Existing profile ID to overwrite. |
| 948 | +
|
| 949 | + name: Profile name to overwrite or create. |
| 950 | +
|
| 951 | + extra_headers: Send extra headers |
| 952 | +
|
| 953 | + extra_query: Add additional query parameters to the request |
| 954 | +
|
| 955 | + extra_body: Add additional JSON properties to the request |
| 956 | +
|
| 957 | + timeout: Override the client-level default timeout for this request, in seconds |
| 958 | +
|
| 959 | + idempotency_key: Specify a custom idempotency key for this request |
| 960 | + """ |
| 961 | + if not id_or_name: |
| 962 | + raise ValueError(f"Expected a non-empty value for `id_or_name` but received {id_or_name!r}") |
| 963 | + return self._post( |
| 964 | + path_template("/browsers/{id_or_name}/profiles", id_or_name=id_or_name), |
| 965 | + body=maybe_transform( |
| 966 | + { |
| 967 | + "id": id, |
| 968 | + "name": name, |
| 969 | + }, |
| 970 | + browser_save_profile_params.BrowserSaveProfileParams, |
| 971 | + ), |
| 972 | + options=make_request_options( |
| 973 | + extra_headers=extra_headers, |
| 974 | + extra_query=extra_query, |
| 975 | + extra_body=extra_body, |
| 976 | + timeout=timeout, |
| 977 | + idempotency_key=idempotency_key, |
| 978 | + ), |
| 979 | + cast_to=Profile, |
| 980 | + ) |
| 981 | + |
900 | 982 |
|
901 | 983 | class AsyncBrowsersResource(AsyncAPIResource): |
902 | 984 | @cached_property |
@@ -1671,6 +1753,86 @@ async def repl( |
1671 | 1753 | cast_to=BrowserReplResult, |
1672 | 1754 | ) |
1673 | 1755 |
|
| 1756 | + async def save_profile( |
| 1757 | + self, |
| 1758 | + id_or_name: str, |
| 1759 | + *, |
| 1760 | + id: str | Omit = omit, |
| 1761 | + name: str | Omit = omit, |
| 1762 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 1763 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 1764 | + extra_headers: Headers | None = None, |
| 1765 | + extra_query: Query | None = None, |
| 1766 | + extra_body: Body | None = None, |
| 1767 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 1768 | + idempotency_key: str | None = None, |
| 1769 | + ) -> Profile: |
| 1770 | + """ |
| 1771 | + Saves the running browser's current user-data state to an existing or new |
| 1772 | + profile without ending the browser session. |
| 1773 | +
|
| 1774 | + Saving restarts the browser. Active CDP and WebDriver connections are closed and |
| 1775 | + must reconnect, and WebDriver clients must create a new session. Open tabs are |
| 1776 | + restored, but pages reload and in-memory page state is lost. The browser is |
| 1777 | + stopped only while its user data is copied; this request returns once the |
| 1778 | + restarted browser accepts CDP connections again and the profile has been |
| 1779 | + uploaded. Caches, Service Worker storage and Google Drive IndexedDB data are |
| 1780 | + left out of the saved profile but kept in the running browser. |
| 1781 | +
|
| 1782 | + This does not attach the destination profile to the browser or change its |
| 1783 | + save_changes setting. Active browsers that already loaded the destination |
| 1784 | + profile keep their in-memory state. Pools with refresh_on_profile_update enabled |
| 1785 | + flush idle sessions and replenish them from the new snapshot; other browsers |
| 1786 | + receive it the next time they load the profile. When saves made with this |
| 1787 | + endpoint to the same profile overlap, the save that started most recently wins, |
| 1788 | + even if an earlier one finishes later. The automatic save at the end of a |
| 1789 | + session whose profile has save_changes enabled is ordered against these saves by |
| 1790 | + when each finishes. |
| 1791 | +
|
| 1792 | + A successful save restarts the browser's inactivity timeout (timeout_seconds). A |
| 1793 | + failed save leaves it unchanged. |
| 1794 | +
|
| 1795 | + Returns 409 when the browser is no longer active, when a pooled browser was |
| 1796 | + released or reacquired after the request was made (browser_lease_changed), or |
| 1797 | + when the browser is briefly unable to accept a save (browser_busy), in which |
| 1798 | + case the request can be retried. |
| 1799 | +
|
| 1800 | + Args: |
| 1801 | + id: Existing profile ID to overwrite. |
| 1802 | +
|
| 1803 | + name: Profile name to overwrite or create. |
| 1804 | +
|
| 1805 | + extra_headers: Send extra headers |
| 1806 | +
|
| 1807 | + extra_query: Add additional query parameters to the request |
| 1808 | +
|
| 1809 | + extra_body: Add additional JSON properties to the request |
| 1810 | +
|
| 1811 | + timeout: Override the client-level default timeout for this request, in seconds |
| 1812 | +
|
| 1813 | + idempotency_key: Specify a custom idempotency key for this request |
| 1814 | + """ |
| 1815 | + if not id_or_name: |
| 1816 | + raise ValueError(f"Expected a non-empty value for `id_or_name` but received {id_or_name!r}") |
| 1817 | + return await self._post( |
| 1818 | + path_template("/browsers/{id_or_name}/profiles", id_or_name=id_or_name), |
| 1819 | + body=await async_maybe_transform( |
| 1820 | + { |
| 1821 | + "id": id, |
| 1822 | + "name": name, |
| 1823 | + }, |
| 1824 | + browser_save_profile_params.BrowserSaveProfileParams, |
| 1825 | + ), |
| 1826 | + options=make_request_options( |
| 1827 | + extra_headers=extra_headers, |
| 1828 | + extra_query=extra_query, |
| 1829 | + extra_body=extra_body, |
| 1830 | + timeout=timeout, |
| 1831 | + idempotency_key=idempotency_key, |
| 1832 | + ), |
| 1833 | + cast_to=Profile, |
| 1834 | + ) |
| 1835 | + |
1674 | 1836 |
|
1675 | 1837 | class BrowsersResourceWithRawResponse: |
1676 | 1838 | def __init__(self, browsers: BrowsersResource) -> None: |
@@ -1700,6 +1862,9 @@ def __init__(self, browsers: BrowsersResource) -> None: |
1700 | 1862 | self.repl = to_raw_response_wrapper( |
1701 | 1863 | browsers.repl, |
1702 | 1864 | ) |
| 1865 | + self.save_profile = to_raw_response_wrapper( |
| 1866 | + browsers.save_profile, |
| 1867 | + ) |
1703 | 1868 |
|
1704 | 1869 | @cached_property |
1705 | 1870 | def telemetry(self) -> TelemetryResourceWithRawResponse: |
@@ -1774,6 +1939,9 @@ def __init__(self, browsers: AsyncBrowsersResource) -> None: |
1774 | 1939 | self.repl = async_to_raw_response_wrapper( |
1775 | 1940 | browsers.repl, |
1776 | 1941 | ) |
| 1942 | + self.save_profile = async_to_raw_response_wrapper( |
| 1943 | + browsers.save_profile, |
| 1944 | + ) |
1777 | 1945 |
|
1778 | 1946 | @cached_property |
1779 | 1947 | def telemetry(self) -> AsyncTelemetryResourceWithRawResponse: |
@@ -1848,6 +2016,9 @@ def __init__(self, browsers: BrowsersResource) -> None: |
1848 | 2016 | self.repl = to_streamed_response_wrapper( |
1849 | 2017 | browsers.repl, |
1850 | 2018 | ) |
| 2019 | + self.save_profile = to_streamed_response_wrapper( |
| 2020 | + browsers.save_profile, |
| 2021 | + ) |
1851 | 2022 |
|
1852 | 2023 | @cached_property |
1853 | 2024 | def telemetry(self) -> TelemetryResourceWithStreamingResponse: |
@@ -1922,6 +2093,9 @@ def __init__(self, browsers: AsyncBrowsersResource) -> None: |
1922 | 2093 | self.repl = async_to_streamed_response_wrapper( |
1923 | 2094 | browsers.repl, |
1924 | 2095 | ) |
| 2096 | + self.save_profile = async_to_streamed_response_wrapper( |
| 2097 | + browsers.save_profile, |
| 2098 | + ) |
1925 | 2099 |
|
1926 | 2100 | @cached_property |
1927 | 2101 | def telemetry(self) -> AsyncTelemetryResourceWithStreamingResponse: |
|
0 commit comments