π Key Takeaway:
Always use
Web.Contents()
when connecting to authenticated web resources or APIs, especially if publishing to the Power BI Service.
ReserveWeb.BrowserContents()
for desktop-only scenarios like scraping HTML pages with dynamic content β and expect no scheduled refresh capability.
βοΈ Scenario
We encountered a frustrating authentication issue when trying to refresh a published Power BI report in the Service. Despite working fine in Desktop, the dataset failed to refresh online, with no option to set credentials.
π Root cause:
The query used Web.BrowserContents()
β either directly or implicitly chosen by Power BI based on the URL entered when using Get Data β Web.
π¨ Gotcha:
Power BI automatically chooses between
Web.Contents()
andWeb.BrowserContents()
based on the URL style:
- If the URL looks like a file (e.g., ends in
.json
,.csv
, etc.), it typically usesWeb.Contents()
. - If the URL looks like a web page (e.g., no file extension, or points to a homepage), it may use
Web.BrowserContents()
.
Unlike Web.Contents()
, the Web.BrowserContents()
function:
- Does not support credential management in the Power BI Service
- Cannot be refreshed on a schedule, even with anonymous access
- Does not handle privacy levels or authentication headers
β Resolution:
We replaced Web.BrowserContents()
with Web.Contents()
and structured the call to include the necessary headers (e.g., Bearer token), enabling proper credential handling and refresh support.
πΉ Web.Contents(url)
β Preferred in Power BI Service
This is the standard method to fetch data from the web (or APIs) in Power Query M. It supports:
- Credential storage: Power BI Desktop and Power BI Service both allow you to set credentials for the URL or root domain (Basic, OAuth, API key, etc.).
- Scheduled refresh: Supported and reliable in the Power BI Service.
- Privacy Levels: Respects privacy level settings (Public, Organisational, Private).
β Recommended for API calls and web data sources where credentials or headers are required.
Example:
Source = Json.Document(Web.Contents("https://api.example.com/data", [
Headers = [Authorization="Bearer abc123"]
]))
in
Source
πΈ Web.BrowserContents(url)
β Interactive Browsing Only
This simulates a browser session and is typically used for scraping data from web pages rendered in HTML+JavaScript.
- No credential storage: Power BI cannot manage credentials for
Web.BrowserContents
in the Service β it’s designed for interactive use in Desktop only. - Not supported for refresh: Power BI Service does not support scheduled refresh using this function.
- Authentication: You cannot pass headers or tokens directly.
- Privacy: Does not handle privacy levels or security isolation in the same way.
β Not recommended for APIs or authenticated services if you intend to publish and refresh in the Power BI Service.
Example:
Source = Web.BrowserContents("https://example.com/dashboard")
in
Source
π Summary: Credential Management & Publishing
Feature | Web.Contents | Web.BrowserContents |
---|---|---|
Scheduled refresh (Service) | β Supported | β Not supported |
Credentials in Service | β Stored & managed securely | β Not available |
API access support | β Yes | β No (HTML scraping only) |
Privacy level handling | β Yes | β No |
Intended use | APIs, REST calls, static files | Interactive pages, JavaScript sites |
β Recommendation
Always use Web.Contents()
when building reports that will be published to the Power BI Service, especially if:
- You’re calling APIs
- You need to authenticate
- You want scheduled refreshes to work
Use Web.BrowserContents()
only for web scraping in Desktop where the page content must be rendered before accessing data (and manual refresh is acceptable).