it fits a polynomial regression, with an order p, i.e. linear regression where the the x variable is expanded so
p=1: Y ~ x
p=2: Y ~ x + x^2
p=3: Y ~ x + x^2 + x^3
and return residuals. Thus if there is some linear or nonlinear trend in the data, it will be removed
One way I have checked for cointegration is to run the OLS model on 2 series and then just do the ADF test on the OLS.residuals. If the residuals are stationary, then the series are considered cointegrated.