Suppose my extension has obtained the URL for the current active tab using the method suggested in How can I get the current tab URL for chrome extension?, e.g.
chrome.tabs.query({
active: true,
lastFocusedWindow: true
}, function (tabs) {
// use first tab to obtain url
var tab = tabs[0];
var url = tab.url
});
How can I determine if the URL refers to a Google Doc to which I have editing rights? The distinction between ownership and being an invited collaborator is not important for this application. I'm interested only in Docs as opposed to Spreadsheets or Forms.
For context on what I'm trying to develop, see: How to manually generate notifications to a Google Doc collaborator?
Alternate answer, based on the Google Drive API rather than the Google Docs UI.
Before doing any of this, make sure to declare permissions in the manifest (to only match URLs that look like
docs.google.com/document/*
).Here is a broad overview of the steps you could follow:
GET a file, which will return some metadata. You can use the URL you have to extract the relevant ID which is used in the GET request.
Use this metadata
file
resource to retrieve apermissions
resourcerole
attribute: it will be eitherowner
,reader
, orwriter
. You will not have editing rights if you are areader
, but should have editing rights otherwise.