I'm developing a Bitbucket add-on but I can't access the url in the browser.
I need the Bitbucket url to parse out the repo slug and the repo owner.
When I try to get it using
window.location.href
I get the url where I am hosting the add-on but not the url that is presented in the browser, i.e. the Bitbucket url.
If there is some other way to achieve this then that way would also be great.
Community moderators have prevented the ability to post new answers.
Hi @freyr123 NA,
I suspect you can probably access the browser URL from an iframe using window.parent.location.href
or more correctly window.top.href
. However, the best way to do this with a Bitbucket add-on is to have the repository path (e.g. account_name/repo_slug
) or repository UUID injected into your add-on URL using context parameters.
If you put the token {repo_path}
, {repo_uuid}
and/or {repo_owner_uuid}
somewhere in the url
property of your Bitbucket add-on module it will be substituted with the appropriate value when your url is rendered in the Bitbucket UI.
This add-on has an example of the repo_uuid being injected into the URL.
Hope this helps!
Tim
Hi @Tim Pettersen,
The "window.parent.location.href" method does not work (something about protocols, domains, and ports must match).
The tokens worked like a charm, thank you.
I had already seen the repo_uuid in the tutorial you mentioned but I couldn't find any mentions of other options in the documentation. You might want to add those
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again @freyr123 NA, Sorry about that, our developer documentation is lagging behind the implementation a little. I've built an add-on that will let you view the different add-on module locations and context parameters from within Bitbucket, which you can install from here: https://pow-location-3.herokuapp.com Alternatively, the available context params are listed in the add-on's source code, here: https://bitbucket.org/tpettersen/pow-location-3/src/2dc45e6ee0497b56135c3fdd728879d5bf1b9e10/contextParameters.js?at=master We'll get the documentation updated soon :) cheers, Tim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.