Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Get browser url for bitbucket add-on

freyr123 NA October 2, 2015

 

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.

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
TimP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2015

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

freyr123 NA October 2, 2015

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 smile

TimP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2015

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

freyr123 NA October 5, 2015

Thanks again :)

TAGS
AUG Leaders

Atlassian Community Events